commit:b2e07e4758fafa140a6325fd3ce43901373f9f48
author:Chip Black
committer:Chip Black
date:Tue May 19 21:04:38 2009 -0500
parents:dc082919abf26d87045aea84855ecd84cccd9c4b
Accept both id and full URL, and error on failure
diff --git a/youtube-subrip b/youtube-subrip
line changes: +8/-1
index f73c48d..1ada937
--- a/youtube-subrip
+++ b/youtube-subrip
@@ -3,10 +3,17 @@ use LWP::Simple;
 use XML::Twig;
 use strict;
 
-my $id = shift;
+my $url = shift;
+$url =~ /v=([A-Za-z0-9_]+)/;
+my $id = $1 || $url;
 
 my $xml = get("http://video.google.com/timedtext?hl=en&v=$id&type=track&name=&lang=en");
 
+unless (defined $xml) {
+	print "Could not fetch subtitles for $id\n";
+	exit 1;
+}
+
 my $t = XML::Twig->new(
 	twig_roots => { 'text' => \&convert_text }
 );