Recently for various reasons my blog has become a very low priority, but I should belatedly fulfil a promise I made in the last post where I mentioned a Python script for recording digital television in Linux.

To run the script the only system requirements are a working DVB device (eg. PCI or USB tuner) that tzap can talk to, and a recent version of Python 2.x. Python 2.6.5 works fine on my system running Ubuntu Lucid 10.04. You will need to have tzap working correctly beforehand. See my previous blog post.

I had intended to clean up the code a little but never got around to it. I’m not proud of the date parsing code in it. Looking at it now I can barely understand what it’s doing, but I’ve been using it for a long time now without problems. Anyway, you can download it from here:

http://dl.ozzmosis.com/tvsched.py

The script looks for ~/etc/tvsched.conf and puts the recorded streams in /media/xfs/vidcap. Those paths are hard-coded in the script – obviously you’ll need to change them to suit your system.

tvsched.conf is a comma-separated value (CSV) formatted file with a list of TV shows to record. Comments are allowed if they are prefixed with ‘#’ at the start of the line. Blank lines are allowed, and ignored.

# day, start, end, channel, show-name
Sat, 22:50, 08:00, ABC1, rage-DATE
Sun, 9:30p, 2:00am, TEN Digital, f1-2013-belgium-race

The format should be fairly self-explanatory, with the following comments:

Days of the week can begin with any unambiguous form of the English day of the week. Two letters is enough to be unambiguous, therefore “Mo” is accepted for “Monday”, “Tues” is accepted as “Tuesday”, etc.

The start and end times can be in either 12-hour or 24-hour format, specifying hours and minutes. If using 12-hour format, “a”, “am”, “p” and “pm” are acceptable.

The start and end times can cross midnight.

The channel name should match a channel in the channels.conf file that tzap is using. This is case insensitive – “abc1” is the same as “ABC1” as far as tzap is concerned.

The show name can be any name but should not have spaces in it, otherwise the recorded file will end up in the wrong place. The script doesn’t actually check for that, so be careful.

The string ‘DATE’ in the show name is automatically replaced with the current date in YYYY-MM-DD format.

The script automatically creates a directory under /media/xfs/vidcap/ to store the recorded .mpg file. The .mpg file itself has the format “capture-YYYY-MM-DD-hhmmss.mpg”.

The script re-parses the tvsched.conf roughly every 20 seconds and shows the parsed output to the screen. It will show the start date, start time, end time, recording duration, channel, and the show name you’ve provided.

An unusually long recording duration could mean that you’ve made a mistake entering the start or end time – usually by accidentally mixing up 12 and 24 hour time.

You can lower this 20 second refresh value if you like, but the screen will scroll faster with the parsed output.

The script will abort if tvsched.conf cannot be parsed correctly.

Over a single weekend, the above tvsched.conf file would result in two recordings:

/media/xfs/vidcap/rage-2013-08-24/capture-2013-08-24-225000.mpg
/media/xfs/vidcap/f1-2013-belgium-race/capture-2013-08-25-213000.mpg

The filenames are approximate, since the script only wakes up 20 seconds, therefore the ‘seconds’ part of the filename may not be zeroed.

I run the script under GNU Screen, so it can be detached. You could also use tmux.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti-Spam Quiz: