Reply
Thread Tools
Posts: 8 | Thanked: 22 times | Joined on Jan 2010
#1
Media player in Maemo 5 stores the internet radio station in a sqlite database. The database is located in '/home/seadog/.mafw.db' and contains only one table 'iradiobookmarks' with three columns 'id', 'key', 'value'.

Id is a integer value and it's not unique
Key is a string defining the type of data stored in value.
Value is a blob build in a special way explained later.

Each station must have at least three entries in the database with the same id (so they are grouped) and with keys "title", "mime-type" and "uri". Other keys also exist like "last-played" etc.

"Title" defines the title which is shown in the UI
"Mime-type" is "audio" for radio stations
"Uri" is the location of the stream

The "value" column contains the actual value of the "key" column. Because "value" can store different kind of data, depending on the "key" column, is defined as a binary blob. The format of the blob is "\x01\x00\x00\x00@\x00\x00\x00string that we want\x00"

Because value is a blob we need some easy python scripting to produce valid entries in our database.

Code:
    def findLargestId(cursor):
        """ Finds the largest id so we can add stations after that """
        cursor.execute("SELECT MAX(id) FROM iradiobookmarks")
        row = cursor.fetchone()
        if row:
            return row[0]
        else:
            return -1

    def buildBlob(self, string):
        """ Builds the needed blob for value column """
        return sqlite3.Binary(chr(1) + chr(0) * 3 + '@' + chr(0) * 3 + string + chr(0) )

    # Check if station in already listed and return it's id.
    # Used to do updates        
    def findStationId(self, cursor, station):
        """ finds the id of an existing station """
        cursor.execute('SELECT id FROM iradiobookmarks WHERE key="title" and value=?', (self.buildBlob(station),))
        row = cursor.fetchone()
        if row:
            return row[0]
        else:
            return -1

    def insertIntoDB(cursor, title, uri):
            """ inserts station in db"""
            nextID = self.findLargestId(cursor)+1
            stationId = self.findStationId(cursor, title)
            if stationId == -1:
                # station is not listed. Add it to the list with the next ID
                stationId = nextID
                nextID += 1
                cursor.execute('INSERT INTO iradiobookmarks VALUES (?, "title", ?)', (stationId, self.buildBlob(title),))
                cursor.execute('INSERT INTO iradiobookmarks VALUES (?, "mime-type", ?)', (stationId, self.buildBlob("audio"),))
                cursor.execute('INSERT INTO iradiobookmarks VALUES (?, "uri", ?)', (stationId, self.buildBlob(uri),))
            else:
                # station is listed. Update the uri entry
                cursor.execute('UPDATE iradiobookmarks SET value = ? WHERE id = ? AND key = "uri" ', (self.buildBlob(uri), stationId))


conn = sqlite3.connect("/home/user/.mafw.db")
cursor = conn.cursor()

So for example to store a station with name "Foobar FM" and stream location "mms://example.com/stream.asx" we call insertIntoDb(cursor, "Foobar FM", "mms://example.com/stream.asx") and the function updates the station uri if the station is already there, or makes a new entry.

Note: Before updating the database you should stop the media play internet daemon by typing

/usr/bin/mafw.sh stop mafw-iradio-source

and after updating enable it again

/usr/bin/mafw.sh start mafw-radio-source

If you ignore this step you want see your new entries until you reboot and you may destroy the database.

You can find a working example of database updating the internet radio stations list under the devel repository named 'greekiradio'. The application creates feeds for greek internet radio stations from www.eradio.gr and inserts them into the database.

http://maemo.org/packages/view/greekiradio/
 

The Following 15 Users Say Thank You to seadog For This Useful Post:
zerojay's Avatar
Posts: 2,669 | Thanked: 2,555 times | Joined on Apr 2007 @ Halifax, Nova Scotia, Canada
#2
Thanks for this great post. I'm now working on a package to add/remove all the Digitally Imported streams thanks to all the work you've done.
 
Posts: 94 | Thanked: 28 times | Joined on Oct 2009
#3
HMmh, so you're able to listen to asx using the Maemo Media Player? It never worked for me (it says the codecs aren't supported, even with extra codecs installed :/)
 
Posts: 8 | Thanked: 22 times | Joined on Jan 2010
#4
Originally Posted by zerojay View Post
Thanks for this great post. I'm now working on a package to add/remove all the Digitally Imported streams thanks to all the work you've done.
Thnx, great to hear that. Waiting for your application!
 
Posts: 8 | Thanked: 22 times | Joined on Jan 2010
#5
Originally Posted by corsac View Post
HMmh, so you're able to listen to asx using the Maemo Media Player? It never worked for me (it says the codecs aren't supported, even with extra codecs installed :/)
I'm not sure if I have tried with asx stream but I'm sure that gstreamer has some problems with streams also in the desktop (like in totem) which are not codec related.
 
Posts: 10 | Thanked: 8 times | Joined on Feb 2010
#6
I love the stations added to the mediaplayer by greek iradio, but there are many that i dont need. Is it possible to remove them many at once? I dont want to remove them one by one. I removed the application after first installation, but reinstalled it now. If i use the "remove stations" button there is nothing happening. Any help? I copied some of the stations that were added so its ok to remove all of the others.
Thanks in advance
 
Posts: 8 | Thanked: 22 times | Joined on Jan 2010
#7
Originally Posted by Wassili View Post
I love the stations added to the mediaplayer by greek iradio, but there are many that i dont need. Is it possible to remove them many at once? I dont want to remove them one by one. I removed the application after first installation, but reinstalled it now. If i use the "remove stations" button there is nothing happening. Any help? I copied some of the stations that were added so its ok to remove all of the others.
Thanks in advance
The "Remove stations" button will work for the stations you add from this version and after. Unfortunately it won't work for stations added with previous versions.

You can try to delete the whole radio database by typing
~$ /usr/bin/mafw.sh stop mafw-iradio-source
~$ rm ~/.mafw.db
~$ /usr/bin/mafw.sh start mafw-iradio-source

in you terminal and then updating the list from the application.

Hope that helps,
-g
 
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#8
Excellent app and thanks also for the detailed instructions.

Would you like to also add localisation for the Greek iRadio too?

See here for info http://talk.maemo.org/showthread.php?t=43652
 
Posts: 8 | Thanked: 22 times | Joined on Jan 2010
#9
Originally Posted by Saturn View Post
Excellent app and thanks also for the detailed instructions.

Would you like to also add localisation for the Greek iRadio too?

See here for info http://talk.maemo.org/showthread.php?t=43652

Hi,
Yes I will add greek localization to the app,asap. thnx for the link.
 

The Following User Says Thank You to seadog For This Useful Post:
Posts: 1,141 | Thanked: 781 times | Joined on Dec 2009 @ Magical Unicorn Land
#10
Thanks. I always wondered why the N900 radio station list is so small compared to Nokia Internet Radio on Symbian.
 
Reply


 
Forum Jump


All times are GMT. The time now is 12:02.