fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / HTTPRPCGetter.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # A getter which calls a remote URL in order to trigger a 
5 # download.
6
7 package videosite::HTTPRPCGetter;
8
9 use videosite::GetterBase;
10 @ISA = qw(videosite::GetterBase);
11
12 use strict;
13 use LWP::Simple qw(!get);
14
15 sub new {
16     my $class = shift;
17     my $self = $class->SUPER::new(
18         NAME => 'HTTPRPCGetter',
19         _PARAMS => {
20             URL => ['http://www.example.com/get.pl?type=%s&vid=%s&title=%s&url=%s', "The URL to call in order to trigger a download. This is a string which is passed to a sprintf call later on. The parameters passed to that sprintf call, in order, are:\n- The site the video is from\n- The ID of the video\n- The title of the video\n- The URL of the video file itself\n- The URL of the site the video was taken from\nAll parameters are hexencoded"]
21         },
22         @_,
23     );
24
25     return bless($self, $class);
26 }
27
28 sub get {
29     my $self = shift;
30     my $video = shift;
31     my $callurl;
32
33     $callurl = sprintf($self->_getval('URL'),
34         $self->_encode($video->{'SOURCE'}),
35         $self->_encode($video->{'ID'}),
36         $self->_encode($video->{'TITLE'}),
37         $self->_encode($video->{'DLURL'}),
38         $self->_encode($video->{'URL'}));
39
40     $self->debug('Going to call %s', $callurl);
41
42     unless(defined(LWP::Simple::get($callurl))) {
43         $self->error("Error calling RPC");
44         return 0;
45     }
46
47     return 1;
48 }
49
50 sub _encode {
51     my $self = shift;
52     my $s = shift;
53
54     $s =~ s/(.)/sprintf("%%%02x", ord($1))/ge;
55
56     return $s;
57 }