aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzakflash <zakflashvideo@gmail.com>2012-12-14 12:46:35 -0800
committerzakflash <zakflashvideo@gmail.com>2012-12-14 12:46:35 -0800
commit5c5c867af1dfc81804b577093cb7b4ffe8a3806f (patch)
tree4324bafddf049a8a26a6ff68c0cd6a28938a0ff5
parent5a0142a39b149bd26188c3eeb02b4f5f39046069 (diff)
parent29d159e0e4c3fbea02a5bbf234c10a91ff839734 (diff)
downloadget-flash-videos-5c5c867af1dfc81804b577093cb7b4ffe8a3806f.tar.gz
Merge pull request #82 from karjonas/master
Tv4play wrong matching for video_id
-rw-r--r--lib/FlashVideo/Site/Tv4play.pm85
1 files changed, 45 insertions, 40 deletions
diff --git a/lib/FlashVideo/Site/Tv4play.pm b/lib/FlashVideo/Site/Tv4play.pm
index d175a62..f45458a 100644
--- a/lib/FlashVideo/Site/Tv4play.pm
+++ b/lib/FlashVideo/Site/Tv4play.pm
@@ -2,59 +2,64 @@
package FlashVideo::Site::Tv4play;
use strict;
use FlashVideo::Utils;
+use List::Util qw(reduce);
sub find_video {
my ($self, $browser, $embed_url, $prefs) = @_;
- my $vid = ($embed_url =~ /videoid=([0-9]*)/)[0];
- my $smi_url = "http://premium.tv4play.se/api/web/asset/$vid/play";
-
+ my $video_id = ($embed_url =~ /video_id=([0-9]*)/)[0];
+ my $smi_url = "http://premium.tv4play.se/api/web/asset/$video_id/play";
my $title = ($browser->content =~ /property="og:title" content="(.*?)"/)[0];
my $flv_filename = title_to_filename($title, "flv");
$browser->get($smi_url);
my $content = from_xml($browser);
my $i = 0;
- my @dump;
+ my @streams;
my $subtitle_url;
- for ($i = 0; $i < 5; $i++){
- my $format = $content->{items}->{item}[$i]->{mediaFormat};
- my $bitrate = $content->{items}->{item}[$i]->{bitrate};
- my $rtmp = $content->{items}->{item}[$i]->{base};
- my $mp4 = $content->{items}->{item}[$i]->{url};
- @dump[$i] = { 'rtmp' => $rtmp,
- 'bitrate' => $bitrate,
- 'mp4' => $mp4,
- 'format' => $format
- };
- }
- foreach (@dump) {
- if($_->{format} eq 'smi'){ $subtitle_url = $_->{mp4};}
+
+ foreach my $item (@{ $content->{items}->{item} || [] }) {
+ push @streams, {
+ rtmp => $item->{base},
+ bitrate => $item->{bitrate},
+ mp4 => $item->{url},
+ format => $item->{mediaFormat}
+ };
+ }
+
+ foreach (@streams) {
+ if ($_->{format} eq 'smi') {
+ $subtitle_url = $_->{mp4};
+ last;
+ }
}
- debug "Subtitle_url: $subtitle_url";
- # Subtitle not supported
- # if ($prefs->{subtitles} == 1) {
- # if (not $subtitle_url eq '') {
- # info "Found subtitles: $subtitle_url";
- # $browser->get("$subtitle_url");
- # my $srt_filename = title_to_filename($title, "srt");
- # if(!eval { require XML::Simple && XML::Simple::XMLin("<foo/>") }) {
- # die "Must have XML::Simple to download " . caller =~ /::([^:])+$/ . " videos\n";
- # }
- # convert_sami_subtitles_to_srt($browser->content, $srt_filename);
- # } else {
- # info "No subtitles found!";
- # }
- # }
-
-
-
+
+ if ($prefs->{subtitles} == 1) {
+ if (not $subtitle_url eq '') {
+ $browser->get("$subtitle_url");
+ if (!$browser->success) {
+ info "Couldn't download subtitles: " . $browser->status_line;
+ } else {
+ my $srt_filename = title_to_filename($title, "srt");
+ info "Saving subtitles as " . $srt_filename;
+ open my $srt_fh, '>', $srt_filename
+ or die "Can't open subtitles file $srt_filename: $!";
+ binmode $srt_fh, ':utf8';
+ print $srt_fh $browser->content;
+ close $srt_fh;
+ }
+ } else {
+ info "No subtitles found";
+ }
+ }
+
+ my $max_stream = reduce {$a->{bitrate} > $b->{bitrate} ? $a : $b} @streams;
+
return {
- rtmp => $dump[0]->{rtmp},
- swfVfy => "http://www.tv4play.se/flash/tv4playflashlets.swf",
- playpath => $dump[0]->{mp4},
- flv => $flv_filename
+ rtmp => $max_stream->{rtmp},
+ swfVfy => "http://www.tv4play.se/flash/tv4playflashlets.swf",
+ playpath => $max_stream->{mp4},
+ flv => $flv_filename
};
-
}
1;