source: trunk/grabbers/zaxmltv

Last change on this file was 1390, checked in by max, 7 years ago

shepherd 1.6.0: Change shebang lines from '/usr/bin/perl' to '/usr/bin/env perl', which is more portable (i.e. works on OSX).

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/usr/bin/env perl
2#
3# simple grabber for Al Jazeera and CCTV data from http://zaxmltv.flash.za.org
4#
5
6use warnings;
7
8use XMLTV;
9use Shepherd::Common;
10use POSIX qw(strftime mktime);
11
12#
13# global variables and settings
14#
15# supported Shepherd channels and the corresponding number @ zaxmltv
16
17my @supported = ("AlJazeera","CCTVNews");
18my %channels = (       
19    'AlJazeera' => "406",
20    'CCTVNews' =>"448"
21);
22
23$| = 1;
24my $writer;
25my $baseurl = "http://zaxmltv.flash.za.org";
26
27#
28# go go go!
29#
30
31my %stats;
32my $o;
33
34Shepherd::Common::program_begin(\$o, "zaxmltv grabber", "0.03", \%stats);
35&start_writing_xmltv();
36
37my ($channels, $opt_channels, $gaps) =();
38my $channel_xmlid; 
39
40($channels, $opt_channels, $gaps) = Shepherd::Common::read_channels($o, @supported);
41
42# first write the channel names and id's
43while (my ($name, $num) = each (%channels)) {
44     if ($channels->{$name} || $opt_channels->{$name}) {
45       $channel_xmlid = $channels->{$name} || $opt_channels->{$name};
46       $writer->write_channel( {'display-name' => [[ "$name", $o->{lang} ]], 'id' => $channel_xmlid } );
47     }else{
48       Shepherd::Common::log("ignoring unwanted channel $name");     
49     }
50}
51
52#now the actual program data for each channel
53while (my ($name, $num) = each (%channels)) {
54    if ($channels->{$name} || $opt_channels->{$name}) {
55       $channel_xmlid = $channels->{$name} || $opt_channels->{$name};
56       Shepherd::Common::log("grabbing data for $name - $channel_xmlid");
57       &get_data($num);
58    }
59}
60
61$writer->end();
62
63Shepherd::Common::program_end($o, %stats);
64exit(0);
65
66##############################################################################
67
68sub start_writing_xmltv
69{       
70        my %writer_args = ( encoding => 'ISO-8859-1' );
71        if ($o->{outputfile}) {
72                my $fh = new IO::File(">$o->{outputfile}") || die "can't open $o->{outputfile}: $!";
73                $writer_args{OUTPUT} = $fh;
74        }
75
76        $writer = new XMLTV::Writer(%writer_args);
77        $writer->start ( { 'source-info-name' => "$baseurl",'generator-info-name' => "$o->{program_name} v$o->{version_number}"} );
78}
79
80##############################################################################
81
82sub get_data
83{
84        my $num = $_[0];
85        my $data = &Shepherd::Common::get_url(url => $baseurl."/schedule/zaxmltv_get.php", postvars => "chanlist[]=$num");
86        if (!$data) {
87                 Shepherd::Common::log("Failed to get XML from '$baseurl'");
88                 $stats{failed_html_get}++;
89                 return 0;
90        }
91        my $listing = XMLTV::parse($data);
92        # strip the cruft from the source xml, we only want the programs.
93        my ($encoding, $credits, $ch, $progs) = @$listing;
94        foreach (@$progs) {
95                $_->{channel} = $channel_xmlid;
96                $writer->write_programme($_);
97        }
98                                                                                                                                 
99}
100
101##############################################################################
102
Note: See TracBrowser for help on using the repository browser.