Monday, 2 May 2011

How to export Rhythmbox radio stations?

Rhythmbox is currently my favorite audio player. I often listen to internet radio stations.



Now I wanted to export the stations which I added to Rhythmbox. Unfortunately you can't do this with Rhythmbox itself. It's possible to export normal playlists, but it's not possible to export your radio stations.

Rhythmbox stores meta information of your media library in an XML file which is located at
~/.local/share/rhythmbox/rhythmdb.xml

You will probably see that most of the elements starts with <entry type="ignore"> or <entry type="song">

The type of internet radio stations is "iradio". E.g.:
<entry type="iradio">
    <title>Radio Swiss Jazz</title>
    <genre>Jazz Music</genre>
    <artist></artist>
    <album></album>
    <location>http://www.radioswissjazz.ch/live/mp3.m3u</location>
    <rating>5</rating>
    <play-count>14</play-count>
    <last-played>1304359817</last-played>
    <bitrate>128</bitrate>
    <date>0</date>
    <mimetype>application/octet-stream</mimetype>
  </entry>

What we need is a way to extract all titles and locations of xml entries of type iradio. This can easily done with a XPath query. I use XMLStarlet for this purpose (I like to work in the command line). You can install it with

sudo apt-get install xmlstarlet

Now we have the tool to work with and we know what we are looking for. Here comes the magic:

xmlstarlet sel -t -m "/rhythmdb/entry[@type='iradio']" -v title -n -v location -n ~/.local/share/rhythmbox/rhythmdb.xml


This will give you a list of you stations with their names and addresses. In my case it looks like this:

Rockland
http://www.rockland.de/fileadmin/user_upload/Streams/rockland.m3u
Rock Antenne
http://www.rockantenne.de/webradio/rockantenne.m3u
WDR2
http://www.wdr.de/wdrlive/media/wdr2.m3u
Bremen 1
http://gffstream.ic.llnwd.net/stream/gffstream_mp3_w48a
DRS3
http://stream.srg-ssr.ch/drs3/mp3_128.m3u
Radio Swiss Jazz
http://www.radioswissjazz.ch/live/mp3.m3u
SWR3
http://swr.ic.llnwd.net/stream/swr_mp3_m_swr3a
hr1
http://metafiles.gl-systemhaus.de/hr/hr1_2.m3u
hr3
http://metafiles.gl-systemhaus.de/hr/hr3_2.m3u
hr2
http://metafiles.gl-systemhaus.de/hr/hr2_2.m3u
WDR3
http://www.wdr.de/wdrlive/media/wdr3_hq.m3u
Radio Stephansdom
http://srvhost24.serverhosting.apa.net:8000/rsdstream128.m3u
OE1 ORF.at
http://mp3stream3.apasf.apa.at:8000/
hr-iNfo
http://metafiles.gl-systemhaus.de/hr/hrinfo_2.m3u

Enjoy!