diff options
author | zakflash <zakflashvideo@gmail.com> | 2012-12-14 12:44:50 -0800 |
---|---|---|
committer | zakflash <zakflashvideo@gmail.com> | 2012-12-14 12:44:50 -0800 |
commit | 5a0142a39b149bd26188c3eeb02b4f5f39046069 (patch) | |
tree | ac146f316dfd8dc5f0a930891a1742b06fa9ed0d | |
parent | d74c9f6e0119f6340b027b1b97b6603704040922 (diff) | |
parent | bc346e8ed1ac1ad7e71419399f4102252867c742 (diff) | |
download | get-flash-videos-5a0142a39b149bd26188c3eeb02b4f5f39046069.tar.gz |
Merge pull request #84 from zmughal/master
Fix Putlocker and add support for SockShare
-rw-r--r-- | lib/FlashVideo/Site/Putlocker.pm | 62 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Sockshare.pm | 7 |
2 files changed, 58 insertions, 11 deletions
diff --git a/lib/FlashVideo/Site/Putlocker.pm b/lib/FlashVideo/Site/Putlocker.pm index 476ca17..0778fa1 100644 --- a/lib/FlashVideo/Site/Putlocker.pm +++ b/lib/FlashVideo/Site/Putlocker.pm @@ -4,12 +4,21 @@ package FlashVideo::Site::Putlocker; use strict; use FlashVideo::Utils; use HTML::Tree; +use HTML::Entities qw(decode_entities); +use URI; sub find_video { - my ($self, $browser, $embed_url) = @_; + my ($self, $browser, $embed_url, $prefs) = @_; + + die 'Could not retrieve video' unless ($browser->success); + + my ($id) = ($embed_url =~ m,file/([^/]*),); my ($filename) = title_to_filename(extract_title($browser)); - $filename =~ s/[\s\|_]*PutLocker[\s_]*//; + my $host = URI->new($embed_url)->host; # www.putlocker.com or www.sockshare.com + my $sitename = _host_to_sitename($host); + $filename =~ s/[\s\|_]*$sitename[\s_]*//; + my $url; # the final URL #get the "hash" value from the HTML my $tree = HTML::Tree->new(); @@ -18,7 +27,7 @@ sub find_video { info 'Found hash: ' . $hash; #Construct a POST request to get the tell the server to serve real page content - info "Confirming request to PutLocker."; + info "Confirming request to $sitename."; $browser->add_header( 'Content-Type' => 'application/x-www-form-urlencoded' ); $browser->add_header( 'Accept-Encoding' => 'text/html' ); @@ -29,29 +38,60 @@ sub find_video { 'hash'=>$hash ]); - #we will get a redirect, this is the cue to re-request the same page - die if not - die 'Response code was ' . $response->code . '. Should be 302.' unless ($response->code == '302'); + # request is successful - die if not + die 'Request not successful' unless ($browser->success); - info "Re-fetching page, which will now have the video embedded."; - $browser->delete_header( 'Content-Type'); - my $page_html = $browser->get($embed_url)->content; + my $page_html = $response->content; #the stream ID is now embedded in the page. - my ($streamID) = ($page_html =~ /get_file\.php\?stream=([A-Za-z0-9]+)/); + my ($streamID) = ($page_html =~ /get_file\.php\?stream=([A-Za-z0-9=]+)/); info "Found the stream ID: " . $streamID; #request the url of the actual file - my $uri = URI->new( "http://www.putlocker.com/get_file.php" ); + my $uri = URI->new( "http://$host/get_file.php" ); $uri->query_form((stream=>$streamID)); #parse the url and title out of the response - much easier to regex it out, as the XML has dodgy &'s. + $browser->allow_redirects; my $contents = $browser->get($uri)->content; - my ($url) = ($contents =~ /url="(.*?)"/); + # this is necessary to download both high quality and streaming version + die 'Unable to download video information' unless ($browser->success); + my ($stream_url) = ($contents =~ /url="(.*?)"/); + $stream_url = decode_entities($stream_url); + if($stream_url =~ /expired_link/) { + # if link is unavailable + if( $page_html =~ m,"/(get_file\.php\?id=[^"]*)", ) { + # download original file if link available + my $download_page = $1; + $url = URI->new( "http://$host/$1" ); + # this URL should be equivalent to what is returned by _get_high_quality() + } + } elsif($prefs->{quality} eq 'high' and $host eq 'www.putlocker.com') { + # only works on PutLocker + $url = _get_high_quality($host, $id, $streamID); + } else { + # get streaming version + $url = $stream_url; + } info "Got the video URL: " . $url; return $url, $filename; } +sub _get_high_quality { + my ( $host, $id, $key ) = @_; + return "http://$host/get_file.php?id=$id&key=$key&original=1"; +} + +sub _host_to_sitename { + my ($host) = @_; + if($host eq 'www.putlocker.com') { + return "PutLocker"; + } elsif($host eq 'www.sockshare.com') { + return "SockShare"; + } +} + 1; diff --git a/lib/FlashVideo/Site/Sockshare.pm b/lib/FlashVideo/Site/Sockshare.pm new file mode 100644 index 0000000..61a79c8 --- /dev/null +++ b/lib/FlashVideo/Site/Sockshare.pm @@ -0,0 +1,7 @@ +# Part of get-flash-videos. See get_flash_videos for copyright. +package FlashVideo::Site::Sockshare; + +# SockShare uses the same software as PutLocker +use base 'FlashVideo::Site::Putlocker'; + +1; |