Skip to content

Instantly share code, notes, and snippets.

@013
Created June 5, 2012 13:19
Show Gist options
  • Save 013/2874931 to your computer and use it in GitHub Desktop.
Save 013/2874931 to your computer and use it in GitHub Desktop.
Perl-Youtube-Downloader
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
my $url = $ARGV[0];
die"URL Needed\n" unless defined $url;
$url =~ /[\?&]v=(.{11})/g;
my $video_id = $1;
my $info_url = "http://www.youtube.com/get_video_info?video_id=" . $video_id;
my $content = get $info_url;
$content = urldecode(urldecode(urldecode($content))); # That decoding....
my @matches = $content =~ /url=(http:\/\/[^:]*);/g;
foreach(@matches) {
print "$_\n\n";
}
sub urldecode {
my $str = shift;
$str =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
$str =~ s/\+/ /g;
return $str;
}
@013
Copy link
Author

013 commented Jan 22, 2014

This no longer works, but was cool at the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment