Created
October 2, 2011 03:44
-
-
Save miya2000/1257006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # author: mizzy, yusukebe | |
| use Plagger::Util qw( decode_content ); | |
| use JSON; | |
| use URI::Escape; | |
| sub handle { | |
| my ($self, $url) = @_; | |
| $url =~ qr!http://(?:(?:au|br|ca|fr|de|us|hk|ie|it|jp|mx|nl|nz|pl|es|tw|gb|www)\.)?youtube\. | |
| com/(?:watch(?:\.php)?)?\?v=.+!; | |
| } | |
| sub find { | |
| my ($self, $args) = @_; | |
| my $url = $args->{url}; | |
| my $ua = Plagger::UserAgent->new; | |
| my $res = $ua->fetch($url); | |
| return if $res->is_error; | |
| if ((my $verify_url = $res->http_response->request->uri) =~ /\/verify_age\?/) { | |
| $res = $ua->post($verify_url, { action_confirm => 'Confirm' }); | |
| return if $res->is_error; | |
| $res = $ua->fetch($url); | |
| return if $res->is_error; | |
| $args->{content} = decode_content($res); | |
| } | |
| if ($args->{content} =~ /yt\.playerConfig\s*=\s*(.*?);\n/) { | |
| my $obj = decode_json($1); | |
| my $fmt_stream_map = uri_unescape($obj->{args}->{url_encoded_fmt_stream_map}); | |
| if ($fmt_stream_map =~ /url=([^;]+quality=(?:hd720|large)[^;]*type=video\/mp4[^;]*);/) { | |
| my $video_url = $1; | |
| my $enclosure = Plagger::Enclosure->new; | |
| $enclosure->url($video_url); | |
| $enclosure->type('video/mp4'); | |
| if ($url =~ /v=(\w+)/) { | |
| $enclosure->filename("$1.mp4"); | |
| } | |
| return $enclosure; | |
| } | |
| } | |
| return; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment