xmltv/grab/uk_atlas CHANGELOG, 1.8, 1.9 tv_grab_uk_atlas, 1.12, 1.13
Geoff <[email protected]>
| Newsgroups | gmane.comp.tv.xmltv.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/xmltv/xmltv/grab/uk_atlas
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv860
Modified Files:
CHANGELOG tv_grab_uk_atlas
Log Message:
Add support for lineups capability (--list-lineups, --get-lineup)
Option to use 'lineup' code during configure
Index: tv_grab_uk_atlas
===================================================================
RCS file: /cvsroot/xmltv/xmltv/grab/uk_atlas/tv_grab_uk_atlas,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** tv_grab_uk_atlas 14 Dec 2013 16:15:14 -0000 1.12
--- tv_grab_uk_atlas 18 Dec 2013 13:03:52 -0000 1.13
***************
*** 76,82 ****
($opt, $conf) = ParseOptions({
grabber_name => $GRABBER_NAME,
! capabilities => [qw/baseline manualconfig apiconfig cache/],
stage_sub => \&config_stage,
! listchannels_sub => \&fetch_channels,
version => $VERSION,
description => $GRABBER_DESC,
--- 76,84 ----
($opt, $conf) = ParseOptions({
grabber_name => $GRABBER_NAME,
! capabilities => [qw/baseline manualconfig apiconfig lineups cache/],
stage_sub => \&config_stage,
! listchannels_sub => \&list_channels,
! list_lineups_sub => \&list_lineups,
! get_lineup_sub => \&get_lineup,
version => $VERSION,
description => $GRABBER_DESC,
***************
*** 117,121 ****
# ------------------------------------------------------------------------------------------------------------------------------------- #
# Used by the configure sub
! my @platforms;
my $selected_platform; my $selected_region;
my $platform_title; my $region_title;
--- 119,123 ----
# ------------------------------------------------------------------------------------------------------------------------------------- #
# Used by the configure sub
! my @platforms; my %regions;
my $selected_platform; my $selected_region;
my $platform_title; my $region_title;
***************
*** 790,798 ****
}
! sub fetch_channels {
# Fetch Atlas' channels for a Region for a Platform
! # This sub is used by both --configure and --list-channels
! # For --configure we will already have a Platform & Region from config_stage()
# For --list-channels it's not practical to list all channels for all regions for all platforms
# (this would take too long (over 10 mins) and would place an unnecessary load on the Atlas server -
--- 792,961 ----
}
! sub list_lineups ( $ ) {
! # Returns an xml-string containing a list of all the channel lineups for which the grabber can deliver data (in xmltv-lineups.xsd format).
!
! my $nb = 'Note: list-lineups and get-lineup is still unofficial in XMLTV, and the format and content of this xml is liable to change.'; print STDERR $nb."\n";
!
! my $opts = $_;
! fetch_platforms();
!
! # There doesn't seem to be a proc in XMLTV for writing the xmltv-lineups.xml
! # so we'll have to roll our own
! # (to validate use " xmllint -noout -schema xmltv-lineups.xsd filename " )
!
! # The lineups xml doesn't map well to the Atlas database but we'll try
!
! use XML::Writer;
!
! my $w = XML::Writer->new( 'ENCODING' => 'UTF-8', 'DATA_MODE' => 1, 'DATA_INDENT' => 1 ); # OUTPUT to stdout
! $w->xmlDecl('UTF-8');
! $w->comment($nb);
! $w->startTag('xmltv-lineups',
! 'modified' => strftime("%FT%T %z", localtime),
! 'source-info-name' => $source_info_name,
! 'source-info-url' => $source_info_url,
! 'generator-info-name' => $generator_info_name,
! 'generator-info-url' => $generator_info_url );
!
! foreach my $platform (@platforms) {
! $w->startTag('xmltv-lineup', 'id' => $platform->{'id'} );
! $w->startTag('type');
! $w->characters('STB');
! $w->endTag('type');
! $w->startTag('display-name', 'lang' => 'en' );
! $w->characters($platform->{'title'});
! $w->endTag('display-name');
! foreach my $country (@{$platform->{'countrieslist'}}) {
! $w->startTag('availability', 'area' => 'country' );
! $w->characters($country);
! $w->endTag('availability');
! }
! $w->endTag('xmltv-lineup');
! foreach my $region (@{$platform->{'regions'}}) {
! $w->startTag('xmltv-lineup', 'id' => $region->{'id'} );
! $w->startTag('type');
! $w->characters('STB');
! $w->endTag('type');
! $w->startTag('display-name', 'lang' => 'en' );
! $w->characters($platform->{'title'} .' - '. $region->{'title'});
! $w->endTag('display-name');
! $w->startTag('availability', 'area' => 'region' );
! $w->characters($region->{'title'});
! $w->endTag('availability');
! $w->endTag('xmltv-lineup');
! }
! }
!
! $w->endTag('xmltv-lineups');
! $w->end();
! return;
! }
!
! sub get_lineup ( $$ ) {
! # Returns an xml-string describing the configured lineup (in xmltv-lineups.xsd format).
!
! my $nb = 'Note: list-lineups and get-lineup is still unofficial in XMLTV, and the format and content of this xml is liable to change.'; print STDERR $nb."\n";
!
! my ($conf, $opt) = @_;
! my @channels = fetch_channels ($conf, $opt);
!
! use XML::Writer;
!
! my $w = XML::Writer->new( 'ENCODING' => 'UTF-8', 'DATA_MODE' => 1, 'DATA_INDENT' => 1 ); # OUTPUT to stdout
! $w->xmlDecl('UTF-8');
! $w->comment($nb);
! $w->startTag('xmltv-lineups',
! 'modified' => strftime("%FT%T %z", localtime),
! 'source-info-name' => $source_info_name,
! 'source-info-url' => $source_info_url,
! 'generator-info-name' => $generator_info_name,
! 'generator-info-url' => $generator_info_url );
!
! $w->startTag('xmltv-lineup', 'id' => $conf->{'platform'}[0] );
! $w->startTag('type');
! $w->characters('STB');
! $w->endTag('type');
! $w->startTag('display-name', 'lang' => 'en' );
! $w->characters($conf->{'platform-title'}[0]);
! $w->endTag('display-name');
!
! foreach my $channel (@channels) {
! $w->startTag('lineup-entry');
! $w->startTag('preset');
! $w->characters($channel->{'num'});
! $w->endTag('preset');
! $w->startTag('station', 'rfc2838' => map_channel_id($channel->{'id'}) );
! $w->startTag('name', 'lang' => 'en' );
! $w->characters($channel->{'title'});
! $w->endTag('name');
! $w->emptyTag('logo', 'url' => $channel->{'image'} ) if $channel->{'image'};
! if ($channel->{'media_type'} && $channel->{'media_type'} eq 'video') {
! if (defined $channel->{'high_definition'}) {
! $w->startTag('video');
! $w->startTag('format');
! $w->characters( ($channel->{'high_definition'} eq 1 ? 'HDTV' : 'SDTV') );
! $w->endTag('format');
! $w->endTag('video');
! } else {
! $w->emptyTag('video');
! }
! }
! if ($channel->{'media_type'} && $channel->{'media_type'} eq 'audio') {
! $w->emptyTag('audio');
! }
! $w->endTag('station');
! $w->startTag('stb-channel');
! $w->startTag('stb-preset');
! $w->characters($channel->{'num'});
! $w->endTag('stb-preset');
! $w->endTag('stb-channel');
! $w->endTag('lineup-entry');
! }
!
! $w->endTag('xmltv-lineup');
! $w->endTag('xmltv-lineups');
! $w->end();
! return;
! }
!
! sub list_channels ( $$ ) {
! # List all available channels on the configured 'region' (in xmltv.dtd format).
!
! my @channels = fetch_channels (@_);
!
! # We must return an xml-string (c.f. Options.pm), E.g.:
! # <channel id="cbbR">
! # <display-name lang="en">BBC News Channel</display-name>
! # </channel>
! # <channel id="cbbT">
! # <display-name lang="en">BBC Parliament</display-name>
! # </channel>
! #
! # Map the list of channels to a hash XMLTV::Writer will understand
! my $channels_conf = {};
! foreach my $c (@channels) {
! my %channel = %$c;
! $channels_conf->{$channel{'num'}} = {
! 'id' => $channel{'id'},
! 'display-name' => [[ $channel{'title'}, 'en' ]],
! };
! $channels_conf->{$channel{'num'}}->{'icon'} = [{'src' => $channel{'image'} }] if $channel{'image'};
! }
! #
! # Let XMLTV::Writer format the results as xml.
! my $result;
! my $writer = new XMLTV::Writer(OUTPUT => \$result, encoding => 'UTF-8');
! $writer->start({'generator-info-name' => $generator_info_name});
! $writer->write_channels($channels_conf);
! $writer->end();
! return $result;
! }
!
! sub fetch_channels ( $$ ) {
# Fetch Atlas' channels for a Region for a Platform
! # This sub is used by both --configure and --list-channels (and --get-lineup)
! # For --configure we have a Platform & Region from config_stage()
! # For --list-channels we have a Platform & Region from %conf
# For --list-channels it's not practical to list all channels for all regions for all platforms
# (this would take too long (over 10 mins) and would place an unnecessary load on the Atlas server -
***************
*** 800,808 ****
# in the 'data' directory on github)
#
- # It seems XMLTV doesn't really handle the situation where there are multiple Platforms->Regions
- # The only way we can reduce the list is to have the user select Platform and Region and then just
- # list the channels for that one Region. But this duplicates the selections we've done in config_stage()
- # unfortunately. If anyone can see a more practical way of doing this please let me know.
- #
my ($conf, $opt) = @_;
--- 963,966 ----
***************
*** 820,827 ****
print OUT "platform-title=$platform_title\n";
print OUT "region-title=$region_title\n";
close OUT;
# ...now back to the normal listchannels_sub
}
! elsif ($opt->{'list-channels'}) {
$selected_platform = $conf->{'platform'}[0];
$selected_region = $conf->{'region'}[0];
--- 978,990 ----
print OUT "platform-title=$platform_title\n";
print OUT "region-title=$region_title\n";
+ if ($conf->{'lineupcode'}[0] ne '') {
+ # if user selected a lineup then we need to manually write the platform/region (since there's no configure_stage for them)
+ print OUT "platform=$selected_platform\n";
+ print OUT "region=$selected_region\n";
+ }
close OUT;
# ...now back to the normal listchannels_sub
}
! else {
$selected_platform = $conf->{'platform'}[0];
$selected_region = $conf->{'region'}[0];
***************
*** 848,852 ****
name => "Fetching channels",
count => 1
! });
foreach my $url (@urls) {
--- 1011,1015 ----
name => "Fetching channels",
count => 1
! }) unless ($opt->{quiet} || $opt->{debug});
foreach my $url (@urls) {
***************
*** 874,878 ****
$channel{'title'} = $chan{'channel'}->{'title'};
$channel{'image'} = $chan{'channel'}->{'image'};
!
if ($opt->{'list-channels'}) {
--- 1037,1042 ----
$channel{'title'} = $chan{'channel'}->{'title'};
$channel{'image'} = $chan{'channel'}->{'image'};
! $channel{'media_type'} = $chan{'channel'}->{'media_type'};
! $channel{'high_definition'} = $chan{'channel'}->{'high_definition'};
if ($opt->{'list-channels'}) {
***************
*** 882,886 ****
}
-
push @channels, \%channel;
}
--- 1046,1049 ----
***************
*** 894,932 ****
$bar->update() && $bar->finish && undef $bar if defined $bar;
! #print Dumper(@channels);
!
!
! # We must return an xml-string (c.f. Options.pm), E.g.:
! # <channel id="cbbR">
! # <display-name lang="en">BBC News Channel</display-name>
! # </channel>
! # <channel id="cbbT">
! # <display-name lang="en">BBC Parliament</display-name>
! # </channel>
! #
! # Map the list of channels to a hash XMLTV::Writer will understand
! my $channels_conf = {};
! foreach my $c (@channels) {
! my %channel = %$c;
! $channels_conf->{$channel{'num'}} = {
! 'id' => $channel{'id'},
! 'display-name' => [[ $channel{'title'}, 'en' ]],
! };
! $channels_conf->{$channel{'num'}}->{'icon'} = [{'src' => $channel{'image'} }] if $channel{'image'};
! }
! #
! # Let XMLTV::Writer format the results as xml.
! my $result;
! my $writer = new XMLTV::Writer(OUTPUT => \$result, encoding => 'UTF-8');
! $writer->start({'generator-info-name' => $generator_info_name});
! $writer->write_channels($channels_conf);
! $writer->end();
! return $result;
}
! sub fetch_platforms {
# Fetch Atlas' channel_groups
! # (note: $opt & $conf have not been returned by ParseOptions() yet, since that hasn't exited yet)
# http://atlas.metabroadcast.com/3.0/channel_groups.json?type=platform
--- 1057,1068 ----
$bar->update() && $bar->finish && undef $bar if defined $bar;
! #print Dumper(@channels);exit;
! return @channels;
}
! sub fetch_platforms () {
# Fetch Atlas' channel_groups
! # (note: if called during --configure then $opt & $conf have not been returned by ParseOptions() yet, since that hasn't exited yet)
# http://atlas.metabroadcast.com/3.0/channel_groups.json?type=platform
***************
*** 935,943 ****
@platforms = ();
my $bar = new XMLTV::ProgressBar({
name => "Fetching platforms",
count => 1
! });
# Fetch the page
--- 1071,1080 ----
@platforms = ();
+ undef %regions;
my $bar = new XMLTV::ProgressBar({
name => "Fetching platforms",
count => 1
! }) unless ($opt->{quiet} || $opt->{debug});
# Fetch the page
***************
*** 961,964 ****
--- 1098,1102 ----
$platform{'title'} = $group{'title'};
+ $platform{'countrieslist'} = $group{'available_countries'};
$platform{'countries'} = '';
foreach my $country (@{$group{'available_countries'}}) {
***************
*** 969,972 ****
--- 1107,1111 ----
foreach my $region (@{$group{'regions'}}) {
push @{$platform{'regions'}}, { 'id' => $region->{'id'}, 'title' => $region->{'title'} };
+ $regions{$region->{'id'}} = { 'title' => $region->{'title'}, 'platform_id' => $platform{'id'}, 'platform_title' => $platform{'title'} };
}
***************
*** 978,988 ****
}
! $bar->update if defined $bar;
! $bar->finish() && undef $bar if defined $bar;
! return @platforms;
}
! sub config_stage {
my ( $stage, $conf ) = @_; # note that $conf is mostly empty at this stage of course
--- 1117,1128 ----
}
! $bar->update() && $bar->finish && undef $bar if defined $bar;
! #print Dumper(@platforms);exit;
! #print Dumper(\%regions);exit;
! return;
}
! sub config_stage ( $$ ) {
my ( $stage, $conf ) = @_; # note that $conf is mostly empty at this stage of course
***************
*** 1028,1032 ****
--- 1168,1236 ----
} );
+ $writer->end('select-lineup');
+
+ }
+ # ------------------------------------------------------------------ #
+ elsif ($stage eq 'select-lineup') {
+
+ # I don't like the way the "lineup" functionality is supposed to work:
+ # If user selects a lineup then we are supposed to get ALL channels for that lineup. Every time. No exception
+ # Not only does that mean (i) we have to do a fetch of the channels for the lineup EVERY time the grabber is run,
+ # (since the channels for the lineup would *not* be stored in the config file)
+ # but (ii) we are potentially grabbing 600 channels *just because* the user selected a lineup -- not only does this
+ # place a load on the data source, but it might not even be what the user needs.
+ # AIUI "lineup" is so a user's PVR can grab data in a (semi-) automated way. But that doesn't mean that just because
+ # I am using MythTV that I want to get all 600 channels! (Especially if it's a paid for service where you pay per channel
+ # downloaded.)
+ # Therefore I'm going to still run the channels selector. If a user/PVR software really wants all 600 channels then all
+ # they have to do is send "all" in response to the subsequent question.
+
+ $writer->write_string( {
+ id => 'lineupcode', # don't use 'lineup' or else we don't run the channels selector
+ title => [ [ 'Enter your viewing region', 'en' ] ],
+ description => [ [ 'Enter the region code you want or leave blank to select from a list', 'en' ] ],
+ default => '',
+ } );
+
+ $writer->end('check-lineup');
+
+ }
+ # ------------------------------------------------------------------ #
+ elsif ($stage eq 'check-lineup') {
+
+ fetch_platforms();
+
+ if ($conf->{'lineupcode'}[0] ne '') {
+ # selected 'code' could be a platform OR a region
+ my $lineupcode = $conf->{'lineupcode'}[0];
+ { LOOP:
+ foreach my $platform (@platforms) {
+ if ($platform->{'id'} eq $lineupcode) {
+ $selected_platform = $platform->{'id'};
+ $platform_title = $platform->{'title'};
+ $selected_region = '';
+ $region_title = '';
+ last LOOP;
+ }
+ foreach my $region (@{$platform->{'regions'}}) {
+ if ($region->{'id'} eq $lineupcode) {
+ $selected_platform = $platform->{'id'};
+ $platform_title = $platform->{'title'};
+ $selected_region = $region->{'id'};
+ $region_title = $region->{'title'};
+ last LOOP;
+ }
+ }
+ }
+ }
+
+ if (defined $selected_platform && $selected_platform ne '') {
+ $writer->end('select-channels');
+ }
+ }
+ else
+ {
$writer->end('select-platform');
+ }
}
***************
*** 1034,1038 ****
elsif ($stage eq 'select-platform') {
! fetch_platforms();
$writer->start_selectone( {
--- 1238,1242 ----
elsif ($stage eq 'select-platform') {
! #fetch_platforms();
$writer->start_selectone( {
***************
*** 1058,1061 ****
--- 1262,1268 ----
elsif ($stage eq 'select-region') {
+ # store platform selected in previous stage
+ $selected_platform = $conf->{'platform'}[0];
+
$writer->start_selectone( {
id => 'region',
***************
*** 1092,1100 ****
$writer->end_selectone();
! $writer->end('select-done');
}
# ------------------------------------------------------------------ #
! elsif ($stage eq 'select-done') {
# Store some extra data in the conf file (just for info)
--- 1299,1307 ----
$writer->end_selectone();
! $writer->end('clean-up');
}
# ------------------------------------------------------------------ #
! elsif ($stage eq 'clean-up') {
# Store some extra data in the conf file (just for info)
***************
*** 1254,1258 ****
tv_grab_uk_atlas
! [--hours N] [--offset N]
[--channel S]
[--config-file FILE]
--- 1461,1465 ----
tv_grab_uk_atlas
! --hours N [--offset N]
[--channel S]
[--config-file FILE]
***************
*** 1260,1264 ****
tv_grab_uk_atlas
! [--date DATE] [--dst]
[--channel S]
[--config-file FILE]
--- 1467,1471 ----
tv_grab_uk_atlas
! --date DATE [--dst]
[--channel S]
[--config-file FILE]
***************
*** 1274,1277 ****
--- 1481,1490 ----
[--output FILE] [--quiet] [--debug]
+ tv_grab_uk_atlas --list-lineups [--output FILE]
+ [--quiet] [--debug]
+
+ tv_grab_uk_atlas --get-lineup [--config-file FILE] [--output FILE]
+ [--quiet] [--debug]
+
=head1 DESCRIPTION
***************
*** 1319,1323 ****
B<--list-channels> Write output giving <channel> elements for every
! channel available (ignoring the config file), but no programmes.
B<--capabilities> Show which capabilities the grabber supports. For more
--- 1532,1541 ----
B<--list-channels> Write output giving <channel> elements for every
! channel available in the current configuration.
!
! B<--list-lineups> Write output giving list of available viewing regions.
!
! B<--get-lineup> Write output giving <channel> elements for every
! channel available in the current lineup.
B<--capabilities> Show which capabilities the grabber supports. For more
Index: CHANGELOG
===================================================================
RCS file: /cvsroot/xmltv/xmltv/grab/uk_atlas/CHANGELOG,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** CHANGELOG 14 Dec 2013 17:38:19 -0000 1.8
--- CHANGELOG 18 Dec 2013 13:03:52 -0000 1.9
***************
*** 1,2 ****
--- 1,4 ----
+ 1.13 18-Dec-2013 Add support for lineups capability (--list-lineups, --get-lineup)
+ Option to use 'lineup' code during configure
1.12 14-Dec-2013 Fix --list-channels so it uses the conf hash
1.11 5-Dec-2013 Minor mod to config validation
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk