fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / BroadcasterGrabber.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # Grabber for broadcaster.com
5
6 package videosite::BroadcasterGrabber;
7
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
10
11 use videosite::HTMLHelper;
12 use Data::Dumper;
13
14 use strict;
15
16 sub new {
17     my $class = shift;
18     my $self = $class->SUPER::new(
19         NAME => 'broadcaster',
20         PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*broadcaster\.com/clip/(\d+))'],
21         @_,
22     );
23
24     return bless($self, $class);
25 }
26
27 sub _parse {
28     my $self = shift;
29     my $url = shift;
30     my $pattern = shift;
31     my $content;
32     my $metadata = {};
33     my $p = videosite::HTMLHelper->new();
34     my $n;
35
36     $url =~ m|$pattern|;
37     $url = $1;
38
39     $metadata->{'URL'} = $url;
40     $metadata->{'ID'} = $2;
41     $metadata->{'TYPE'} = 'video';
42     $metadata->{'SOURCE'} = $self->{'NAME'};
43     $metadata->{'TITLE'} = undef;
44     $metadata->{'DLURL'} = undef;
45
46     unless(defined($content = $p->load(sprintf('http://www.broadcaster.com/clip/%s', $2)))) {
47         $self->error('Could not download %s', $url);
48         return undef;
49     }
50
51     # Look for the title
52     ($metadata->{'TITLE'}) = grep { $_ =~ m|\&page_title=([^\x22]+)\x22|s && {$_ = $1} }
53             map { join("", @{$_->content()}) }
54             grep { defined($_->content()) }
55             $p->findnodes('script');
56
57     # Look for the download URL
58     ($metadata->{'DLURL'}) = grep { $_ =~ m|\&clip_loc=.+?cache.broadcaster.com.+?escape\(\x22([^\x22]+)\x22\)|s && {$_ = 'http://cache.broadcaster.com/peoplecaster/' .$1} }
59             map { join("", @{$_->content()}) }
60             grep { defined($_->content()) }
61             $p->findnodes('script');
62
63     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
64         $self->error('Could not determine download URL');
65         return undef;
66     }
67
68     return $metadata;
69 }
70
71 1;