root/grabbers/oztivo @ 41

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

OzTivo?: changed password file location.

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