Created
April 2, 2010 15:44
-
-
Save xaicron/353284 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
| use strict; | |
| use warnings; | |
| use utf8; | |
| use LWP::Simple; | |
| use URI::Escape; | |
| use Encode; | |
| my %SUFFIX = ( | |
| 37 => '.mp4', | |
| 35 => '.flv', | |
| 34 => '.flv', | |
| 22 => '.mp4', | |
| 18 => '.mp4', | |
| 17 => '.3gp', | |
| 13 => '.3gp', | |
| 6 => '.flv', | |
| 5 => '.flv', | |
| ); | |
| my $video_id = shift; | |
| my $info = "http://www.youtube.com/get_video_info?video_id=$video_id"; | |
| my $down = "http://www.youtube.com/get_video?video_id=$video_id&t=%s=&fmt=%d"; | |
| my $param = +{}; | |
| for my $p (split '&', decode_utf8 uri_unescape get $info) { | |
| my ($key, $value) = $p =~ m/^(\w+)=(.*)/; | |
| if ($key eq 'itag' && $param->{$key}) { | |
| $param->{$key} = $value if $value > $param->{$key}; | |
| next; | |
| } | |
| $param->{$key} = $value; | |
| } | |
| my $fmt = $param->{itag} || 18; | |
| mirror(sprintf($down, $param->{token}, $fmt), $video_id . $SUFFIX{$fmt}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment