From: Philipp Matthias Hahn <***@pmhahn.de>
Define grabber name and URL globally once and use that everywhere.
Defining the URL globally simplifies setting up a private server for
local testing.
---
tv_grab_eu_epgdata | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/tv_grab_eu_epgdata b/tv_grab_eu_epgdata
index 73bb264..d4641bc 100755
--- a/tv_grab_eu_epgdata
+++ b/tv_grab_eu_epgdata
@@ -163,6 +163,15 @@ use DateTime::Format::Strptime;
use XMLTV::Memoize; XMLTV::Memoize::check_argv('getstore');
+our $grabber_name = 'tv_grab_eu_epgdata';
+our $grabber_baseurl = "http://www.epgdata.com/";
+our %grabber_tags = (
+ 'source-info-url' => $grabber_baseurl,
+ 'source-info-name' => 'epgData',
+ 'generator-info-name' => $grabber_name,
+ 'generator-info-url' => 'http://xmltv.org/',
+);
+
# set user agent
$ua->agent("xmltv/$XMLTV::VERSION");
@@ -186,7 +195,7 @@ our $genre = new XML::Twig(twig_handlers => { data => \&makegenrehash },
output_encoding => 'UTF-8');
# build a hash: epgdata.com channel id -> xmltv channel id
-my $chanids = GetSupplement('tv_grab_eu_epgdata', 'channel_ids');
+my $chanids = GetSupplement($grabber_name, 'channel_ids');
my @lines = split(/[\n\r]+/, $chanids);
foreach my $line (@lines) {
@@ -198,7 +207,7 @@ foreach my $line (@lines) {
}
my ($opt, $conf) = ParseOptions({
- grabber_name => 'tv_grab_eu_epgdata',
+ grabber_name => $grabber_name,
capabilities => [qw/baseline manualconfig tkconfig apiconfig cache preferredmethod/],
stage_sub => \&config_stage,
listchannels_sub => \&list_channels,
@@ -208,7 +217,7 @@ my ($opt, $conf) = ParseOptions({
});
my $pin = $conf->{pin}->[0];
-die 'Sorry, your PIN is not defined. Run tv_grab_eu_epgdata --configure to fix this.\n' unless $pin;
+die "Sorry, your PIN is not defined. Run $grabber_name-configure to fix this.\n" unless $pin;
# country is determined by the filenames downloaded from the server
# and used to determine the time zone if not specified in the config
@@ -233,7 +242,7 @@ sub config_stage {
my $result;
my $configwriter = new XMLTV::Configure::Writer(OUTPUT => \$result,
encoding => 'ISO-8859-1');
- $configwriter->start({ grabber => 'tv_grab_eu_epgdata' });
+ $configwriter->start({ grabber => $grabber_name });
$configwriter->write_string({
id => 'pin',
title => [ [ 'Enter your PIN for epgdata.com', 'en' ] ],
@@ -309,14 +318,13 @@ sub downloadepg {
my $offset = shift;
my $pin = shift;
my @filenames;
- my $baseurl='http://www.epgdata.com';
my $expiry_date = 0;
# we've got to start counting at 0
# if we did "$i <= $days", we'd end up with one zip file too much
for (my $i = 0; $i < $days; $i++) {
my $dataoffset = $i + $offset;
- my $url = "$baseurl/index.php?action=sendPackage&iOEM=&pin=$pin&dayOffset=$dataoffset&dataType=xml";
+ my $url = $grabber_baseurl . "index.php?action=sendPackage&iOEM=&pin=$pin&dayOffset=$dataoffset&dataType=xml";
# get file name from content-disposition header
warn "url=$url\n" if $opt->{debug};
my $response = $ua->request(GET $url);
@@ -349,7 +357,7 @@ sub downloadepg {
sub prepareinclude {
my ($conf, $opt) = @_;
my $pin = $conf->{pin}->[0];
- my $includeurl = "http://www.epgdata.com/index.php?action=sendInclude&iOEM=&pin=$pin&dataType=xml";
+ my $includeurl = $grabber_baseurl . "index.php?action=sendInclude&iOEM=&pin=$pin&dataType=xml";
warn "Downloading include zip file\n" unless $opt->{quiet};
getstore($includeurl, $tmp . 'includezip');
my @zipfiles=($tmp . 'includezip');
@@ -376,7 +384,7 @@ sub unzip {
sub processxml {
- $writer->start({ 'generator-info-name' => 'tv_grab_eu_epgdata' });
+ $writer->start(\%grabber_tags);
$genre->parsefile($tmp . 'genre.xml');
$channels->parsefile($tmp . 'channel_' . sanitize($channelgroup) . '.xml');
foreach my $xmlfile (@_) {
@@ -628,7 +636,7 @@ sub list_channels {
$channels->parsefile($tmp . 'channel_' . $channelgroup . '.xml');
my $channel_list = $channels->root;
my @channels = $channel_list->children;
- my $xmltv_channel_list = "<tv generator-info-name=\"tv_grab_eu_epgdata\">\n";
+ my $xmltv_channel_list = "<tv generator-info-name=\"$grabber_name\">\n";
foreach my $channel (@channels) {
my $internalchanid = $channel->first_child('ch4')->text;
--
1.8.5.2