Skip to content

Commit

Permalink
Fix YouTube embedded videos, some playlists and RTMP
Browse files Browse the repository at this point in the history
Fixes issue 93.
  • Loading branch information
monsieurvideo committed Apr 6, 2010
1 parent ce521d1 commit 9a31328
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions FlashVideo/Site/Youtube.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sub find_video {
# don't require the 't' parameter.
if ($browser->content =~ /["']fmt_url_map["']:\s{0,3}["']([^"']+)["']/) {
debug "Using fmt_url_map method from page";
return $self->download_fmt_map($prefs, $browser, $title, {}, $1);
return $self->download_fmt_map($prefs, $browser, $title, {}, uri_unescape($1));
}

my $video_id;
Expand Down Expand Up @@ -78,14 +78,14 @@ sub find_video {
# Get season and episode
my ($season, $episode);

if ($browser->content =~ m{<span(?: class=["']\w+["'])?>Season ?(\d+)</span>}) {
if ($browser->content =~ m{<span[^>]*>Season ?(\d+)}i) {
$season = $1;
}

if ($browser->content =~ m{<span(?: class=["']\w+["'])?>Episode ?(\d+)</span>}) {
if ($browser->content =~ m{<span[^>]*>[^<]+Ep\.?\w* ?(\d+)\W*\s*</span>}i) {
$episode = $1;
}

if ($season and $episode) {
$title .= sprintf " S%02dE%02d", $season, $episode;
}
Expand All @@ -94,8 +94,9 @@ sub find_video {
my $swf_url;
if ($browser->content =~ /SWF_URL['"] ?: ?.{0,90}?(http:\/\/[^ ]+\.swf)/) {
$swf_url = $1;
}
else {
} elsif($browser->content =~ /src=\\['"](.*?\.swf)/) {
$swf_url = json_unescape($1);
} else {
die "Couldn't extract SWF URL";
}

Expand Down Expand Up @@ -191,8 +192,9 @@ sub check_die {
my($browser, $message) = @_;

if($browser->content =~ m{class="yt-alert-content">([^<]+)}) {
$message .= "\n$1";
$message =~ s/\s+/ /g;
my $alert = $1;
$alert =~ s/(^\s+|\s+$)//g;
$message .= "\nYouTube: $alert";
error $message;
exit 1;
} else {
Expand Down Expand Up @@ -308,19 +310,23 @@ sub get_youtube_video_info {

$url ||= "http://www.youtube.com/watch?v=$video_id";

my $video_info_url_template =
"http://www.youtube.com/get_video_info?&video_id=%s&el=profilepage&ps=default&eurl=%s&hl=en_US&t=%s";
for my $el(qw(profilepage detailpage)) {
my $video_info_url_template =
"http://www.youtube.com/get_video_info?&video_id=%s&el=$el&ps=default&eurl=%s&hl=en_US&t=%s";

my $video_info_url = sprintf $video_info_url_template,
uri_escape($video_id), uri_escape($url), uri_escape($t);
my $video_info_url = sprintf $video_info_url_template,
uri_escape($video_id), uri_escape($url), uri_escape($t);

debug "get_youtube_video_info: $video_info_url";
debug "get_youtube_video_info: $video_info_url";

$browser->get($video_info_url);
$browser->get($video_info_url);

return unless $browser->success;
next unless $browser->success;

return parse_youtube_video_info($browser->content);
}

return parse_youtube_video_info($browser->content);
error "Unable to get YouTube video information.";
}

# Decode form-encoded key-value pairs into a hash for convenience.
Expand Down

0 comments on commit 9a31328

Please sign in to comment.