Skip to content

Commit 5e61fdf

Browse files
committed
'gfv' update
1 parent d9d05d7 commit 5e61fdf

File tree

4 files changed

+63
-68
lines changed

4 files changed

+63
-68
lines changed

x renamed to arf2

File renamed without changes.

lib/FlashVideo/Site/Svtplay.pm

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ use FlashVideo::Utils;
88
use FlashVideo::JSON;
99
use HTML::Entities;
1010

11-
our $VERSION = '0.02';
11+
our $VERSION = '0.03';
1212
sub Version() { $VERSION;}
1313

14+
my $bitrate_index = {
15+
high => 0,
16+
medium => 1,
17+
low => 2
18+
};
19+
1420
sub find_video_svt {
1521
my ($self, $browser, $embed_url, $prefs, $oppet_arkiv) = @_;
1622
my @rtmpdump_commands;
@@ -72,47 +78,33 @@ sub find_video_svt {
7278

7379
# If we found an m3u8 file we generate the ffmpeg download command
7480
if (!($m3u8 eq "")) {
75-
$browser->get($m3u8);
76-
if (!$browser->success) {
77-
die "Couldn't download $m3u8: " . $browser->response->status_line;
78-
}
7981

80-
my @lines = split(/\r?\n/, $browser->content);
81-
$bitrate = -1;
82-
my $video_url = "";
83-
my $i = 0;
84-
85-
# Select highest bitrate available
86-
foreach my $line (@lines) {
87-
if ($line =~ /BANDWIDTH/) {
88-
$line =~ /BANDWIDTH=([0-9]*),/;
89-
my $this_rate = $1;
90-
91-
if ($bitrate < $this_rate) {
92-
$video_url = $lines[$i + 1];
93-
$bitrate = $this_rate;
94-
}
95-
}
96-
$i++;
97-
}
82+
my %urls = read_hls_playlist($browser, $m3u8);
83+
84+
# Sort the urls and select the suitable one based upon quality preference
85+
my $quality = $bitrate_index->{$prefs->{quality}};
86+
my $min = $quality < scalar(keys(%urls)) ? $quality : scalar(keys(%urls));
87+
my $key = (sort {int($b) <=> int($a)} keys %urls)[$min];
88+
89+
my $video_url = $urls{$key};
90+
my $filename = title_to_filename($name, "mp4");
91+
92+
# Set the arguments for ffmpeg
93+
my @ffmpeg_args = (
94+
"-i", "$video_url",
95+
"-acodec", "copy",
96+
"-vcodec", "copy",
97+
"-absf", "aac_adtstoasc",
98+
"-f", "mp4",
99+
"$filename"
100+
);
101+
102+
return {
103+
downloader => "ffmpeg",
104+
flv => $filename,
105+
args => \@ffmpeg_args
106+
};
98107

99-
my $filename = title_to_filename($name, "mp4");
100-
101-
# Set the arguments for ffmpeg
102-
my @ffmpeg_args = (
103-
"-i", "$video_url",
104-
"-acodec", "copy",
105-
"-vcodec", "copy",
106-
"-absf", "aac_adtstoasc",
107-
"-f", "mp4",
108-
"$filename"
109-
);
110-
111-
return {
112-
downloader => "ffmpeg",
113-
flv => $filename,
114-
args => \@ffmpeg_args
115-
};
116108
} else {
117109
return {
118110
flv => title_to_filename($name, "flv"),

lib/FlashVideo/Site/Tv4play.pm

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use warnings;
55
use FlashVideo::Utils;
66
use List::Util qw(reduce);
77

8-
our $VERSION = '0.01';
8+
our $VERSION = '0.02';
99
sub Version() { $VERSION;}
1010

1111
my $bitrate_index = {
@@ -14,33 +14,15 @@ my $bitrate_index = {
1414
low => 2
1515
};
1616

17-
sub read_m3u {
18-
my $content = shift;
19-
my @lines = split(/\r?\n/, $content);
20-
my %urltable = ();
21-
my $i = 0;
22-
23-
# Fill the url table
24-
foreach my $line (@lines) {
25-
if ($line =~ /BANDWIDTH/) {
26-
$line =~ /BANDWIDTH=([0-9]*),/;
27-
$urltable{int($1)} = $lines[$i + 1];
28-
}
29-
$i++;
30-
}
31-
32-
return %urltable;
33-
}
34-
3517
sub find_video {
3618
my ($self, $browser, $embed_url, $prefs) = @_;
3719
my $video_id = ($embed_url =~ /video_id=([0-9]*)/)[0];
3820
my $smi_url = "http://premium.tv4play.se/api/web/asset/$video_id/play?protocol=hls";
39-
my $title = ($browser->content =~ /property="og:title" content="(.*?)"/)[0];
21+
my $title = extract_title($browser);
4022
$browser->get($smi_url);
4123
my $content = from_xml($browser);
4224
my $subtitle_url;
43-
my $hls_m3u;
25+
my $hls_m3u = "";
4426
my $hls_base;
4527

4628
foreach my $item (@{ $content->{items}->{item} || [] }) {
@@ -59,11 +41,7 @@ sub find_video {
5941
}
6042
}
6143

62-
if ($hls_m3u eq "") {die "No stream found!"};
63-
$browser->get($hls_m3u);
64-
if (!$browser->success) {
65-
die "Couldn't download $hls_m3u: " . $browser->response->status_line;
66-
}
44+
if ($hls_m3u eq "") {die "No HLS stream found!"};
6745

6846
# Download subtitles
6947
if ($prefs->{subtitles} == 1) {
@@ -85,7 +63,7 @@ sub find_video {
8563
}
8664
}
8765

88-
my %urls = read_m3u($browser->content);
66+
my %urls = read_hls_playlist($browser, $hls_m3u);
8967

9068
# Sort the urls and select the suitable one based upon quality preference
9169
my $quality = $bitrate_index->{$prefs->{quality}};
@@ -100,6 +78,7 @@ sub find_video {
10078
"-i", "$hls_base$video_url",
10179
"-acodec", "copy",
10280
"-vcodec", "copy",
81+
"-absf", "aac_adtstoasc",
10382
"-f", "mp4",
10483
"$filename"
10584
);

lib/FlashVideo/Utils.pm

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ our @EXPORT = qw(debug info error
1717
swfhash swfhash_data EXTENSIONS get_user_config_dir get_win_codepage
1818
is_program_on_path get_terminal_width json_unescape
1919
convert_sami_subtitles_to_srt from_xml
20-
convert_ttml_subtitles_to_srt);
20+
convert_ttml_subtitles_to_srt read_hls_playlist);
2121

2222
sub debug(@) {
2323
# Remove some sensitive data
@@ -525,4 +525,28 @@ sub from_xml {
525525
return $xml;
526526
}
527527

528+
sub read_hls_playlist {
529+
my($browser, $url) = @_;
530+
531+
$browser->get($url);
532+
if (!$browser->success) {
533+
die "Couldn't download m3u file, $url: " . $browser->response->status_line;
534+
}
535+
536+
my @lines = split(/\r?\n/, $browser->content);
537+
my %urltable = ();
538+
my $i = 0;
539+
540+
# Fill the url table
541+
foreach my $line (@lines) {
542+
if ($line =~ /BANDWIDTH/) {
543+
$line =~ /BANDWIDTH=([0-9]*),/;
544+
$urltable{int($1)} = $lines[$i + 1];
545+
}
546+
$i++;
547+
}
548+
549+
return %urltable;
550+
}
551+
528552
1;

0 commit comments

Comments
 (0)