961
1007
#split the lines
962
1008
foreach my $line (@lines) {
963
1009
next unless $line=~/span class=\'time\'/;
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>/;
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";
973
if ($title=~/<a href.*?>(.*?)<\/a/) {$title = $1;}
975
#warn "$title, $time_start, $time_stop, $description\n";
977
# Three mandatory fields: title, start, channel.
978
if (not defined $title) {
979
warn 'no title found, skipping programme';
982
$programme{title}=[[tidy($title), $LANG] ];
983
if (not defined $time_start) {
984
warn "no start time for title $title, skipping programme";
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>/;
1015
my ($title, $time_start, $description) = ($2, $1, $3);
1017
if ($title=~/<a href.*?>(.*?)<\/a/) {$title = $1;}
1019
# Three mandatory fields: title, start, channel.
1020
if (not defined $title) {
1021
warn 'no title found, skipping programme';
1024
$programme{title}=[[tidy($title), $LANG] ];
1025
if (not defined $time_start) {
1026
warn "no start time for title $title, skipping programme";
988
1030
$programme{desc}=[[tidy($description), $LANG] ] if ($description ne '');
989
1031
$programme{start}=xmltv_date($time_start, $offset);
991
if ($time_start2 <7.05 and $time_start2>=0) {
1033
my $time_start2 = $time_start;
1034
$time_start2=~s/://;
1036
if ($time_start2 <700 and $time_start2>=0) {
992
1037
$programme{start}=xmltv_date($time_start, $offset + 1);
995
1040
$programme{start}=xmltv_date($time_start, $offset);
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);
1003
$programme{stop}=xmltv_date($time_stop, $offset);
1005
$programme{channel}=$xmltv_id;
1008
push @programmes, {%programme};
1043
$programme{channel}=$xmltv_id;
1046
push @programmes, {%programme};
1011
1049
if (scalar @programmes) {
2474
# everything below this is experimental
2475
########################
2476
# search.ch functions #
2477
########################
2507
#########################
2508
# dahliatv.it functions #
2509
#########################
2479
2511
####################################################
2480
# searchch_get_channels_list
2481
sub searchch_get_channels_list {
2512
# dahlia_get_channels_list
2513
sub dahlia_get_channels_list {
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);
2490
2522
eval { $content = get_nice($url); };
2523
$content=~/(.*?)box_canali_body/igm;
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);
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);
2507
$url = $backend_info{searchch}{base_data}.'?id='.$channum;
2508
my $iconurl = '/img/stationlogos_id/'.$channum.'.gif';
2509
$chan_hash{$channame} = "$url";
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">
2543
my ($channame)=(tidy($1));
2544
next if (not defined $channame);
2546
$chan_hash{$channame} = $backend_info{dahlia}{base_data};
2549
my $xmltv_id = xmltv_chanid('dahlia', $channame);
2550
$backend_info{dahlia}{site_ids}{$xmltv_id}{site_id} = $channame;
2518
2554
return %chan_hash;
2521
sub searchch_fetch_data {
2557
####################################################
2559
# 2 parameters: xmltv_id of channel
2561
# returns an error or an array of data
2563
sub dahlia_fetch_data {
2522
2564
my ($xmltv_id, $offset) = @_;
2527
'Franz�sisch' => 'fr',
2528
'Italienisch' => 'it',
2532
my $sprache = 'error!';
2534
my $site_id = $backend_info{searchch}{site_ids}{$xmltv_id}{site_id};
2567
my $site_id = $backend_info{dahlia}{site_ids}{$xmltv_id}{site_id};
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" :
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
2553
my $cachestring = "&pippo=".UnixDate("today","%Y%m%d%H");
2555
my $grabdate = UnixDate(&DateCalc("today","+ ".$offset." days"), '%Y%m%d');
2556
my $tomorrowdate = UnixDate(&DateCalc("today","+ ".($offset+1)." days"), '%Y%m%d');
2558
my @prog_to_check = ();
2561
my $starttime = ParseDate("$grabdate 00:00");
2562
die 'date calculation failed' if (! $starttime);
2564
$url.=$cachestring if ($opt_cache_slow);
2566
warn "VERBOSE: fetching $url\n" if ($opt_verbose);
2593
if ($opt_cache_slow) {
2594
my $cachestring = "?pippo=".UnixDate("today","%Y%m%d%H");
2597
warn ($DEF_LANG eq 'eng' ?
2598
"VERBOSE: fetching $url\n" :
2599
"VERBOSE: scarico $url\n") if ($opt_verbose);
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);
2574
# Indicate to the caller that we had problems
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);
2607
# Indicate to the caller that we had problems
2611
my @programmes = ();
2578
2612
warn "VERBOSE: parsing...\n" if ($opt_verbose);
2581
$content=~/>Sprache: <\/td><td class="text">(.*?)<\/td>/;
2582
$sprache = $langs{$1} || 'error!';
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');
2616
my @p = split /<Event/, $content;
2617
foreach my $pr (@p) {
2618
$pr=~/NAME=\"(.*?)\" SERVICENAME=\"(.*?)\" SYNOPSIS=\"(.*?)\" TIMEOFFSET=\"(.*?)\" date=\"(.*?)\" dayofweek=\"(.*?)\" theme=\"(.*?)\" time=\"(.*?)\" visualduration=\"(.*?)\" visualtime=\"(.*)\"/;
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"/>
2624
my ($title, $channel, $desc, $date, $category, $time_start, $duration, $visualtime) = ($1, $2, $3, $5, $7, $8, $9, $10);
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";
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;
2639
# if ($time_start < 6) {
2640
# $next_day_start = 1;
2641
# $next_day_end = 1;
2643
# $time_end=~s/\./:/; $time_start=~s/\./:/;
2644
# $programme{stop}=xmltv_date($time_end, $offset + $next_day_end);
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');
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");
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");
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 '');
2673
push @programmes, {%programme};
2676
if (scalar @programmes) {
2677
return (0, @programmes);
2589
#split and parse the lines
2590
$content=~/<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">(.*?)<\/table>/s;
2592
$content=~s/[\n|\r]+//isgm;
2594
my @lines = split /<tr>/, $content;
2596
foreach my $line (@lines) {
2597
$line=~/valign=\"top\">(.*?)<\/td>.*<td width=\"100%\"><a href=\"(.*?)\">(.*?)<\/a>(.*?)<\/td>/;
2598
next if not defined $1;
2600
my ($starttime, $detail, $title, $category) = (tidy($1), tidy($2), tidy($3), tidy($4));
2602
if ($category=~/\((.*?)\)/){$category=$1};
2603
my $starttime2=$starttime; $starttime2=~s/:/./;
2604
if ($starttime2<6) {
2605
$starttime = ParseDate("$tomorrowdate $starttime");
2608
$starttime = ParseDate("$grabdate $starttime");
2610
push @prog_to_check, [$title, $detail, $starttime, $category];
2680
# there is a number of reasons why we could get an empty array.
2681
# so we return an error
2682
return (1, @programmes);
2686
########################
2687
# la7.it functions #
2688
########################
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');
2698
####################################################
2700
# 2 parameters: xmltv_id of channel
2702
# returns an error or an array of data
2703
sub la7_fetch_data {
2704
my ($xmltv_id, $offset) = @_;
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);
2715
# adds today date after url to avoid using today's data for tomorrow
2716
my $cachestring = "?pippo=".UnixDate("today","%Y%m%d");
2718
my $url = $backend_info{la7}{base_data}.$offset.'.html'.$cachestring;
2719
$url=~ s/index_0/index/;
2722
warn ($DEF_LANG eq 'eng' ?
2723
"VERBOSE: fetching $url\n" :
2724
"VERBOSE: scarico $url\n") if ($opt_verbose);
2726
eval { $content=get_nice($url) };
2727
if ($@) { #get_nice has died
2728
warn "errore get_nice";
2614
2732
my @programmes = ();
2616
my $parse_date = &DateCalc("today 00:00","+ ".$offset." days");
2617
my $next_day = &DateCalc("today 00:00","+ ".($offset + 1)." days");
2619
foreach (@prog_to_check) {
2734
my @lines = split /<li>\n<div class=\"sx\">\n/, $content;
2738
foreach my $line (@lines) {
2741
if( !$got_la7d && $xmltv_id eq 'www.la7d.it' ) {
2742
next unless ($line =~ /<div id=\"palinsesto_la7d\"/);
2747
# Reach begin of programs
2748
next unless $line=~/<p class=\"ora/;
2620
2750
my %programme = ();
2621
my ($title, $detail, $start, $category) = @$_;
2622
my $subtitle = undef;
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);
2631
$category = tr_cat(tidy($category));
2632
push @{$programme{category}}, [tidy($category), 'de' ]
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);
2756
# Three mandatory fields: title, start, channel.
2757
if (not defined $title) {
2758
warn 'no title found, skipping programme';
2761
$programme{title}=[[tidy($title), $LANG] ];
2762
if (not defined $time_start) {
2763
warn "no start time for title $title, skipping programme";
2767
my $time_start2 = $time_start;
2768
$time_start2=~s/://;
2770
if ($time_start2 <600 and $time_start2>=0) {
2771
$time_start = xmltv_date($time_start, $offset + 1);
2774
$time_start = xmltv_date($time_start, $offset );
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 '');
2782
push @programmes, {%programme};
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\"/);
2793
if (scalar @programmes) {
2794
return (0, @programmes);
2797
# there is a number of reasons why we could get an empty array.
2798
# so we return an error
2799
return (1, @programmes);
2804
#########################
2805
# mediaset.it functions #
2806
#########################
2808
####################################################
2809
# mediaset_get_channels_list
2810
sub mediaset_get_channels_list {
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);
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);
2827
my @canali = split /\n/, $content;
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";
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};
2845
####################################################
2846
# mediaset_fetch_data
2847
# 2 parameters: xmltv_id of channel
2849
# returns an error or an array of data
2851
sub mediaset_fetch_data {
2852
my ($xmltv_id, $offset) = @_;
2855
my $site_id = $backend_info{mediaset}{site_ids}{$xmltv_id}{chanid};
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);
2864
my %chan = %{$backend_info{mediaset}{channels}};
2866
my $date_grab = &DateCalc("today","+ ".$offset." days");
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');
2872
my $url = $backend_info{mediaset}{base_data};
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");
2634
#searchch_fetch_data_slow($detail, \%programme) if ($opt_slow);
2635
push @programmes, {%programme} if ($start and $title);
2884
warn ($DEF_LANG eq 'eng' ?
2885
"VERBOSE: fetching $url\n" :
2886
"VERBOSE: scarico $url\n") if ($opt_verbose);
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);
2894
# Indicate to the caller that we had problems
2898
my @programmes = ();
2899
warn "VERBOSE: parsing...\n" if ($opt_verbose);
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";
2910
my ($id, $time_start, $criptato, $title) = ($1, $5, $3, $4);
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;
2919
# if ($time_start < 6) {
2920
# $next_day_start = 1;
2921
# $next_day_end = 1;
2923
# $time_end=~s/\./:/; $time_start=~s/\./:/;
2924
# $programme{stop}=xmltv_date($time_end, $offset + $next_day_end);
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');
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");
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");
2944
$programme{channel}=$xmltv_id;
2945
$programme{title} = [[tidy($title), $LANG] ] if (defined $title);
2948
push @programmes, {%programme};
2638
2951
if (scalar @programmes) {
2639
2952
return (0, @programmes);