Skip to content

Add Broadcast Date to MythWeb Direct Download

This was originally published for MythTV 0.27 in July 2016. It is provided here for historic reference only.

MythWeb included with MythTV allows you to download records from the web browser, by using the Direct Download link on the recording details or recording list.

By default, these files are named in the form of Title – 3×01 – Subtitle.mpg. This is fine if the EPG data included a subtitle field or season/episode number to differentiate episode numbers or episode titles, but that is not always the case.

I wanted to add the broadcast/recording date to the downloaded filename, and I could not find any way of doing so in the settings, so I made the following modification to the code.

The file to modify is stream_raw.pl, and on Ubuntu 14.04 and Mint 17, this is located at /usr/share/mythtv/mythweb/modules/stream

Find the block of code which is prefixed by “#Download filename” (around line 71) in 0.27

# Download filename
    my $name = $basename;
    if ($name =~ /^\d+_\d+\.\w+$/) {
        if ($title =~ /\w/) {
            $name = $title;
            $name .= sprintf(" - %dx%02d", $season, $episode) if $season and $episode;
            if ($subtitle =~ /\w/) {
                $name .= " - $subtitle";
            }
        }
        $name .= $suffix;
    }

The recording start time is held in the $starttime variable, which is an epoch timestamp. Convert this to a human-readable date with strftime, and then append to $name, before the suffix (i.e. MPG) is added.

The block of code will now look like this:

# Download filename
    my $name = $basename;
    if ($name =~ /^\d+_\d+\.\w+$/) {
        if ($title =~ /\w/) {
            $name = $title;
            $name .= sprintf(" - %dx%02d", $season, $episode) if $season and $episode;
            if ($subtitle =~ /\w/) {
                $name .= " - $subtitle";
            }
            use Time::Piece;
            my $timestring = localtime($starttime)->strftime('%Y-%m-%d_%H:%M:%S');
            $name .= "_$timestring";
        }
        $name .= $suffix;
    }