Skip to content

Commit

Permalink
Fix Onion support (issue 89).
Browse files Browse the repository at this point in the history
  • Loading branch information
zakflash committed Apr 6, 2010
1 parent 9a31328 commit c358d72
Showing 1 changed file with 18 additions and 40 deletions.
58 changes: 18 additions & 40 deletions FlashVideo/Site/Theonion.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,29 @@ use FlashVideo::Utils;
sub find_video {
my ($self, $browser) = @_;

# Get the video ID
my $video_id;
if ($browser->response->is_redirect) {
$browser->get( $browser->response->header('Location') );

if ($browser->content =~ /<meta name="nid" content="(\d+)"/) {
$video_id = $1;
if (!$browser->success) {
die "Couldn't follow Onion redirect: " .
$browser->response->status_line;
}
}
elsif ($browser->content =~ /var videoid = ["'](\d+)["'];/) {
$video_id = $1;

my $title;
if ($browser->content =~ /var video_title = "([^"]+)"/) {
$title = $1;
}

die "Couldn't find Onion video ID" unless $video_id;

# Get XML with FLV details
# TODO - support "bookend" (online exclusive videos).
$browser->get("http://www.theonion.com/content/xml/$video_id/video");

die "Couldn't download Onion XML: " . $browser->response->status_line
if !$browser->success;

# Generic can handle this XML so just pass it over to that.
my ($url, @filenames) = FlashVideo::Generic->find_video($browser);

# We can probably make a better guess for the filename than generic can
# though.
my $has_xml_simple = eval { require XML::Simple };

# Don't die if XML::Simple isn't installed, as strictly speaking it's not
# needed for this video -- it just lets us have a better title.
if ($has_xml_simple) {
my $video_rss = eval {
XML::Simple::XMLin($browser->content);
};

die "Couldn't parse The Onion XML: $@" if $@;

if (my $title_from_rss = $video_rss->{channel}->{item}->[0]->{title}) {
$title_from_rss = title_to_filename($title_from_rss);

# Likely to be a better filename so put it first for people who are
# using --yes
unshift @filenames, $title_from_rss;
}
else {
$title = extract_info($browser)->{meta_title};
}

return $url, @filenames;
my $filename = title_to_filename($title);

# They now pass the URL as a param, so the generic code can extract it.
my $url = (FlashVideo::Generic->find_video($browser, $browser->uri))[0];

return $url, $filename;
}

1;

0 comments on commit c358d72

Please sign in to comment.