~ubuntu-branches/ubuntu/raring/xmltv/raring

« back to all changes in this revision

Viewing changes to grab/it/tv_grab_it.in

  • Committer: Bazaar Package Importer
  • Author(s): Chris Butler
  • Date: 2010-11-29 19:43:10 UTC
  • mfrom: (1.4.1 upstream) (20.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20101129194310-o2lptjn26an5lq77
Tags: 0.5.59-1
* New upstream release
  - added new grabbers: pt_meo and fi_sv
* Refreshed patches
* Fixed tv_grab_fi by updating to revision 1.58 from upstream CVS 
  (closes: #605467)

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
# sistemato iris (grazie gpancot)
56
56
# 23/02/2010
57
57
# sistemato rai.it (grazie gianni kurgo)
 
58
# 14/09/2010
 
59
# aggiunto nuovo backend dahlia
 
60
# aggiunto nuovo backend k2 (grazie a r.ghetta!)
 
61
# fix per skylife di r.ghetta
 
62
# 18/10/2010
 
63
# aggiunto backend la7 e riattivato mtv.it (grazie gpancot)
 
64
# aggiunto backend mediaset
 
65
# 25/10/2010
 
66
# patch da mennucc per possibili errori di parsing di data
 
67
# patch da wyrdmeister per aggiungere la7d e un fix per raiit
 
68
# 30/10/2010
 
69
# rimosso k2 (grazie rghetta)
 
70
# fix per la7 (grazie rghetta)
 
71
# rimosso searchch
58
72
#################################################
59
73
# TODO
60
74
# - add more informative errors in xml
71
85
use warnings;
72
86
use strict;
73
87
 
74
 
use XMLTV::Version '$Id: tv_grab_it.in,v 1.89 2010/03/28 13:18:27 mnbjhguyt Exp $';
 
88
use XMLTV::Version '$Id: tv_grab_it.in,v 1.97 2010/10/30 12:03:44 mnbjhguyt Exp $';
75
89
use XMLTV::Capabilities qw/baseline manualconfig cache/;
76
90
use XMLTV::Description 'Italy';
77
91
use XMLTV::Supplement qw/GetSupplement/;
127
141
my $LANG="it";
128
142
my $date_today = UnixDate("today", '%Y-%m-%d');
129
143
 
130
 
#searchch is experimental
131
 
#my @default_backends = ('raisat', 'skylife', 'raiit', 'mtvit', 'mediasetpremium', 'iris', 'boingtv', 'searchch', 'sitcom1');
132
 
my @default_backends = ('raisat', 'skylife', 'raiit', 'mtvit', 'mediasetpremium', 'iris', 'boingtv', 'sitcom1');
 
144
my @default_backends = ('mediaset', 'skylife', 'raiit', 'mediasetpremium', 'iris', 'boingtv', 'dahlia', 'mtvit', 'la7');
133
145
 
134
146
 
135
147
my %channels; #to store display names
195
207
       channel_list_sub => \&iris_get_channels_list,
196
208
     },
197
209
 
198
 
     'searchch' =>
199
 
     { domain => 'tv.search.ch',
200
 
       base_chan => 'http://tv.search.ch/programm/',
201
 
       base_data => 'http://tv.search.ch/programm/station/detail.php',
202
 
       rturl => "http://tv.search.ch/programm/station/detail.php",
203
 
       needs_login => 0,
204
 
       needs_cookies => 0,
205
 
       fetch_data_sub =>   \&searchch_fetch_data,
206
 
       channel_list_sub => \&searchch_get_channels_list,
207
 
     },
208
 
 
209
210
     'mtvit' =>
210
211
     { domain => 'www.mtv.it',
211
212
       base_chan => 'http://www.mtv.it/tv/palinsesto/index.asp',
239
240
       channel_list_sub => \&raiit_get_channels_list,
240
241
     },
241
242
 
 
243
     'dahlia' =>
 
244
     { domain => 'dahliatv.it',
 
245
       base_chan => 'http://www.dahliatv.it/guidatv',
 
246
       base_data => 'http://www.dahliatv.it/html/portlet/ext/epg/epg.jsp',
 
247
       rturl => "http://www.dahliatv.it/",
 
248
       needs_login => 0,
 
249
       needs_cookies => 0,
 
250
       fetch_data_sub =>   \&dahlia_fetch_data,
 
251
       channel_list_sub => \&dahlia_get_channels_list,
 
252
     },
 
253
 
 
254
 
 
255
     'la7' =>
 
256
     { domain => 'la7.it',
 
257
       base_chan => 'http://www.la7.it/guidatv/index.html',
 
258
       base_data => 'http://www.la7.it/guidatv/index_',
 
259
       rturl => "http://www.la7.it/guidatv/index",
 
260
       needs_login => 0,
 
261
       needs_cookies => 0,
 
262
       fetch_data_sub =>   \&la7_fetch_data,
 
263
       channel_list_sub => \&la7_get_channels_list,
 
264
     },
 
265
 
 
266
     'mediaset' =>
 
267
     { domain => 'mediaset.it',
 
268
       base_chan => 'http://www.tv.mediaset.it/dati/palinsesto/palinsesto-mondotv.xml',
 
269
       base_data => 'http://www.tv.mediaset.it/dati/palinsesto/palinsesto-mondotv.xml',
 
270
       rturl => "http://www.tv.mediaset.it/dati/palinsesto/palinsesto-mondotv.xml",
 
271
       needs_login => 0,
 
272
       needs_cookies => 0,
 
273
       fetch_data_sub =>   \&mediaset_fetch_data,
 
274
       channel_list_sub => \&mediaset_get_channels_list,
 
275
     },
 
276
 
 
277
 
242
278
    );
243
279
 
244
280
######################################################################
502
538
$w->start({ 'source-info-url'     => $source_info_str ,
503
539
        'source-data-url'     => $source_data_str,
504
540
        'generator-info-name' => 'XMLTV',
505
 
        'generator-info-url'  => 'http://membled.com/work/apps/xmltv/',
 
541
        'generator-info-url'  => 'http://xmltv.org/',
506
542
        });
