aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas <jonaskarlsson@fripost.org>2012-11-08 22:53:14 +0100
committerJonas <jonaskarlsson@fripost.org>2012-11-08 22:53:14 +0100
commit4f72a9d3a62624f0c2bc9f8753fd3c5c8327347d (patch)
tree386ab32d33a35a84eaafba0cce95f84649aa8532
parentdc5f34306a3ac7dbd0037d7f16ce737b0686d009 (diff)
downloadget-flash-videos-4f72a9d3a62624f0c2bc9f8753fd3c5c8327347d.tar.gz
Tv4play wrong matching for video_id
-rw-r--r--lib/FlashVideo/Site/Tv4play.pm61
1 files changed, 32 insertions, 29 deletions
diff --git a/lib/FlashVideo/Site/Tv4play.pm b/lib/FlashVideo/Site/Tv4play.pm
index d175a62..1cfad1d 100644
--- a/lib/FlashVideo/Site/Tv4play.pm
+++ b/lib/FlashVideo/Site/Tv4play.pm
@@ -3,58 +3,61 @@ package FlashVideo::Site::Tv4play;
use strict;
use FlashVideo::Utils;
+
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 $vid = ($embed_url =~ /video_id=([0-9]*)/)[0];
+ my $smi_url = "http://premium.tv4play.se/api/web/asset/$vid/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++){
+
+ for ($i = 0; $i < length($content->{items}); $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,
+ @streams[$i] = { 'rtmp' => $rtmp,
'bitrate' => $bitrate,
'mp4' => $mp4,
'format' => $format
};
- }
- foreach (@dump) {
+ }
+
+ foreach (@streams) {
if($_->{format} eq 'smi'){ $subtitle_url = $_->{mp4};}
}
- 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";
+ }
+ }
+
return {
- rtmp => $dump[0]->{rtmp},
+ rtmp => $streams[0]->{rtmp},
swfVfy => "http://www.tv4play.se/flash/tv4playflashlets.swf",
- playpath => $dump[0]->{mp4},
+ playpath => $streams[0]->{mp4},
flv => $flv_filename
};
-
}
1;