1 package NonameTV
::Importer
::TVGrabXX
;
8 Importer for data from other XMLTV sources using tv_grab_xx grabbers.
9 The tv_grab_xx should be run before this importer. The output file
10 of the grabber should be the file: $self->{FileStore} . "/tv_grab/" . $tvgrabber . ".xml";
12 Use grabber_data to specify grabber and the channel.
14 Example: to grab RAI1 using Italian grabber tv_grab_it, the grabber_data
15 will look like 'tv_grab_it;www.raiuno.rai.it'
23 use Encode qw
/encode decode/;
25 use NonameTV qw
/norm AddCategory ParseXmltv/;
26 use NonameTV
::Log qw
/d progress error/;
27 use NonameTV
::Config qw
/ReadConfig/;
28 use NonameTV
::DataStore
::Helper
;
30 use NonameTV
::Importer
::BaseOne
;
32 use base
'NonameTV::Importer::BaseOne';
36 my $class = ref($proto) || $proto;
37 my $self = $class->SUPER::new
( @_ );
38 bless ($self, $class);
40 #defined( $self->{UrlRoot} ) or die "You must specify UrlRoot";
42 my $dsh = NonameTV
::DataStore
::Helper
->new( $self->{datastore
} );
43 $self->{datastorehelper
} = $dsh;
45 my $conf = ReadConfig
();
46 $self->{FileStore
} = $conf->{FileStore
};
54 my( $batch_id, $data ) = @_;
56 my( $tvgrabber, $tvchannel ) = ( $data->{grabber_info
} =~ /^(.*);(.*)$/ );
57 $self->{tvgrabber
} = $tvgrabber;
58 $self->{tvchannel
} = $tvchannel;
60 my $xmlf = $self->{FileStore
} . "/tv_grab/" . $tvgrabber . ".xml";
64 my $content = <XMLFILE
>;
67 return( $content, "" );
73 my( $batch_id, $cref, $chd ) = @_;
75 my $dsh = $self->{datastorehelper
};
82 my $ds = $self->{datastore
};
83 $ds->{SILENCE_END_START_OVERLAP
}=1;
85 my $prog = ParseXmltv
(\
$$cref, $self->{tvchannel
});
86 my @shows = SortShows
( @
{$prog} );
87 foreach my $e (@shows) {
89 $e->{channel_id
} = $chd->{id
};
91 # translate start end from DateTime to string
92 $e->{start_dt
}->set_time_zone ('UTC');
93 $e->{start_time
} = $e->{start_dt
}->ymd('-') . " " . $e->{start_dt
}->hms(':');
94 delete $e->{start_dt
};
96 # some XMLTV exports don't provide programme "stop" time
97 # helper is needed for such implementations
98 if( $e->{stop_dt
} and ! $needhelper ){
99 # translate stop end from DateTime to string
100 $e->{stop_dt
}->set_time_zone ('UTC');
101 $e->{end_time
} = $e->{stop_dt
}->ymd('-') . " " . $e->{stop_dt
}->hms(':');
102 delete $e->{stop_dt
};
107 # translate channel specific program_type and category to common ones
108 my $pt = $e->{program_type
};
109 delete $e->{program_type
};
110 my $c = $e->{category
};
111 delete $e->{category
};
114 my($program_type, $category ) = $ds->LookupCat( $chd->{xmltvid
}, $pt );
115 AddCategory
( $e, $program_type, $category );
118 my($program_type, $category ) = $ds->LookupCat( $chd->{xmltvid
}, $c );
119 AddCategory
( $e, $program_type, $category );
123 ( $date, $time ) = ( $e->{start_time
} =~ /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}):\d{2}$/ );
124 if( $date ne $currdate ){
125 $dsh->StartDate( $date , "00:00" );
127 progress
("TVGrabXX: $chd->{xmltvid}: Date is $date");
129 $e->{start_time
} = $time;
132 d
( "TVGrabXX: $chd->{xmltvid}: $e->{start_time} - $e->{title}" );
135 $dsh->AddProgramme($e);
137 $ds->AddProgramme($e);
147 my( $Y1, $M1, $D1, $h1, $m1, $s1 ) = ( $$a{start_dt
} =~ /^(\d+)\-(\d+)\-(\d+)T(\d+)\:(\d+)\:(\d+)$/ );
148 my $t1 = int( sprintf( "%04d%02d%02d%02d%02d%02d", $Y1, $M1, $D1, $h1, $m1, $s1 ) );
150 my( $Y2, $M2, $D2, $h2, $m2, $s2 ) = ( $$b{start_dt
} =~ /^(\d+)\-(\d+)\-(\d+)T(\d+)\:(\d+)\:(\d+)$/ );
151 my $t2 = int( sprintf( "%04d%02d%02d%02d%02d%02d", $Y2, $M2, $D2, $h2, $m2, $s2 ) );
159 my @sorted = sort bytime
@shows;