
david.schmidt.in.dallas at gmail
Aug 23, 2007, 5:50 AM
Post #2 of 17
(11497 views)
Permalink
|
|
Re: Script to use Schedules Direct with legacy MythTV installations
[In reply to]
|
|
Thanks!! I will definitely give this a try as soon as I get my subscription! I (still) have my prototype box on FC3, 0.18.1 and it's also my primary desktop/word processing/websurfing machine and I *really* didn't want to rush through an upgrade to F7/0.20.2 with attendant breakage while the wife is job-hunting! Hopefully this will keep the old system up until I can quit procrastinating and build out my production 0.20 system. On 8/22/07, Josh Mastronarde <jmastron[at]gmail.com> wrote: > I know we're all anxiously awaiting new releases to natively support > Schedules Direct; I'm planning to upgrade as soon as I can, but in the > meantime I made a small script to semi-automatically run a modified version > of XMLTV's tv_grab_na_dd followed by mythfilldatabase, adjusting the new > program ID format to match the old database. It's not pretty (though it > does nice things like wait for the next suggested run time), and it's > definitely not permanent, but will give me a bit of breathing room to > upgrade on my own schedule. At the very least, you can extract the manual > commands to roll your own solution; it took me some trial and error to > figure out the right command line parameters. > > This assumes XMLTV (and tv_grab_na_dd) is already installed (an older > version without the new URL is okay; see modification instructions); this > was true in my ATRPMS "yum install mythtv-suite" following Jarod's guide. > See the help/comments at the beginning for more instructions. > > Good luck; I hope this helps a few people. > > Josh > > > #!/usr/bin/perl > > sub printhelp { > print <<ENDOFHELP; > > SchedulesDirect semi-automatic downloader for legacy MythTV installations > Josh Mastronarde, jmastron[at]gmail.com > 8-22-07 > > Syntax: sdfill <options> > -nodownload Don't download data (use last downloaded file) > -nofill Don't run mythfilldatabase > -once Only run once > > > This script will grab listings data, modify the episode ID field to match > the old data, and run mythfilldatabase. If -once not specified, it will > loop > waiting for the next suggested time from the last run. > > Steps to prepare: > > 1) Find XMLTV's tv_grab_na_dd (was in /usr/bin for me); copy to > ./tv_grab_na_sd > > 2) Modify ./tv_grab_na_sd; replace the "dd_service" line with: > my $dd_service= > > 'http://docs.tms.tribune.com/tech/tmsdatadirect/zap2it/xtvd.wsdl > '; > > 3) Run: ./tv_grab_na_sd --configure --config-file > ~/.xmltv/tv_grab_na_sd.conf" > > 4) Replace "CA54023" with your lineup id (from the above .conf file; leave > off > the ":-", I think) > > If you want to run by hand, the key commands are in "$grabcmd" and > "$mythfillcmd" below, along with the small section of code after "Modify > episode/program IDs" to shorten the IDs. > > > ENDOFHELP > exit(1); > } > > use Time::Local; > > # Defaults > > $xmlfile1 = "sdlist.xml"; > $xmlfile2 = "sdlist_fixed.xml"; > $grablog = "grab_log"; > > $grabcmd = "./tv_grab_na_sd --config-file ~/.xmltv/tv_grab_na_sd.conf " . > "--days 14 --dd-data $xmlfile1 --download-only --list-times"; > > $mythfillcmd = "mythfilldatabase --dd-file 1 -1 CA54023 $xmlfile2"; > > # Parse command line arguments > while (@ARGV) { > $arg = shift(@ARGV); > if ($arg eq "-nodownload") { > $nodownload = 1; > } elsif ($arg eq "-nofill") { > $nofill = 1; > } elsif ($arg eq "-h") { > &printhelp; > } elsif ($arg eq "-once") { > $once = 1; > } else { > push(@narg, $arg); > } > } > > $| = 1; > print "\n---- SDfill started at ", &prlocal(time()), "\n\n"; > > # Loop (but only once if -once flag set) > > $run = 1; > while ($run) { > $run = 0 if ($once); > > # Check for logfile from last grabber run and look for suggested time > > if (-e $grablog) { > $suggtime = ""; > open(grablog, "<$grablog") || die "Error: Can't open $grablog\n"; > while (<grablog>) { > if (($year,$mon,$day,$hour,$min,$sec) = ($_ =~ > /^suggestedTime > \|(\d+)\-(\d+)\-(\d+)T(\d+):(\d+):(\d+)Z/)) { > $suggtime = > timegm($sec,$min,$hour,$day,$mon-1,$year-1900); > } > } > close(grablog); > if ($suggtime) { > $waitsecs = $suggtime - time(); > $waithrs = int($waitsecs/3600); > $waitmins = int($waitsecs/60) % 60; > > print "---- Sleeping until suggested ", &prlocal($suggtime), ", > $waithrs:$waitmins from now ----\n\n"; > sleep($waitsecs); > } > } > > > print "\n---- Grab starting at ", &prlocal(time()), "\n\n"; > > unless ($nodownload) { > unlink("sdlist.xml"); > print "Running: $grabcmd\n"; > open(f, "$grabcmd 2>&1 |") || die "Error: Can't execute tv_grab\n"; > open(grablog, ">$grablog") || die "Error: Can't write $grablog\n"; > while (<f>) { > print; > print grablog; > } > close(f); > close(grablog); > } > > # Modify episode/program IDs to remove 2 digits to match old format > > print "\n\n---- Fixing Episode Number format\n\n"; > open(xmlin, "<$xmlfile1") || die "Error: Can't open $xmlfile1"; > open(xmlout, ">$xmlfile2") || die "Error: Can't open $xmlfile2"; > > while (<xmlin>) { > s/(\<program id=\'..)00/$1/; > s/(\<schedule program=\'..)00/$1/; > s/(\<programGenre program=\'..)00/$1/; > s/(\<series\>..)00/$1/; > print xmlout; > } > close(xmlin); > close(xmlout); > > # Run mythfilldatabase > > unless ($nofill) { > print "Running: $mythfillcmd\n"; > open(f, "$mythfillcmd 2>&1 |") || die "Error: Can't execute > mythfilldatabase\n"; > while (<f>) { > print; > } > } > > print "\n---- Grab done at ", &prlocal(time()), "\n\n"; > } > > > # Helper routine to print nicely formatted local time from a timestamp > > sub prlocal { > my($intime) = @_; > my ($sec,$min,$hour,$mday,$mon,$year) = > localtime($intime); > return(sprintf("%04d/%02d/%02d %02d:%02d:%02d", > $year+1900,$mon+1,$mday,$hour,$min,$sec)); > } > > > _______________________________________________ > mythtv-users mailing list > mythtv-users[at]mythtv.org > http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users > > _______________________________________________ mythtv-users mailing list mythtv-users[at]mythtv.org http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
|