Navigation

  • Mythtv & Mediatomb
Home‎ > ‎

Mythtv & Mediatomb

This is a brain dump of the steps that I took to setup Mediatomb to (semi) dynamically publish a list of my mythtv recordings for playback on various media devices connected to my network.

Exporting information from Myth

The first step is do get the information out of the mythtv data base and into a format that can be easily parsed by media tomb.  The format that I've chosen to use for the data transfer tab separated vales, other formats such as csv would work just as well, it just that tsv files are easier to parse and import later in this process.  The actual export is performed using the following script.

export-db-to-tsv

#!/bin/bash

MythDir="/mnt/data/myth"        # This is the directory where all the myth recordings are stored
MediaTombRoot="MythTV"          # This is the name of the mediatomb folder that will contain the list of recordings
MythDBUser="mythtv"             # mythconverge db username
MythDBPass="mythtv"             # mythconverge db password

echo "select distinct title from recorded;" | mysql --user=$MythDBUser --password=$MythDBPass -N mythconverg | \
while read show
do
        echo "set @i=0; \
                select CONCAT('$MythDir/',basename), \
                if(subtitle=\"\",DATE_FORMAT(starttime,\"%Y-%m-%d\"),subtitle), \
                @i:=@i+1, \"$MediaTombRoot\", title from recorded where title=\"$show\" order by starttime;" \
                | mysql --user=$MythDBUser --password=$MythDBPass -N mythconverg
done


The first select produces a list of each different TV series that Myth has recorded eg Mythbusters, Time Team, Dr Who, etc.  For each of these series the second select produces a list of episodes currently on disk and numbers them sequentially in ascending date recorded order.  This numbering is important later on in the import step as it gives Mediatomb a field to order its listings by.

A cron entry is set up to run this script each hour and to dump the output into "/tmp/mythdump.tsv".  Note that the extension .tsv is very important as it will tell Mediatomb how to process the file.

Telling Mediatomb about TSV files

Next we need to tell media tomb what a TSV file is and how it should be handled.  First modify the config.xml file as follows.

In the extension-mimetype section add the following line.

<map from="tsv" to="text/tab-separated-values"/>

This tells Mediatomb to assign a mime type of
"text/tab-separated-values" to all files that end with ".tsv".  Next in the mime-contenttype section add the following line.

<treat mimetype="text/tab-separated-values" as="playlist"/>

This tells Mediatomp to treat all text/tab-separated-values files as playlists, not as regular files.

Finally modify getPlaylistType function in the comon.js file to return the connect value if a TSV file is being processed

getPlaylistType

function getPlaylistType(mimetype)
{
    if (mimetype == 'audio/x-mpegurl')
        return 'm3u';
    if (mimetype == 'audio/x-scpls')
        return 'pls';
    if (mimetype == 'text/tab-separated-values') // *New*
        return 'tsv';                           
// *New*
    return '';
}


Importing the TSV File

The last thing to to is to tell Mediatomb how to import the TSV file.  Do this by appending the following lines to the end of the playlist.js file

playlist.js

else if (type == 'tsv')
{
    var line = readln();
    line = readln();
    do
    {
    lineParts = line.split('\t');
    addPlaylistItem(lineParts[0], lineParts[1], createContainerChain(lineParts.slice(3)), lineParts[2]);
    line = readln();
    }
    while (line);
}


Now all you need to do is to tell Mediatomb to watch the dump file (in this case /tmp/mythdump.tsv) for changes and it will automatically import the files into the structure for you.  I've found that there is a bug in Mediatomb where immediately after you set up a watch the file is not imported.  However if you regenerate the dump file after the watch is in place then everything works fine.