507
543
 
508
544
 
772
808
    s/^\s*//;
773
809
    # Remove trailing white space
774
810
    s/\s*$//;
 
811
    # FIXME handle a with a grave accent encoded as utf-8 (fallout from LWP::Simple?)
 
812
    s/\xc3\xa0/\xe0/g;
775
813
    return decode_entities($_);
776
814
    }
777
815
}
857
895
    my @programmes = ();
858
896
    warn "VERBOSE: parsing...\n" if ($opt_verbose);
859
897
    my @lines = split /\n/, $content;
860
 
 
 
898
    my $title = '';
 
899
    my $time_start = '';
 
900
    my $description = '';
861
901
    #split the lines
862
902
    foreach my $line (@lines) {
863
903
                next unless $line=~/EVENT/;
864
904
                $line=~/timestamp="(.*?)".*name="(.*?)".*description="(.*?)"/;
865
905
 
866
906
        my %programme = ();
867
 
        my ($title, $time_start, $description) = ($2, utc_offset($1.'00', '+0100'), $3);
868
907
 
 
908
        eval {
 
909
            ($title, $time_start, $description) = ($2, utc_offset($1.'00', '+0100'), $3) ;
 
910
        } or do {
 
911
            warn 'skipping programme, error: ' . $@ ;
 
912
            next ;
 
913
        };
 
914
   
869
915
        # Three mandatory fields: title, start, channel.
870
916
        if (not defined $title) {
871
917
            warn 'no title found, skipping programme';
961
1007
    #split the lines
962
1008
    foreach my $line (@lines) {
963
1009
        next unless $line=~/span class=\'time\'/;
964
 
        
965
 
#       <span class='time'>07.05 - 09.00</span><h3>PURE MORNING</h3><p>Suoni e colori: tanti video per la vostra mattinata.</p></li>
966
 
        $line=~/<span class=\'time\'>(.*?) - (.*?)<\/span><h3>(.*?)<\/h3><p>(.*?)<\/p>/;
967
 
 
968
 
        my %programme = ();
969
 
        my ($title, $time_start, $time_stop, $description) = ($3, $1, $2, $4);
970
 
        my ($time_start2, $time_stop2) = ($time_start, $time_stop);
971
 
        $time_start=~s/\./:/ || warn "$line!$time_start!$time_stop\n$1\n$2\n$3\n$4\n$5\n"; 
972
 
        $time_stop=~s/\./:/;
973
 
        if ($title=~/<a href.*?>(.*?)<\/a/) {$title = $1;}
974
 
#       warn $line;
975
 
#warn "$title, $time_start, $time_stop, $description\n";
976
 
 
977
 
        # Three mandatory fields: title, start, channel.
978
 
        if (not defined $title) {
979
 
            warn 'no title found, skipping programme';
980
 
            next;
981
 
        }
982
 
            $programme{title}=[[tidy($title), $LANG] ];
983
 
        if (not defined $time_start) {
984
 
            warn "no start time for title $title, skipping programme";
985
 
            next;
986
 
        }
 
1010
 
 
1011
#   <span class='time'>07:00</span><h3>NEWS</h3><p>Le notizie del giorno una finestra sull'attualita' e la cronaca.</p></li>
 
1012
        $line=~/<span class=\'time\'>(.*?)<\/span><h3>(.*?)<\/h3><p>(.*?)<\/p>/;
 
1013
 
 
1014
    my %programme = ();
 
1015
    my ($title, $time_start, $description) = ($2, $1, $3);
 
1016
    
 
1017
    if ($title=~/<a href.*?>(.*?)<\/a/) {$title = $1;}
 
1018
 
 
1019
        # Three mandatory fields: title, start, channel.
 
1020
    if (not defined $title) {
 
1021
        warn 'no title found, skipping programme';
 
1022
        next;
 
1023
    }
 
1024
        $programme{title}=[[tidy($title), $LANG] ];
 
1025
    if (not defined $time_start) {
 
1026
        warn "no start time for title $title, skipping programme";
 
1027
        next;
 
1028
    }
987
1029
        
988
1030
        $programme{desc}=[[tidy($description), $LANG] ] if ($description ne '');
989
1031
        $programme{start}=xmltv_date($time_start, $offset);
990
1032
 
991
 
        if ($time_start2 <7.05 and $time_start2>=0) {
 
1033
        my $time_start2 = $time_start;
 
1034
        $time_start2=~s/://;
 
1035
 
 
1036
        if ($time_start2 <700 and $time_start2>=0) {
992
1037
            $programme{start}=xmltv_date($time_start, $offset + 1);
993
1038
            }
994
1039
        else {
995
1040
            $programme{start}=xmltv_date($time_start, $offset);
996
1041
        }
997
1042
 
998
 
 
999
 
        if ($time_stop2 <=7.05 and $time_stop2>=0) { #they can work as decimals, 0.32 < 23.44
1000
 
            $programme{stop}=xmltv_date($time_stop, $offset + 1);
1001
 
            }
1002
 
        else {
1003
 
            $programme{stop}=xmltv_date($time_stop, $offset);
1004
 
        }
1005
 
        $programme{channel}=$xmltv_id;
1006
 
 
1007
 
        #put info in array
1008
 
        push @programmes, {%programme};
 
1043
    $programme{channel}=$xmltv_id;
 
1044
 
 
1045
    #put info in array
 
1046
    push @programmes, {%programme};
1009
1047
    }
1010
1048
 
1011
1049
    if (scalar @programmes) {
1166
1204
 
1167
1205
        my @canali = split /\n/, $content;
1168
1206
        foreach my $canale (@canali) {
1169
 
                #{id:"101",name:"SKY Cinema 1",number:"301",service:"101"}
1170
 
                $canale=~/\{id:\"(.*?)\",name:\"(.*?)\",number:\"(.*?)\",service:\"(.*?)"}/;
 
1207
                #{"id":"101","name":"SKY Cinema 1","number":"301","service":"101","channellogo":"http://guidatv.sky.it/app/guidatv/images/epgimages/channels/grid/301_grid.gif"}
 
1208
                $canale=~/\{\"id\":\"(.*?)\",\"name\":\"(.*?)\",\"number\":\"(.*?)\",\"service\":\"(.*?)\",\"channellogo\":\"(.*?)\"}/;
1171
1209
                next if (not defined $2);
1172
 
                #print "|$1|$2|$3|$4|\n";
 
1210
                #print "|$1|$2|$3|$4|$5|\n";
1173
1211
                my $name = tidy($2);
1174
1212
                my $iconurl = $backend_info{skylife}{base_icon}.$3.'_grid.gif';
1175
1213
                my $channum = $3; #dove metto il 3???chi si ricorda??
1203
1241
 
1204
1242
    # build url to grab
1205
1243
    my $url = $backend_info{skylife}{base_data}.UnixDate(&DateCalc("today","+ ".$offset." days"), '%y_%m_%d').'/ch_'.$backend_info{skylife}{site_ids}{$xmltv_id}{chanid}.'.js';
1206
 
    
1207
 
          
 
1244
 
1208
1245
    #as with other grabber we trick memoize into not caching data
1209
1246
    #however, we do this only for the first day, other days use cache
1210
1247
    my $cachestring = "?pippo=".UnixDate("today","%Y%m%d%H") if ($offset == 0);
1230
1267
        warn "VERBOSE: parsing...\n" if ($opt_verbose);
1231
1268
          
1232
1269
        #split and parse the lines
1233
 
        my @lines = split /{id:/, $content;
 
1270
        my @lines = split /{\"id\":/, $content;
1234
1271
        foreach my $line (@lines) {
1235
 
          next if ($line=~/{channel/);
 
1272
          next if ($line=~/{\"channel\"/);
1236
1273
          
1237
1274
          my ($id, $pid, $start, $durata, $title, $title2, $desc, $cat, $cat2, $prima);
1238
 
          if ($line=~/\'(\d+?)\',\r\n   pid:\'(.*?)\',\r\n   starttime:\'(.*?)\',\r\n   dur:\'(\d+?)\',\r\n   title:\'(.*?)\',\r\n   normalizedtitle: \'(.*?)\',\r\n      desc:\'(.*?)\',\r\n   genre:\'(.*?)\',\r\n   subgenre:\'(.*)\',\r\n   prima:(.*)/m){
1239
 
                 ($id, $pid, $start, $durata, $title, $title2, $desc, $cat, $cat2, $prima) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);
1240
 
          }
1241
 
          elsif ($line=~/\'(\S+?)\',\r\n   pid:\'(.*?)\',\r\n   starttime:\'(.*?)\',\r\n   dur:\'(\d+?)\',\r\n   title:\'(.*?)\',\r\n   normalizedtitle: \'(.*?)\',\r\n      desc:\'(.*?)\',\r\n   genre:\'(.*?)\',\r\n   subgenre:\'(.*)\',\r\n   prima:(.*)/m){
 
1275
          if ($line=~/\"(\S+?)\",\s+\"pid\":\"(.*?)\",\s+\"starttime\":\"(.*?)\",\s+\"dur\":\"(\d+?)\",\s+\"title\":\"(.*?)\",\s+\"normalizedtitle\":\s*\"(.*?)\",\s+\"desc\":\"(.*?)\",\s+\"genre\":\"(.*?)\",\s+\"subgenre\":\"(.*)\",\s+\"prima\":(.*)/m){
1242
1276
                 ($id, $pid, $start, $durata, $title, $title2, $desc, $cat, $cat2, $prima) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);
1243
1277
          }
1244
1278
          else {
2314
2348
        next unless $start; 
2315
2349
        next unless $title;        
2316
2350
        my $start2=$start; $start2=~s/:/\./;
2317
 
        if ($start2 <=7 and $start2>=0) { #they can work as decimals, 0.32 < 23.44
 
2351
        if ($start2 <6 and $start2>=0) { #they can work as decimals, 0.32 < 23.44
2318
2352
                 push @prog_to_check, [$title, $tomorrowdate." ".$start];
2319
2353
              }
2320
2354
              else {
2470
2504
    }
2471
2505
}
2472
2506
 
2473
 
 
2474
 
# everything below this is experimental
2475
 
########################
2476
 
# search.ch  functions #
2477
 
########################
 
2507
#########################
 
2508
# dahliatv.it functions #
 
2509
#########################
2478
2510
 
2479
2511
####################################################
2480
 
# searchch_get_channels_list
2481
 
sub searchch_get_channels_list {
 
2512
# dahlia_get_channels_list
 
2513
sub dahlia_get_channels_list {
2482
2514
    my %chan_hash;
2483
2515
 
2484
 
    my $url = $backend_info{searchch}{base_chan};
 
2516
    my $url = $backend_info{dahlia}{base_chan};
2485
2517
    warn ($DEF_LANG eq 'eng' ?
2486
2518
                      "VERBOSE: Getting channel list from $url\n" :
2487
2519
                      "VERBOSE: Scarico la lista dei canali da $url\n") if ($opt_verbose);
2488
2520
 
2489
2521
    my $content;
2490
2522
    eval { $content = get_nice($url); };
 
2523
    $content=~/(.*?)box_canali_body/igm;
 
2524
    $content=$1;
2491
2525
 
2492
2526
    if ($@) {   #get_nice has died
2493
2527
            warn ($DEF_LANG eq 'eng' ? 
2494
 
                      "VERBOSE: Cannot get search.ch's channel list ($url). Site down?\n" : 
2495
 
                      "VERBOSE: Non sono riuscito a prendere la lista dei canali di search.ch ($url). Il sito non funziona?\n"
 
2528
                      "VERBOSE: Cannot get dahliatv.it's channel list ($url). Site down?\n" : 
 
2529
                      "VERBOSE: Non sono riuscito a prendere la lista dei canali di dahliatv.it ($url). Il sito non funziona?\n"
2496
2530
                        ) unless ($opt_quiet);
2497
2531
                    return ();
2498
2532
            } 
 
2533
            
2499
2534
 
2500
 
    my @lines = split /\n/, $content;
 
2535
    my @lines = split /<div class=\"/, $content;
2501
2536
    foreach my $line (@lines) {
2502
 
      if ($line=~/station\/detail.php\?id=(\d+)\".*?und Tagesprogramm zu (.*?)\"/) {
2503
 
         my ($channum, $channame)=(tidy($1), tidy($2));
2504
 
         next if (not defined $channum or not defined $channame);# or $channame eq 'TV-Sender' or $channame eq '--------------');
2505
 
         #      next if ($channame!~/tsi/igm);
2506
 
         
2507
 
         $url = $backend_info{searchch}{base_data}.'?id='.$channum;
2508
 
         my $iconurl = '/img/stationlogos_id/'.$channum.'.gif';
2509
 
         $chan_hash{$channame} = "$url";
2510
 
 
2511
 
         my $xmltv_id = xmltv_chanid('searchch', $channame);
2512
 
         $backend_info{searchch}{site_ids}{$xmltv_id}{site_id} = $channame;
2513
 
         $backend_info{searchch}{site_ids}{$xmltv_id}{icon} = $iconurl;
2514
 
         $backend_info{searchch}{site_ids}{$xmltv_id}{channum} = $channum;
 
2537
      if ($line=~/(.*?)\">/){
 
2538
#<div id="lun" class="panel">
 
2539
#div class="sport"></div><div class="sport2"></div><div class="extra"></div><div class="xtreme"></div><div class="eros"></div><div class="explorer"></div><div class="palermo"></div><div class="calcio1"></div><div class="calcio2"></div><div class="calcio3"></div><div class="calcio4"></div><div class="calcio5"></div><div class="adult1"></div><div class="adult2"></div><div class="adult3"></div></div><div id="mar" class="panel">
 
2540
 
 
2541
 
 
2542
 
 
2543
         my ($channame)=(tidy($1));
 
2544
         next if (not defined $channame);
 
2545
         
 
2546
         $chan_hash{$channame} = $backend_info{dahlia}{base_data};
 
2547
 
 
2548
         
 
2549
         my $xmltv_id = xmltv_chanid('dahlia', $channame);
 
2550
         $backend_info{dahlia}{site_ids}{$xmltv_id}{site_id} = $channame;
2515
2551
         }      
2516
2552
    }
2517
2553
 
2518
2554
    return %chan_hash;
2519
2555
}
2520
2556
 
2521
 
sub searchch_fetch_data {
 
2557
####################################################
 
2558
# dahlia_fetch_data
 
2559
# 2 parameters: xmltv_id of channel 
 
2560
#               day offset
 
2561
# returns an error or an array of data
 
2562
 
 
2563
sub dahlia_fetch_data {
2522
2564
    my ($xmltv_id, $offset) = @_;
2523
2565
    my $content;
2524
 
    
2525
 
    my %langs = (
2526
 
       'Deutsch' => 'de',
2527
 
       'Franz�sisch' => 'fr',
2528
 
       'Italienisch' => 'it',
2529
 
       'Englisch' => 'en',
2530
 
    );
2531
 
    
2532
 
    my $sprache = 'error!';
2533
 
 
2534
 
    my $site_id = $backend_info{searchch}{site_ids}{$xmltv_id}{site_id};
 
2566
 
 
2567
    my $site_id = $backend_info{dahlia}{site_ids}{$xmltv_id}{site_id};
 
2568
 
2535
2569
    if (not defined $site_id) {
2536
2570
        warn ($DEF_LANG eq 'eng' ?
2537
2571
                         "VERBOSE: \tThis site doesn't know about $xmltv_id!\n" : 
2539
2573
        return (1, ());
2540
2574
    }
2541
2575
 
2542
 
    # build url to grab
2543
 
    my $date  = UnixDate(&DateCalc("today","+ ".($offset)." days"), '%Y-%m-%d');
2544
 
    my $url = $backend_info{searchch}{base_data}.'?id='.$backend_info{searchch}{site_ids}{$xmltv_id}{channum}.'&day='.$date;
 
2576
    my %chan = %{$backend_info{dahlia}{channels}};
 
2577
    my $channel_name  = $backend_info{dahlia}{site_ids}{$xmltv_id}{site_id};
 
2578
 
 
2579
    my $date_grab = &DateCalc("today","+ ".$offset." days");
 
2580
 
 
2581
 
 
2582
    die ($DEF_LANG eq 'eng' ? 'date calculation failed' : 'errore di calcolo di data') if not defined $date_grab;
 
2583
    $date_grab = UnixDate($date_grab, '%Y%m%d');
 
2584
 
 
2585
    my $url = $backend_info{dahlia}{base_data};
2545
2586
 
2546
2587
    #to trick memoize into not caching data with add a string to the url, based on time, with hourly resolution
2547
2588
    #so if we redownload data within 5 minutes (we are within the same run) it comes from the cache
2549
2590
    #this makes sense if you use the --cache option and you want to cache only the --slow data, to speed up things 
2550
2591
    #when you grab data every two-three days, but you don't want to miss schedule changes
2551
2592
    #this string is ignored by the server
2552
 
    
2553
 
    my $cachestring = "&pippo=".UnixDate("today","%Y%m%d%H");
2554
 
 
2555
 
    my $grabdate      = UnixDate(&DateCalc("today","+ ".$offset." days"), '%Y%m%d');
2556
 
    my $tomorrowdate      = UnixDate(&DateCalc("today","+ ".($offset+1)." days"), '%Y%m%d');    
2557
 
            
2558
 
    my @prog_to_check = ();
2559
 
 
2560
 
    my $offset2 = 0;
2561
 
    my $starttime = ParseDate("$grabdate 00:00");
2562
 
    die 'date calculation failed' if (! $starttime);
2563
 
 
2564
 
    $url.=$cachestring if ($opt_cache_slow);
2565
 
 
2566
 
    warn "VERBOSE: fetching $url\n"  if ($opt_verbose);
 
2593
    if ($opt_cache_slow) {
 
2594
            my $cachestring = "?pippo=".UnixDate("today","%Y%m%d%H");
 
2595
                $url.=$cachestring;
 
2596
        }
 
2597
    warn ($DEF_LANG eq 'eng' ? 
 
2598
                  "VERBOSE: fetching $url\n" :
 
2599
                  "VERBOSE: scarico $url\n") if ($opt_verbose);
2567
2600
 
2568
2601
    eval { $content=get_nice($url) };
2569
2602
    if ($@) {   #get_nice has died
2570
 
            warn ($DEF_LANG eq 'eng' ? 
2571
 
                      "VERBOSE: Error fetching $url channel $xmltv_id day $offset backend skylife\n" :
2572
 
                      "VERBOSE: Errore nello scaricare $url, canale $xmltv_id, giorno $offset, fonte skylife\n") if ($opt_verbose);
2573
 
 
2574
 
            # Indicate to the caller that we had problems
2575
 
            return (1, ());
2576
 
        } 
2577
 
 
 
2603
        warn ($DEF_LANG eq 'eng' ? 
 
2604
                          "VERBOSE: Error fetching $url channel $xmltv_id day $offset backend dahlia\n" :
 
2605
                          "VERBOSE: Errore nello scaricare $url, canale $xmltv_id, giorno $offset, fonte dahlia\n") if ($opt_verbose);
 
2606
 
 
2607
        # Indicate to the caller that we had problems
 
2608
        return (1, ());
 
2609
    } 
 
2610
 
 
2611
    my @programmes = ();
2578
2612
    warn "VERBOSE: parsing...\n" if ($opt_verbose);
2579
 
 
2580
 
    #check language
2581
 
    $content=~/>Sprache: <\/td><td class="text">(.*?)<\/td>/;
2582
 
    $sprache = $langs{$1} || 'error!';
2583
2613
    
2584
 
    #is there data?
2585
 
    if ($content=~/Es wurden keine Sendungen gefunden/){
2586
 
       #warn "canale $xmltv_id -> no data!\n";
 
2614
    my $grabdate  = UnixDate(&DateCalc("today","+ ".($offset)." days"), '%Y/%m/%d');
 
2615
    #split and parse
 
2616
    my @p = split /<Event/, $content;
 
2617
        foreach my $pr (@p) {
 
2618
               $pr=~/NAME=\"(.*?)\" SERVICENAME=\"(.*?)\" SYNOPSIS=\"(.*?)\" TIMEOFFSET=\"(.*?)\" date=\"(.*?)\" dayofweek=\"(.*?)\" theme=\"(.*?)\" time=\"(.*?)\" visualduration=\"(.*?)\" visualtime=\"(.*)\"/;
 
2619
               
 
2620
#        <Event ALFAORDER="A" DURATION="00:55:00" EVENT_TYPE="FTA" LOG_LINE="" MINIMALAGE="0" NAME="CESENA VS MILAN" SERVICENAME="calcio2" 
 
2621
#        SYNOPSIS="CAMPIONATO SERIE  A TIM - CESENA VS MILAN - ANTICIPO 2A GIORNATA ANDATA" 
 
2622
#        TIMEOFFSET="+2" date="2010/09/11" dayofweek="Sabato" theme="Calcio" time="20:40:00" visualduration="00:55:00" visualtime="20:40"/>
 
2623
         
 
2624
                my ($title, $channel, $desc, $date, $category, $time_start, $duration, $visualtime) = ($1, $2, $3, $5, $7, $8, $9, $10);
 
2625
                next unless $title;
 
2626
                next if $xmltv_id ne xmltv_chanid('dahlia', $channel);
 
2627
                next if $date ne $grabdate;
 
2628
                next if $visualtime=~/ del /;           
 
2629
                $date=~/(....).(..).(..)/; $date="$1$2$3";
 
2630
                $time_start=~/(..).(..).(..)/; $time_start=$date."$1$2$3";
 
2631
 
 
2632
                my %programme = ();
 
2633
                
 
2634
#         $time_end=~s/:/\./; $time_start=~s/:/\./;             
 
2635
#         my $next_day_end = 0; my $next_day_start = 0;         
 
2636
#         if ($time_end < 6) {
 
2637
#                   $next_day_end = 1;
 
2638
#à              }
 
2639
#         if ($time_start < 6) {
 
2640
#                   $next_day_start = 1;
 
2641
#                   $next_day_end = 1;
 
2642
#               }
 
2643
#         $time_end=~s/\./:/; $time_start=~s/\./:/;             
 
2644
#               $programme{stop}=xmltv_date($time_end, $offset + $next_day_end);
 
2645
 
 
2646
 
 
2647
                # Three mandatory fields: title, start, channel.
 
2648
                if (not defined $title) {
 
2649
                        warn ($DEF_LANG eq 'eng' ? 'no title found, skipping programme' : 'titolo non trovato, salto');
 
2650
                        next;
 
2651
                }
 
2652
                        $programme{title}=[[tidy($title), $LANG] ];
 
2653
                if (not defined $time_start) {
 
2654
                        warn ($DEF_LANG eq 'eng' ? "no start time for title $title, skipping programme" : "nessun orario di inizio per $title, salto");
 
2655
                        next;
 
2656
                }
 
2657
                #$time_start=~s/://;
 
2658
                $programme{start}=utc_offset($time_start, '+0100');
 
2659
                if (not defined $xmltv_id) {
 
2660
                        warn ($DEF_LANG eq 'eng' ? "no channel for programme $title at $time_start, skipping programme" : "canale non trovato per $title alle $time_start, salto");
 
2661
                        next;
 
2662
                }
 
2663
                $duration=~/(..).(..).(..)/;
 
2664
                my $time_stop = &DateCalc("$time_start","+ $1 hours $2 minutes $3 seconds");
 
2665
                $time_stop=~s/\://g;
 
2666
                $programme{stop}=utc_offset($time_stop, '+0100');
 
2667
                $programme{channel}=$xmltv_id;
 
2668
                $programme{title} = [[tidy($title), $LANG] ] if (defined $title);
 
2669
                $programme{category}=[[tidy($category), $LANG ]] if defined $category;
 
2670
                $programme{desc}=[[tidy($desc), $LANG ]] if (defined $desc and $desc ne '');
 
2671
 
 
2672
                #put info in array
 
2673
                push @programmes, {%programme};
 
2674
        }
 
2675
 
 
2676
    if (scalar @programmes) {
 
2677
        return (0, @programmes);
2587
2678
    }
2588
2679
    else {
2589
 
      #split and parse the lines
2590
 
      $content=~/<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">(.*?)<\/table>/s;
2591
 
      $content=$1;
2592
 
      $content=~s/[\n|\r]+//isgm;
2593
 
  
2594
 
      my @lines = split /<tr>/, $content;
2595
 
  
2596
 
      foreach my $line (@lines) {
2597
 
          $line=~/valign=\"top\">(.*?)<\/td>.*<td width=\"100%\"><a href=\"(.*?)\">(.*?)<\/a>(.*?)<\/td>/;
2598
 
              next if not defined $1;
2599
 
        
2600
 
              my ($starttime, $detail, $title, $category) = (tidy($1), tidy($2), tidy($3), tidy($4));
2601
 
        
2602
 
              if ($category=~/\((.*?)\)/){$category=$1};
2603
 
              my $starttime2=$starttime; $starttime2=~s/:/./;
2604
 
              if ($starttime2<6) {
2605
 
                 $starttime = ParseDate("$tomorrowdate $starttime");
2606
 
                 }
2607
 
              else {
2608
 
             $starttime = ParseDate("$grabdate $starttime");    
2609
 
          }
2610
 
          push @prog_to_check, [$title, $detail, $starttime, $category];
2611
 
      }
2612
 
    }
2613
 
 
 
2680
        # there is a number of reasons why we could get an empty array.
 
2681
        # so we return an error 
 
2682
        return (1, @programmes);
 
2683
    }
 
2684
}
 
2685
 
 
2686
########################
 
2687
# la7.it functions #
 
2688
########################
 
2689
 
 
2690
#########################################################
 
2691
# _get_channels_list
 
2692
# since this site only has two channels this is a fake sub
 
2693
sub la7_get_channels_list {
 
2694
    my %chan_hash = ( 'La7' ,'www.la7.it', 'La7D', 'www.la7d.it');
 
2695
 
 
2696
    return %chan_hash;
 
2697
}
 
2698
####################################################
 
2699
# la7_fetch_data
 
2700
# 2 parameters: xmltv_id of channel 
 
2701
#               day offset
 
2702
# returns an error or an array of data
 
2703
sub la7_fetch_data {
 
2704
    my ($xmltv_id, $offset) = @_;
 
2705
    my $content;
 
2706
 
 
2707
    my $site_id = $backend_info{la7}{site_ids}{$xmltv_id}{site_id};
 
2708
    if (not defined $site_id) {
 
2709
        warn ($DEF_LANG eq 'eng' ?
 
2710
                         "VERBOSE: \tThis site doesn't know about $xmltv_id!\n" : 
 
2711
                         "VERBOSE: \tQuesto sito non sa niente di $xmltv_id!\n" ) if ($opt_verbose);
 
2712
        return (1, ());
 
2713
    }
 
2714
 
 
2715
    # adds today date after url to avoid using today's data for tomorrow
 
2716
    my $cachestring = "?pippo=".UnixDate("today","%Y%m%d");
 
2717
 
 
2718
    my $url = $backend_info{la7}{base_data}.$offset.'.html'.$cachestring;  
 
2719
    $url=~ s/index_0/index/;
 
2720
 
 
2721
 
 
2722
    warn ($DEF_LANG eq 'eng' ?
 
2723
              "VERBOSE: fetching $url\n" :
 
2724
              "VERBOSE: scarico $url\n") if ($opt_verbose);
 
2725
 
 
2726
    eval { $content=get_nice($url) };
 
2727
    if ($@) {   #get_nice has died
 
2728
        warn "errore get_nice";
 
2729
        return (1, ());
 
2730
    } 
 
2731
    
2614
2732
    my @programmes = ();
2615
2733
 
2616
 
    my $parse_date = &DateCalc("today 00:00","+ ".$offset." days");
2617
 
    my $next_day   = &DateCalc("today 00:00","+ ".($offset + 1)." days");
2618
 
 
2619
 
    foreach (@prog_to_check) {
 
2734
    my @lines = split /<li>\n<div class=\"sx\">\n/, $content;
 
2735
 
 
2736
    my $got_la7d = 0;
 
2737
    
 
2738
    foreach my $line (@lines) {
 
2739
 
 
2740
        # Reach La7D
 
2741
        if( !$got_la7d && $xmltv_id eq 'www.la7d.it' ) {
 
2742
            next unless ($line =~ /<div id=\"palinsesto_la7d\"/);
 
2743
            $got_la7d = 1;
 
2744
            next;
 
2745
        }
 
2746
 
 
2747
        # Reach begin of programs
 
2748
        next unless $line=~/<p class=\"ora/;
 
2749
 
2620
2750
        my %programme = ();
2621
 
        my ($title, $detail, $start, $category) = @$_;
2622
 
              my $subtitle = undef;
2623
 
              
2624
 
              if ($title=~/(.*) \((.*?)\)$/) {unless (defined $category) {$title=$1;   $category=$2};}# warn "$xmltv_id tit $title cat  $category ";exit;}
2625
 
              if ($title=~/(.*) - (.*)/) {$title=$1; $subtitle=$2;}
2626
 
        $programme{title} = [[tidy($title), $sprache] ];
2627
 
        $programme{start} = utc_offset(UnixDate($start, '%Y%m%d%H%M').'00', '+0100');
2628
 
        $programme{channel} = $xmltv_id;
2629
 
        $programme{'sub-title'}=[[$subtitle, $sprache] ] if (defined $subtitle);        
2630
 
        if ($category){
2631
 
           $category = tr_cat(tidy($category));
2632
 
           push @{$programme{category}}, [tidy($category), 'de' ]
 
2751
        
 
2752
        $line=~/<p class=\"ora\">(.*?)<\/p>\n<h5>\n(.*?)\n<\/h5>.*?\n.*?\n.*?\n.*?\n(.*?)\n/m;
 
2753
        $line=~/<p class=\"ora\">(.*?)<\/p>\n<h5>\n<a.*\">\n(.*?)\n<\/a>.*?\n.*?\n.*?\n.*?\n.*?\n(.*?)\n/m;
 
2754
        my ($time_start, $title, $desc) = ($1,$2, $3);
 
2755
 
 
2756
        # Three mandatory fields: title, start, channel.
 
2757
        if (not defined $title) {
 
2758
            warn 'no title found, skipping programme';
 
2759
            next;
 
2760
        }
 
2761
        $programme{title}=[[tidy($title), $LANG] ];
 
2762
        if (not defined $time_start) {
 
2763
            warn "no start time for title $title, skipping programme";
 
2764
            next;
 
2765
        }
 
2766
 
 
2767
        my $time_start2 = $time_start;
 
2768
        $time_start2=~s/://;
 
2769
    
 
2770
        if ($time_start2 <600 and $time_start2>=0) {
 
2771
            $time_start = xmltv_date($time_start, $offset + 1);
 
2772
            }
 
2773
        else {
 
2774
            $time_start = xmltv_date($time_start, $offset );
 
2775
        }
 
2776
    
 
2777
        $programme{start}=$time_start;#xmltv_date($time_start, $offset + $past_midnight);
 
2778
        $programme{channel}=$xmltv_id;
 
2779
        $programme{desc}=[[tidy($desc), $LANG ]] if (defined $desc and $desc ne '');
 
2780
        
 
2781
        #put info in array
 
2782
        push @programmes, {%programme};
 
2783
 
 
2784
        # This check must be at the end of the cycle,
 
2785
        # otherwise we loose the last program of every day
 
2786
        if( $xmltv_id eq 'www.la7.it' ) {
 
2787
            # Stop at the end of La7
 
2788
            last if ($line =~ /<div id=\"palinsesto_la7d\"/);
 
2789
        }
 
2790
    
 
2791
    }
 
2792
 
 
2793
        if (scalar @programmes) {
 
2794
        return (0, @programmes);
 
2795
    }
 
2796
    else {
 
2797
        # there is a number of reasons why we could get an empty array.
 
2798
        # so we return an error 
 
2799
        return (1, @programmes);
 
2800
    }
 
2801
}
 
2802
 
 
2803
 
 
2804
#########################
 
2805
# mediaset.it functions #
 
2806
#########################
 
2807
 
 
2808
####################################################
 
2809
# mediaset_get_channels_list
 
2810
sub mediaset_get_channels_list {
 
2811
    my %chan_hash;
 
2812
    
 
2813
    my $url = $backend_info{mediaset}{base_chan};
 
2814
    warn ($DEF_LANG eq 'eng' ?
 
2815
                      "VERBOSE: Getting channel list from $url\n" :
 
2816
                      "VERBOSE: Scarico la lista dei canali da $url\n") if ($opt_verbose);
 
2817
 
 
2818
    my $content;
 
2819
    eval { $content = get_nice($url); };
 
2820
            if ($@) {   #get_nice has died
 
2821
                    warn ($DEF_LANG eq 'eng' ? 
 
2822
                                  "VERBOSE: Cannot get mediaset's channel list ($url). Site \\n" : 
 
2823
                                  "VERBOSE: Non sono riuscito a prendere la lista dei canali di mediaset ($url). Il sito non funziona?\n") unless ($opt_quiet);
 
2824
                    return ();
 
2825
            }
 
2826
 
 
2827
    my @canali = split /\n/, $content;
 
2828
    
 
2829
    foreach my $canale (@canali) {
 
2830
      next unless $canale=~/rete nome=\"(.*?)\" id=\"(.*?)\"/;
 
2831
      next if (not defined $1);
 
2832
      my $name = tidy($1);
 
2833
      next if defined $chan_hash{$name};
 
2834
      $chan_hash{$name} = "$2";
 
2835
      
 
2836
      #update backend info, in case this is a new channel not in channel_ids
 
2837
      my $xmltv_id = xmltv_chanid('mediaset', $name);
 
2838
      $backend_info{mediaset}{site_ids}{$xmltv_id}{site_id} = $name;
 
2839
      $backend_info{mediaset}{site_ids}{$xmltv_id}{chanid} = $chan_hash{$name};                
 
2840
   }
 
2841
 
 
2842
  return %chan_hash;
 
2843
}
 
2844
 
 
2845
####################################################
 
2846
# mediaset_fetch_data
 
2847
# 2 parameters: xmltv_id of channel 
 
2848
#               day offset
 
2849
# returns an error or an array of data
 
2850
 
 
2851
sub mediaset_fetch_data {
 
2852
    my ($xmltv_id, $offset) = @_;
 
2853
    my $content;
 
2854
 
 
2855
    my $site_id = $backend_info{mediaset}{site_ids}{$xmltv_id}{chanid};
 
2856
 
 
2857
    if (not defined $site_id) {
 
2858
        warn ($DEF_LANG eq 'eng' ?
 
2859
                         "VERBOSE: \tThis site doesn't know about $xmltv_id!\n" : 
 
2860
                         "VERBOSE: \tQuesto sito non sa niente di $xmltv_id!\n" ) if ($opt_verbose);
 
2861
        return (1, ());
 
2862
    }
 
2863
 
 
2864
    my %chan = %{$backend_info{mediaset}{channels}};
 
2865
 
 
2866
    my $date_grab = &DateCalc("today","+ ".$offset." days");
 
2867
 
 
2868
 
 
2869
    die ($DEF_LANG eq 'eng' ? 'date calculation failed' : 'errore di calcolo di data') if not defined $date_grab;
 
2870
    $date_grab = UnixDate($date_grab, '%Y%m%d');
 
2871
 
 
2872
    my $url = $backend_info{mediaset}{base_data};
 
2873
 
 
2874
    #to trick memoize into not caching data with add a string to the url, based on time, with hourly resolution
 
2875
    #so if we redownload data within 5 minutes (we are within the same run) it comes from the cache
 
2876
    #but if we download it tomorrow it doesn't.
 
2877
    #this makes sense if you use the --cache option and you want to cache only the --slow data, to speed up things 
 
2878
    #when you grab data every two-three days, but you don't want to miss schedule changes
 
2879
    #this string is ignored by the server
 
2880
    if ($opt_cache_slow) {
 
2881
            my $cachestring = "?pippo=".UnixDate("today","%Y%m%d%H");
 
2882
                $url.=$cachestring;
2633
2883
        }
2634
 
        #searchch_fetch_data_slow($detail, \%programme) if ($opt_slow);
2635
 
        push @programmes, {%programme} if ($start and $title);
2636
 
           }
2637
 
  
 
2884
    warn ($DEF_LANG eq 'eng' ? 
 
2885
                  "VERBOSE: fetching $url\n" :
 
2886
                  "VERBOSE: scarico $url\n") if ($opt_verbose);
 
2887
 
 
2888
    eval { $content=get_nice($url) };
 
2889
    if ($@) {   #get_nice has died
 
2890
        warn ($DEF_LANG eq 'eng' ? 
 
2891
                          "VERBOSE: Error fetching $url channel $xmltv_id day $offset backend mediasetpremium\n" :
 
2892
                          "VERBOSE: Errore nello scaricare $url, canale $xmltv_id, giorno $offset, fonte mediasetpremium\n") if ($opt_verbose);
 
2893
 
 
2894
        # Indicate to the caller that we had problems
 
2895
        return (1, ());
 
2896
    } 
 
2897
 
 
2898
    my @programmes = ();
 
2899
    warn "VERBOSE: parsing...\n" if ($opt_verbose);
 
2900
 
 
2901
    #split and parse
 
2902
    my @p = split /\n/, $content;
 
2903
        foreach my $pr (@p) {
 
2904
                next unless $pr=~/$site_id/;
 
2905
                next unless $pr=~/$date_grab/;
 
2906
                next unless $pr=~/programma idref=\"(.*?)\" timestamp=\"(.*?)\" criptato=\"(.*?)\" titolo=\"(.*?)\" ora=\"(.*?)\"/;
 
2907
#               warn $pr."-----------------\n";
 
2908
#               warn "|$1|$2|$3|$4|$5|\n";
 
2909
                my %programme = ();
 
2910
                my ($id, $time_start, $criptato, $title) = ($1, $5, $3, $4);
 
2911
                
 
2912
                next unless $title;     
 
2913
                
 
2914
#         $time_end=~s/:/\./; $time_start=~s/:/\./;             
 
2915
#         my $next_day_end = 0; my $next_day_start = 0;         
 
2916
#         if ($time_end < 6) {
 
2917
#                   $next_day_end = 1;
 
2918
#               }
 
2919
#         if ($time_start < 6) {
 
2920
#                   $next_day_start = 1;
 
2921
#                   $next_day_end = 1;
 
2922
#               }
 
2923
#         $time_end=~s/\./:/; $time_start=~s/\./:/;             
 
2924
#               $programme{stop}=xmltv_date($time_end, $offset + $next_day_end);
 
2925
 
 
2926
 
 
2927
                # Three mandatory fields: title, start, channel.
 
2928
                if (not defined $title) {
 
2929
                        warn ($DEF_LANG eq 'eng' ? 'no title found, skipping programme' : 'titolo non trovato, salto');
 
2930
                        next;
 
2931
                }
 
2932
                        $programme{title}=[[tidy($title), $LANG] ];
 
2933
                if (not defined $time_start) {
 
2934
                        warn ($DEF_LANG eq 'eng' ? "no start time for title $title, skipping programme" : "nessun orario di inizio per $title, salto");
 
2935
                        next;
 
2936
                }
 
2937
                #$time_start=~s/://;
 
2938
                $programme{start}=xmltv_date($time_start, $offset);
 
2939
                if (not defined $xmltv_id) {
 
2940
                        warn ($DEF_LANG eq 'eng' ? "no channel for programme $title at $time_start, skipping programme" : "canale non trovato per $title alle $time_start, salto");
 
2941
                        next;
 
2942
                }
 
2943
 
 
2944
                $programme{channel}=$xmltv_id;
 
2945
                $programme{title} = [[tidy($title), $LANG] ] if (defined $title);
 
2946
 
 
2947
                #put info in array
 
2948
                push @programmes, {%programme};
 
2949
    }
 
2950
 
2638
2951
    if (scalar @programmes) {
2639
2952
        return (0, @programmes);
2640
2953
    }
2644
2957
        return (1, @programmes);
2645
2958
    }
2646
2959
}
2647
 
 
2648
 
 
2649
 
sub tr_cat {
2650
 
    my $cat = shift;
2651
 
    return "Film" if $cat=~/Abenteuer|Action|Kom�die|Krimi|Drama|Fantasy/;
2652
 
    return "Film" if $cat=~/Geschichte|Horror|Kurzfilm|Liebesfilm|Thriller|Trickfilm|Western/;
2653
 
    return "Sit Com" if $cat=~/Serie|SERIE|Sitcom/;
2654
 
    return $cat;
2655
 
}
2656