Change alert box detection
[videosite.git] / videosite / YouTubeGrabber.pm
index 83cee59..199143e 100644 (file)
@@ -14,6 +14,8 @@ use videosite::GrabberBase;
 use LWP::UserAgent;
 use HTTP::Cookies;
 use HTML::TokeParser;
+use HTML::Entities qw(decode_entities);
+use Encode;
 use Data::Dumper;
 use videosite::JSArrayParser;
 
@@ -73,6 +75,8 @@ sub _parse {
     $metadata->{'TITLE'} = undef;
     $metadata->{'DLURL'} = undef;
 
+    $self->debug("Matched id %s from pattern %s", $2, $pattern);
+
     $preflist = $preflist{$quality};
     $self->debug("Quality: %s, preflist: [%s]", $quality, join(", ", @{$preflist}));
 
@@ -100,6 +104,11 @@ sub _parse {
         if ('meta' eq $tag->[0]) {
             if ('title' eq $tag->[1]->{'name'}) {
                 $metadata->{'TITLE'} = $tag->[1]->{'content'};
+                # Convert HTML entities in the title. This is a bit convoluted.
+                $metadata->{'TITLE'} = encode("utf8",
+                                         decode_entities(
+                                           decode("utf8", $metadata->{'TITLE'})));
+                    
                 $self->debug('Title found: %s', $metadata->{'TITLE'});
             }
         } elsif ('script' eq $tag->[0]) {
@@ -184,7 +193,7 @@ sub _parse {
                 last SWF_ARGS;
             }
         } elsif ('div' eq $tag->[0]) {
-            if (exists($tag->[1]->{'class'}) and ('errorBox' eq $tag->[1]->{'class'})) {
+            if (exists($tag->[1]->{'class'}) and ('yt-alert-content' eq $tag->[1]->{'class'})) {
                 $self->error("Could not get video data for youtube %s: %s",
                         $metadata->{'ID'}, $p->get_trimmed_text());
                 return undef;