Youtube: Disable the scrap handlers for the 2009 and 2010 page formats, they should...
[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::Parser;
12 use Data::Dumper;
13
14 use strict;
15
16 sub new {
17     my $class = shift;
18     my $self = $class->SUPER::new();
19
20     $self->{'NAME'} = 'myvideo';
21     $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*myvideo.de/watch/(\d+))'];
22
23     bless($self, $class);
24     $self->_prepare_parameters();
25
26     return $self;
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 = HTML::Parser->new(api_version => 3);
36     my @accum;
37     my @text;
38     my $e;
39
40     $url =~ m|$pattern|;
41     $url = $1;
42
43     $metadata->{'URL'} = $url;
44     $metadata->{'ID'} = $2;
45     $metadata->{'TYPE'} = 'video';
46     $metadata->{'SOURCE'} = $self->{'NAME'};
47     $metadata->{'TITLE'} = undef;
48     $metadata->{'DLURL'} = undef;
49
50     unless(defined($content = $self->simple_get(sprintf('http://www.myvideo.de/watch/%s', $2)))) {
51         $self->error('Could not download %s', $url);
52         return undef;
53     }
54
55     $p->handler(start => \@accum, "tagname, attr");
56     $p->report_tags(qw(meta link));
57     $p->utf8_mode(1);
58     $p->parse($content);
59
60     # Look for the title in the meta tags
61     foreach $e (@accum) {
62         if ('meta' eq $e->[0]) {
63             if ('title' eq $e->[1]->{'name'}) {
64                 $metadata->{'TITLE'} = $e->[1]->{'content'};
65                 $metadata->{'TITLE'} =~ s/\s+Video\s+-\s+\S+\s+-\s+MyVideo$//;
66                 $self->debug("Found title: %s", $metadata->{'TITLE'});
67                 last;
68             }
69         }
70     }
71
72     # Look for the download URL
73     foreach $e (@accum) {
74         if ('link' eq $e->[0]) {
75             if (exists($e->[1]->{'rel'}) and ('image_src' eq $e->[1]->{'rel'})) {
76                 $metadata->{'DLURL'} = $e->[1]->{'href'};
77                 $metadata->{'DLURL'} =~ s,thumbs/[^/]*$,,;
78                 $metadata->{'DLURL'} .= $metadata->{'ID'} . ".flv";
79                 $self->debug("Found URL: %s", $metadata->{'DLURL'});
80                 last;
81             }
82         }
83     }
84
85     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
86         $self->error('Could not determine download URL');
87         return undef;
88     }
89
90     return $metadata;
91 }
92
93 1;