Other things on this site...


MythTV: adding iPlayer downloads to the menu

MythTV does good stuff but it doesn't (yet) do BBC iPlayer integration. I found this great blog post about adding BBC live streaming to MythTV and it's almost what I wanted, but I don't want the live streams cos I already get them through the receiver!

What I do is download automatically using get_iplayer so that BBC programmes become a lot like podcasts/vodcasts. So what I want is a MythTV menu showing the media files I've downloaded that way. Here's how I did it, based heavily on that blog post I linked above:

(Note: MythTV v0.22 only since 0.22 introduces a new GUI system and 0.23 is going to introduce a nice iplayer-compatible thing I think...)

First of all, I already have a bash script called automatically to do the downloading. Whenever the downloading is done, I want to regenerate an XML menu of available files, for Myth to show me. Here's the code I added to my bash script:

# Now write the XML menu. this folder I created myself, choose yr own path:
cd $datadir

xmltop="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<mythmenu name=\"WATCH_IPLAYER\">

echo $xmltop > $menupath
# NOTE: this ls command only catches files with extension .m__
for f in `ls -1t *.m?? | head -n 15`; do
        trimname=`echo "$f" | sed -e s/_default//g -e s/_//g -e s/\.m..$//g`
        echo "
        <action>EXEC xterm -e mplayer -fs /var/lib/iplayer/$f</action>
    </button>" >> $menupath
echo $xmlbot >> $menupath

So just to unpack that script a little bit: we're building up some XML code bit-by-bit. First I specify the folder, then define some strings which will be the top and bottom of the XML menu. Then the choice of which files to list comes from this line:

ls -1t *.m?? | head -n 15

That asks the ls command to list files in reverse order of their date, and only to include files whose file extension starts with "m" (.mp3, .mov, .mp4 - it's just luck they all have the "m" in common). Then the head command trims that down to the most recent 15 - you might not want that limit but the interface becomes a bit unwieldy otherwise.

For each file we create a menu entry which executes:

xterm -e mplayer -fs /var/lib/iplayer/$f

This is just invoking mplayer, but wrapping it in an xterm call because otherwise I don't seem to have any option to exit the programme!

So when this script runs, it iterates those 15 most recent files and outputs an entry in the XML file for each of them. It generates this watch_iplayer.xml file.

The final thing that needs doing is telling MythTV to include this menu in its interface. I did this in almost exactly the same way as described near the end of the blog I linked above: copy one of myth's menu layouts to a special folder in your home:

cp /usr/share/mythtv/themes/defaultmenu/library.xml ~/.mythtv/library.xml

and then edit it to add a link to your new menu:

    <text>Watch iPlayer downloads</text>
    <description>watch live TV streamed from BBC</description>
    <action>MENU watch_iplayer.xml</action>

(I used a softlink to jump out of this folder to where my watch_iplayer.xml file really is.) Hey presto, we can watch timeshifted iPlayer just like we can watch other timeshifted TV.

| linux | Permalink