Skip to content

Instantly share code, notes, and snippets.

@ramtiga
Created August 12, 2011 09:54
Show Gist options
  • Save ramtiga/1141796 to your computer and use it in GitHub Desktop.
Save ramtiga/1141796 to your computer and use it in GitHub Desktop.
get Youtube Info
#!/usr/bin/env perl
use strict;
use warnings;
use URI::Escape;
use LWP::Simple;
use Data::Dumper;
my $id = shift || die "Usage: $0 [video_id]";
my $dt = get_info($id);
die 'error:'. uri_unescape($dt->{reason}) if $dt->{status} eq 'fail';
my $title = uri_unescape($dt->{title});
$title =~ s/\+/ /g;
print $title;
sub get_info {
my $video_id = shift;
my $uri = "http://youtube.com/get_video_info?video_id=$video_id";
my $data = get($uri);
my %hash = ();
my @dt = split(/&/, $data);
for (@dt) {
my($k, $v) = split(/=/, $_);
$hash{$k} = $v;
}
return \%hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment