1 package NonameTV
::Importer
::Port
;
8 Import data from Xml-files downloaded from PORT.hu
19 use NonameTV qw
/MyGet norm AddCategory/;
20 use NonameTV
::Log qw
/info progress error logdie/;
22 use NonameTV
::Importer
::BaseOne
;
24 use base
'NonameTV::Importer::BaseOne';
28 my $class = ref($proto) || $proto;
29 my $self = $class->SUPER::new
( @_ );
30 bless ($self, $class);
32 $self->{grabber_name
} = "Port";
34 defined( $self->{UrlRoot
} ) or die "You must specify UrlRoot";
43 my( $batch_id, $data ) = @_;
45 my $u = $self->{UrlRoot
} . "/" . $data->{grabber_info
};
46 progress
("Port: Fetching data from $u");
48 my ( $content, $code ) = MyGet
( $u );
50 return( $content, $code );
55 my( $batch_id, $cref, $chd ) = @_;
57 my $channel_id = $chd->{id
};
58 my $channel_xmltvid = $chd->{xmltvid
};
59 my $ds = $self->{datastore
};
60 $ds->{SILENCE_END_START_OVERLAP
}=1;
62 progress
( "Port: $channel_xmltvid: Processing XML" );
65 my $xml = XML
::LibXML
->new;
67 eval { $doc = $xml->parse_string($$cref); };
69 error
( "Port: $batch_id: Failed to parse $@" );
73 # find for how many channels this file has data
74 my $channels = $doc->findnodes( "//Channel" );
75 if( $channels->size() == 0 ) {
76 error
( "Port: $channel_xmltvid: $$cref: No channels found" ) ;
79 progress
( "Port: $channel_xmltvid: found " . $channels->size() . " channels" );
81 # browse through channels
82 foreach my $chan ($channels->get_nodelist) {
84 my $chan_id = $chan->getAttribute('Id');
86 progress
( "Port: $channel_xmltvid: browsing channel id $chan_id for EventDates" );
88 # find all eventdates for this channel
89 my $eventdates = $chan->findnodes( ".//EventDate" );
90 if( $eventdates->size() == 0 ) {
91 error
( "Port: $channel_xmltvid: No EventDates found" ) ;
94 progress
( "Port: $channel_xmltvid: found " . $eventdates->size() . " EventDates" );
96 # browse through channels
97 foreach my $eventdate ($eventdates->get_nodelist) {
99 my $eventdate_date = $eventdate->getAttribute('Date');
101 progress
( "Port: $channel_xmltvid: browsing $eventdate_date for events" );
103 # find all events for this EventDate
104 my $events = $eventdate->findnodes( ".//Event" );
105 if( $events->size() == 0 ) {
106 error
( "Port: $channel_xmltvid: No Events found for $eventdate_date" ) ;
109 progress
( "Port: $channel_xmltvid: found " . $events->size() . " events in $eventdate_date" );
111 # browse through events
112 foreach my $event ($events->get_nodelist) {
114 my $event_id = $event->getAttribute('Id');
116 my $startdate= $event->findvalue( 'StartDate' );
117 my $stopdate= $event->findvalue( 'StopDate' );
118 my $title= $event->findvalue( 'Title' );
119 my $shortdesc= $event->findvalue( 'Shortdescription' );
120 my $longdesc= $event->findvalue( 'Longdescription' );
121 my $dvbccateg= $event->findvalue( 'DVBCategoryName' );
122 my $categlevel= $event->findvalue( 'CategoryNibbleLevel1' );
123 my $rating= $event->findvalue( 'Rating' );
125 my $starttime = create_dt
( $startdate );
126 next if not $starttime;
128 my $endtime = create_dt
( $stopdate );
129 next if not $endtime;
133 progress
( "Port: $channel_xmltvid: $starttime - $title" );
136 channel_id
=> $channel_id,
138 start_time
=> $starttime->ymd("-") . " " . $starttime->hms(":"),
139 end_time
=> $endtime->ymd("-") . " " . $endtime->hms(":"),
142 $ce->{description
} = norm
($shortdesc) if $shortdesc;
143 $ce->{description
} = norm
($longdesc) if $longdesc;
145 # some characters cleanup
146 $ce->{description
} =~ s/\x8a/\n/g;
149 my($program_type, $category ) = $ds->LookupCat( 'Port', $dvbccateg );
150 AddCategory
( $ce, $program_type, $category );
153 $ce->{rating
} = $rating if $rating;
155 $ds->AddProgramme( $ce );
167 if( $dtinfo !~ /^\d{4}-\d{2}-\d{2}T\d\d:\d\d:\d\d$/ ){
171 my( $year, $month, $day, $hour, $minute, $second ) = ( $dtinfo =~ /^(\d{4})-(\d{2})-(\d{2})T(\d\d):(\d\d):(\d\d)$/ );
173 my $dt = DateTime
->new( year
=> $year,
180 time_zone
=> 'Europe/Budapest',
183 #$dt->set_time_zone( "UTC" );
190 ### Setup coding system