diff --git a/grab/pt_vodafone/tv_grab_pt_vodafone b/grab/pt_vodafone/tv_grab_pt_vodafone index 253553dd..67432f9a 100755 --- a/grab/pt_vodafone/tv_grab_pt_vodafone +++ b/grab/pt_vodafone/tv_grab_pt_vodafone @@ -284,7 +284,7 @@ sub get_epg my $channelId = make_channelid( $channelInfo->{$channel}->{name} ); my %ch = ( 'id' => $channelId, - 'icon' => [ { src => $channelInfo->{$channel}->{icon} } ], + 'icon' => [ { src => unquote($channelInfo->{$channel}->{icon}) } ], ); # multiple display-names are ok and may be useful to match other tools lists my @displayname = ( [ sanitizeUTF8( $channelInfo->{$channel}->{name} ), 'pt' ] , @@ -323,80 +323,36 @@ sub get_epg $prog{start} = $dtstart; $prog{stop} = $dtend; - $prog{channel} = $channelId; - $prog{title} = [ [ sanitizeUTF8($programme->{name}), 'pt' ] ]; - $prog{desc} = [ [ sanitizeUTF8($programme->{description}), 'pt' ] ] if ($programme->{description}); - - if ($programme->{metas}{'display duration'}{value}) { - my $duration_str = $programme->{metas}{'display duration'}{value}; - my @duration_items = split(/[PTHMS]/,$duration_str); - $prog{length} = $duration_items[2]*3600+$duration_items[3]*60+$duration_items[4] if scalar @duration_items; - } - - # fetch programme images in 16:9 - $prog{icon} = [ { src => $programme->{images}[0]{url}."/width/360/height/640/quality/95" } ] if ($programme->{images}[0]{url} && $programme->{images}[0]{imageTypeName} eq "ca" ); - $prog{icon} = [ { src => $programme->{images}[0]{url}."/width/640/height/360/quality/95" } ] if ($programme->{images}[0]{url} && $programme->{images}[0]{imageTypeName} eq "cc"); - - if ( $programme->{tags}{genre} ) { - my @category = map { [ sanitizeUTF8($_->{value}) , 'pt' ] } @{$programme->{tags}{genre}{objects}}; - $prog{category} = \@category; - } - $prog{country} = [ [ sanitizeUTF8($programme->{tags}{'country of production'}{objects}[0]{value}), 'pt' ] ] if $programme->{tags}{'country of production'}; - - if ($programme->{tags}{'parental Rating'}) { - my $rating; - if ($programme->{tags}{'parental Rating'}{objects}[0]{value} == 0) { - $rating = [ [ "All Ages", 'Portuguese Movie Rating' ] ]; - } else { - $rating = [ [ "M/".$programme->{tags}{'parental Rating'}{objects}[0]{value}, 'Portuguese Movie Rating' ] ]; - } - $prog{rating} = $rating if $rating; - } - - my @images; - for my $image (@{$programme->{images}}) { - next if !$image->{url}; - - my $type = ""; - my $orient = ""; - my $size = 3; - my $system = "vodafone"; - my $width = 640; - my $height = 360; - - if ($image->{imageTypeName} eq "cc") { - $orient = "L"; - $type = "still"; - } elsif ($image->{imageTypeName} eq "ca") { - $orient = "P"; - $type = "poster"; - $width = 360; - $height = 640; - } elsif ($image->{imageTypeName} eq "bg") { - $orient = "L"; - $type = "backdrop"; - } - - my $url = $image->{url}; - push @images, [ $image->{url}."/width/".$width."/height/".$height."/quality/95", { type => $type, size => $size, orient => $orient, system => $system } ]; - } - $prog{image} = \@images if scalar @images; - - $prog{date} = sanitizeUTF8($programme->{metas}{year}{value}) if $programme->{metas}{year}{value}; - - if ( $programme->{tags}{actors} ) { - my @actors = map { sanitizeUTF8($_->{value}) } @{$programme->{tags}{actors}{objects}}; - $prog{credits}{actor} = \@actors; - } - - if ( $programme->{tags}{director} ) { - my @directors = map { sanitizeUTF8($_->{value}) } @{$programme->{tags}{director}{objects}} ; - $prog{credits}{director} = \@directors; - } - + $prog{title} = get_title($programme); + $prog{desc} = get_desc($programme); + $prog{date} = get_date($programme); $prog{'episode-num'} = make_episode_num($programme); + my $length = get_length($programme); + $prog{length} = $length if $length; + + my $icon = get_icon($programme); + $prog{icon} = $icon if $icon; + + my $category = get_category($programme); + $prog{category} = $category if $category; + + my $country = get_country($programme); + $prog{country} = $country if $country; + + my $rating = get_rating($programme); + $prog{rating} = $rating if $rating; + + my $image = get_images($programme); + $prog{image} = $image if $image; + + my $actors = get_actors($programme); + $prog{credits}{actor} = $actors if $actors; + + my $directors = get_directors($programme); + $prog{credits}{director} = $directors if $directors; + # We can get the same programme for two different days if it goes past midnight. # Lets remove duplicates here. $xmlprogs{$channelId}{ $dtstart, $dtend } = \%prog; @@ -524,4 +480,118 @@ sub make_channelid $id = unidecode($id); $id .= '.tv.vodafone.pt'; # append domain part return( $id ); +} + +sub unquote { + my ($str) = @_; + $str =~ s/^"//; + $str =~ s/"$//; + return $str; +} + +sub get_title { + my ($programme) = @_; + return [ [ sanitizeUTF8($programme->{name}), 'pt' ] ]; +} + +sub get_desc { + my ($programme) = @_; + return [ [ sanitizeUTF8($programme->{description}), 'pt' ] ] if ($programme->{description}); +} + +sub get_length { + my ($programme) = @_; + if ($programme->{metas}{'display duration'}{value}) { + my $duration_str = $programme->{metas}{'display duration'}{value}; + my @duration_items = split(/[PTHMS]/, $duration_str); + return $duration_items[2] * 3600 + $duration_items[3] * 60 + $duration_items[4] if scalar @duration_items; + } +} + +sub get_icon { + my ($programme) = @_; + if ($programme->{images}[0]{url} && $programme->{images}[0]{imageTypeName} eq "ca") { + return [ { src => $programme->{images}[0]{url} . "/width/360/height/640/quality/95" } ]; + } + if ($programme->{images}[0]{url} && $programme->{images}[0]{imageTypeName} eq "cc") { + return [ { src => $programme->{images}[0]{url} . "/width/640/height/360/quality/95" } ]; + } +} + +sub get_category { + my ($programme) = @_; + if ($programme->{tags}{genre}) { + my @category = map { [ sanitizeUTF8($_->{value}), 'pt' ] } @{$programme->{tags}{genre}{objects}}; + return \@category; + } +} + +sub get_country { + my ($programme) = @_; + return [ [ sanitizeUTF8($programme->{tags}{'country of production'}{objects}[0]{value}), 'pt' ] ] if $programme->{tags}{'country of production'}; +} + +sub get_rating { + my ($programme) = @_; + if ($programme->{tags}{'parental Rating'}) { + my $rating; + if ($programme->{tags}{'parental Rating'}{objects}[0]{value} == 0) { + $rating = [ [ "All Ages", 'Portuguese Movie Rating' ] ]; + } else { + $rating = [ [ "M/" . $programme->{tags}{'parental Rating'}{objects}[0]{value}, 'Portuguese Movie Rating' ] ]; + } + return $rating if $rating; + } +} + +sub get_images { + my ($programme) = @_; + my @images; + for my $image (@{$programme->{images}}) { + next if !$image->{url}; + + my $type = ""; + my $orient = ""; + my $size = 3; + my $system = "vodafone"; + my $width = 640; + my $height = 360; + + if ($image->{imageTypeName} eq "cc") { + $orient = "L"; + $type = "still"; + } elsif ($image->{imageTypeName} eq "ca") { + $orient = "P"; + $type = "poster"; + $width = 360; + $height = 640; + } elsif ($image->{imageTypeName} eq "bg") { + $orient = "L"; + $type = "backdrop"; + } + + push @images, [ $image->{url} . "/width/" . $width . "/height/" . $height . "/quality/95", { type => $type, size => $size, orient => $orient, system => $system } ]; + } + return \@images if scalar @images; +} + +sub get_date { + my ($programme) = @_; + return sanitizeUTF8($programme->{metas}{year}{value}) if $programme->{metas}{year}{value}; +} + +sub get_actors { + my ($programme) = @_; + if ($programme->{tags}{actors}) { + my @actors = map { sanitizeUTF8($_->{value}) } @{$programme->{tags}{actors}{objects}}; + return \@actors; + } +} + +sub get_directors { + my ($programme) = @_; + if ($programme->{tags}{director}) { + my @directors = map { sanitizeUTF8($_->{value}) } @{$programme->{tags}{director}{objects}}; + return \@directors; + } } \ No newline at end of file