Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flickr support.
  • Loading branch information
monsieurvideo committed May 17, 2009
1 parent 234147d commit 8fb12ac
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions FlashVideo/Site/Flickr.pm
@@ -0,0 +1,58 @@
# Part of get-flash-videos. See get_flash_videos for copyright.
package FlashVideo::Site::Flickr;

use strict;
use FlashVideo::Utils;
use URI::Escape;

my $get_mtl = "http://www.flickr.com/apps/video/video_mtl_xml.gne?v=x";

sub find_video {
my ($self, $browser, $embed_url) = @_;

my $has_xml_simple = eval { require XML::Simple };
if(!$has_xml_simple) {
die "Must have XML::Simple installed to download Flickr videos";
}

my($id) = $browser->content =~ /photo_id=(\d+)/;
my($secret) = $browser->content =~ /photo_secret=(\w+)/;

die "No video ID found\n" unless $id;

$browser->get($get_mtl . "&photo_id=$id&secret=$secret&olang=en-us&noBuffer=null&bitrate=700&target=_self");

my $xml = eval { XML::Simple::XMLin($browser->content) };
die "Failed parsing XML: $@" if $@;

my $guid = $self->make_guid;
my $video_id = $xml->{Data}->{Item}->{id}->{content};
my $playlist_url = $xml->{Playlist}->{TimelineTemplates}->{Timeline}
->{Metadata}->{Item}->{playlistUrl}->{content};

die "No video ID or playlist found" unless $video_id and $playlist_url;

$browser->get($playlist_url
. "?node_id=$video_id&secret=$secret&tech=flash&mode=playlist"
. "&lq=$guid&bitrate=700&rd=video.yahoo.com&noad=1");

$xml = eval { XML::Simple::XMLin($browser->content) };
die "Failed parsing XML: $@" if $@;

$xml = $xml->{"SEQUENCE-ITEM"};
die "XML not as expected" unless $xml;

my $filename = title_to_filename($xml->{META}->{TITLE});
my $url = $xml->{STREAM}->{APP} . $xml->{STREAM}->{FULLPATH};

return $url, $filename;
}

sub make_guid {
my($self) = @_;

my @chars = ('A' .. 'Z', 'a' .. 'z', 0 .. 9, '.', '_');
return join "", map { $chars[rand @chars] } 1 .. 22;
}

1;
3 changes: 3 additions & 0 deletions t/urls
Expand Up @@ -87,6 +87,9 @@ http://gawker.com/5206458/watch-a-google-street-view-car-hit-a-bridge
# Fora
http://fora.tv/series/interrogation_or_torture

# Flickr
http://www.flickr.com/photos/startcooking/2665769896/

## Generic

# Creativity-online - link expired
Expand Down

0 comments on commit 8fb12ac

Please sign in to comment.