Here's a Perl script I wrote that uses the over the air Electronic Program Guide (EPG) data to schedule TV program recording.
Features:
- Uses keywords to find your favorite TV programs.
- Manual recording settings too, also using days of the week / weekends.
- Can scan many channels to get EPG program data.
- Finds your programs on any of the scanned channels.
- Runs without GUI in the background, even on remote machines.
- Saves energy, can be run on a remote laptop 24/7 using only 20W.
- Controlled by simple to edit text files.
- Easy setup.
- Written with user modification in mind, make it do special things.
Most digital TV channels broadcast "TV Guide" data over the air along with the video feed. This script picks up that data, looks through it for your favorite TV programs and records them to your hard drive for later viewing. It's pretty much like having a Tivo without the monthly fee.
I wrote it in as simple a Perl format as possible, and with many comments so it would be easy for people to modify and customize it.
I use ATSC broadcast for this program, it should work with a little tweaking on other EPG formats and possibly XML TV guides.
To get started, you need to get to the point where you can use "mencoder" from the command line and successfully save a video file, or make a command line that works for you and outputs the format you want.
A working example I use is included and works with Ubuntu 12.04 and "Xine" to play back the saved files. I like to use little CPU and memory so I do no big conversions on the video format and the files get to be 1.8GB for a hour show, watch, delete, so what. If you want something different, you will need to create your own mencoder options and change the mencoder line in the source code. For now, just try it.
You also need to be able to get EPG data using the "atsc_epg" program from command line.
Here's some examples that should work if you substitute your TV channel NAME for "TV11 below, and also get channel info for "atsc_epg" from your "~/.mplayer/channels.conf" file. It will get 5mb of TV and stop. Use google and the man pages to help you with the formats for the commands.
Code:
mencoder -endpos 5mb -ovc copy -oac pcm -o "testvideo.avi" dvb://TV1
atsc_epg -a0 -f 177000000:8VSB:65:68:4
If you can't do the above commands from the command line then this program will not work, get that working first.
Next, create a directory to store the videos, I call mine "tv-recording".
Then create a keyword file based on program names you like, it will find partial names. It's a simple text file named "tv-keywords.txt", one line per keyword (spaces are OK in keywords). This keyword also becomes the saved filename. Example:
Code:
Hawaii Five-O
Mission
Twilight Zone
M*A*S*H
Hogan's Heroes
Notice that "Mission: Impossible" has a ":" in it, and the "tv-schedule.txt" file uses those, so please leave those out of the keyword file.
The next file is the "tv-always.txt", you can create it and leave it empty, but it MUST exist. This is for things you want recorded via time and day all the time, regardless of EPG data or not. One line per entry that you want added to the TOP of the "tv-schedule.txt" file, the line must be in "tv-schedule.txt" file format.
You can use the "tv-always.txt" file to schedule programs for channels that don't broadcast EPG data, or make another script that adds special movie times to this file.
Now you need to enter some channels to do a EPG scan on. The source code has an example near the top, you need to change those to your channels from the ~/.mplayer/channels.conf file. You can add as many as you want, just remember the "," after each one except the last one.
Next you need to create a "tv-schedule.txt" file this ONE TIME by uncommenting the special "goto" line and running the program. You should rename the program file you got here "perl-dvr.txt" to "perl-dvr.pl" and "chmod 755 perl-dvr.pl" so it will run. Leave logging enabled for a while so you can check up on how the program is doing.
Code:
# goto MAKE_SCHEDULE_NOW; # un-comment this line like below
goto MAKE_SCHEDULE_NOW;
Now run the program and it should get the EPG data and create a "tv-schedule.txt" file if it found any programs in that data.
You should only have to do this once manually to check if the program is working correctly and your EPG data is OK.
It also creates a "tv-epg-output-log.txt" file that is a copy of the output from the "atsc_epg" call. You can look through that to understand why it may have not picked up program from the keywords.
If everything works, you need to comment the "goto" line again so it doesn't do that every time it runs, and create a cron entry so this program runs every minute, use "crontab -e" to edit your cron file.
Code:
# min hr day mo day-week (sun=0) command
* * * * * /home/USERNAME/perl-dvr.pl >/dev/null 2>&1
The above cron makes the script run every minute. It will go through the "tv-schedule.txt" file and see if a program needs to be recorded, it will even start a little late by a few minutes.
If it's not recording, it will scan the channels you gave it for EPG data and schedule new programs. It can't be recording because it will need to switch channels to find EPG data on other channels.
That's about it. You should now be automatically recording TV programs!
For your info, the format of the "tv-schedule.txt" file is:
Channel:Hour:Min:Duration:NOT-Days:Filename
Example:
TV1:18:00:60:06:Star Trek
Means record on channel "TV1" starting at 18:00 for 60 minutes and name the file "Star Trek" only on week days.
The "NOT-Days" field is special, 0 means Sunday, 3 is Wednesday, 6 is Saturday etc.. These are days to NOT record a show. Example:
TV1:18:00:60::Star Trek
Means record it every day.
TV1:18:00:60:1:Star Trek
Means don't record on Monday only. You can add as many numbers as you need in this field. 012345 would mean only record on Saturday.
Enjoy!
Please post if you like this program and are using it, and also post any any improvements or cool modifications you make so others can use them too!
(I will try to edit this post and update the program from time to time, but always look below for more messages about any improvements)
Edit: Minor text changes above
Bookmarks