fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / MyVideoGrabber.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # Grabber for myvideo.de
5
6 package videosite::MyVideoGrabber;
7
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
10
11 use HTML::TokeParser;
12 use Data::Dumper;
13
14 use strict;
15
16 sub new {
17     my $class = shift;
18     my $self = $class->SUPER::new(
19         NAME => 'myvideo',
20         _SELFTESTURL => 'http://www.myvideo.de/watch/9191174/Battle_Worlds_Kronos_Alpha_Version_ausprobiert',
21         _SELFTESTTITLE => 'Battle Worlds: Kronos - Alpha-Version ausprobiert',
22         PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*myvideo.de/watch/(\d+))'],
23         @_,
24     );
25
26     return bless($self, $class);
27 }
28
29 sub _parse {
30     my $self = shift;
31     my $url = shift;
32     my $pattern = shift;
33     my $content;
34     my $metadata = {};
35     my $p;
36     my $t;
37
38     $url =~ m|$pattern|;
39     $url = $1;
40
41     $metadata->{'URL'} = $url;
42     $metadata->{'ID'} = $2;
43     $metadata->{'TYPE'} = 'video';
44     $metadata->{'SOURCE'} = $self->{'NAME'};
45     $metadata->{'TITLE'} = undef;
46     $metadata->{'DLURL'} = undef;
47
48     unless(defined($content = $self->simple_get(sprintf('http://www.myvideo.de/watch/%s', $2)))) {
49         $self->error('Could not download %s', $url);
50         return undef;
51     }
52
53     $p = HTML::TokeParser->new(\$content);
54     while ($t = $p->get_tag('meta', 'link')) {
55         if ('meta' eq $t->[0]) {
56             if (exists($t->[1]->{property}) and ($t->[1]->{property} eq 'og:title')) {
57                 $metadata->{'TITLE'} = $t->[1]->{content};
58             }
59         } elsif ('link' eq $t->[0]) {
60             if (exists($t->[1]->{rel}) and ($t->[1]->{rel} eq 'image_src')) {
61                 $metadata->{'DLURL'} = $t->[1]->{'href'};
62                 $metadata->{'DLURL'} =~ s,thumbs/[^/]*$,,;
63                 $metadata->{'DLURL'} .= $metadata->{'ID'} . ".flv";
64                 $self->debug("Found URL: %s", $metadata->{'DLURL'});
65             }
66         }
67     }
68
69     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
70         $self->error('Could not determine download URL');
71         return undef;
72     }
73
74     return $metadata;
75 }
76
77 1;