Skip to content

Instantly share code, notes, and snippets.

@gray
Created March 29, 2010 16:47
Show Gist options
  • Save gray/348077 to your computer and use it in GitHub Desktop.
Save gray/348077 to your computer and use it in GitHub Desktop.
List all youtube videos for a user
#!/usr/bin/env perl
use strict;
use warnings;
use XML::LibXML;
my $user = shift || die "No user specified\n";
my $feed_url = (
"http://gdata.youtube.com/feeds/api/users/$user/uploads?" .
'max-results=50'
);
my $parser = XML::LibXML->new;
my $xpc = XML::LibXML::XPathContext->new;
$xpc->registerNs('atom', 'http://www.w3.org/2005/Atom');
while ($feed_url) {
my $doc = eval { XML::LibXML->load_xml(location => $feed_url) };
$xpc->setContextNode($doc->documentElement);
undef $feed_url;
if (my $next = $xpc->findvalue('//atom:link[@rel="next"]/@href')) {
$feed_url = $next;
}
for my $entry ($xpc->findnodes('//atom:feed/atom:entry')) {
my ($id) = $xpc->findvalue('atom:id', $entry) =~ m{([^/]+)$};
print "http://www.youtube.com/watch?v=$id\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment