| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | # OzTivo grabber |
|---|
| 4 | |
|---|
| 5 | my $version = '0.4'; |
|---|
| 6 | |
|---|
| 7 | # Requires configuration! |
|---|
| 8 | # 1. Register at http://www.tvguide.org.au/ |
|---|
| 9 | # 2. Create file "oztivo.conf" containing the line "username:password" |
|---|
| 10 | # (no quotation marks), e.g. tomdaniels:qwerty09 |
|---|
| 11 | # |
|---|
| 12 | # Changelog: |
|---|
| 13 | # 0.1 : Yucky little initial version |
|---|
| 14 | # 0.2 : --ready option |
|---|
| 15 | # 0.3. : Don't log password |
|---|
| 16 | # 0.4 : Changed password filename |
|---|
| 17 | |
|---|
| 18 | use strict; |
|---|
| 19 | |
|---|
| 20 | use LWP::Simple; |
|---|
| 21 | use Cwd; |
|---|
| 22 | use Getopt::Long; |
|---|
| 23 | |
|---|
| 24 | my $config_file = cwd() . "/oztivo.pw"; |
|---|
| 25 | my $output_file = cwd() . "/oztivo.xmltv"; |
|---|
| 26 | my $channels_file; |
|---|
| 27 | my $channels; |
|---|
| 28 | my @clist; |
|---|
| 29 | my $ver; |
|---|
| 30 | my $ready; |
|---|
| 31 | my $desc; |
|---|
| 32 | |
|---|
| 33 | print "OzTivo Grabber v$version\n"; |
|---|
| 34 | |
|---|
| 35 | GetOptions( |
|---|
| 36 | 'channels_file=s' => \$channels_file, |
|---|
| 37 | 'output=s' => \$output_file, |
|---|
| 38 | 'version' => \$ver, |
|---|
| 39 | 'ready' => \$ready, |
|---|
| 40 | 'desc' => \$desc |
|---|
| 41 | ); |
|---|
| 42 | |
|---|
| 43 | exit 0 if ($ver); |
|---|
| 44 | |
|---|
| 45 | print "Reading configuration file $config_file.\n"; |
|---|
| 46 | |
|---|
| 47 | open(CONF, $config_file) |
|---|
| 48 | or die "Unable to read config file $config_file: $!"; |
|---|
| 49 | my $line = <CONF>; |
|---|
| 50 | close CONF; |
|---|
| 51 | |
|---|
| 52 | unless ($line =~ /^(.*):(.*)$/) |
|---|
| 53 | { |
|---|
| 54 | die "Unable to parse config file!\n" . |
|---|
| 55 | "Should be in format: username:password\n"; |
|---|
| 56 | } |
|---|
| 57 | my ($user, $pw) = ($1, $2); |
|---|
| 58 | |
|---|
| 59 | exit 0 if ($ready); |
|---|
| 60 | |
|---|
| 61 | unless ($channels_file) |
|---|
| 62 | { |
|---|
| 63 | die "No --channels_file specified.\n"; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | unless( -r $channels_file) |
|---|
| 67 | { |
|---|
| 68 | die "Unable to read channels file $channels_file: $!"; |
|---|
| 69 | } |
|---|
| 70 | local (@ARGV, $/) = ($channels_file); |
|---|
| 71 | eval <>; |
|---|
| 72 | die "\nError in channels file!\nDetails:\n$@" if ($@); |
|---|
| 73 | |
|---|
| 74 | # Create a list of channel names from longest to shortest |
|---|
| 75 | @clist = sort { length $b <=> length $a } keys %$channels; |
|---|
| 76 | print "Channels: @clist.\n"; |
|---|
| 77 | |
|---|
| 78 | my $fn = "http://$user:YOURPASSWORD\@minnie.tuhs.org/tivo-bin/xmlguide.pl"; |
|---|
| 79 | print "Retrieving $fn... "; |
|---|
| 80 | |
|---|
| 81 | $fn =~ s/YOURPASSWORD/$pw/; |
|---|
| 82 | |
|---|
| 83 | my $data = LWP::Simple::get($fn); |
|---|
| 84 | |
|---|
| 85 | print "done.\nTransforming XMLTVIDs.\n"; |
|---|
| 86 | |
|---|
| 87 | $data =~ s/channel="(.*)"/'channel="'.subme($1).'"'/ge; |
|---|
| 88 | |
|---|
| 89 | print "Writing output.\n"; |
|---|
| 90 | |
|---|
| 91 | open (OUT, ">$output_file"); |
|---|
| 92 | print OUT $data; |
|---|
| 93 | close OUT; |
|---|
| 94 | |
|---|
| 95 | print "Done.\n"; |
|---|
| 96 | |
|---|
| 97 | sub subme |
|---|
| 98 | { |
|---|
| 99 | my $station = shift; |
|---|
| 100 | |
|---|
| 101 | foreach (@clist) |
|---|
| 102 | { |
|---|
| 103 | return $channels->{$_} if ($station =~ /$_/i); |
|---|
| 104 | } |
|---|
| 105 | print "Warning: station \"$station\" unknown.\n"; |
|---|
| 106 | return $station; |
|---|
| 107 | } |
|---|