root/grabbers/oztivo @ 26

Revision 26, 2.1 kB (checked in by max, 7 years ago)

oztivo: Don't log password.

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