- Initial checkin
[videosite.git] / videosite / HTTPRPCGetter.pm
1 package HTTPRPCGetter;
2
3 use GetterBase;
4 @ISA = qw(GetterBase);
5
6 use strict;
7 use LWP::Simple qw(!get);
8
9 sub new {
10     my $class = shift;
11     my $self = $class->SUPER::new();
12
13     $self->{'NAME'} = 'HTTPRPCGetter';
14     $self->{'_PARAMS'} = {'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"]};
15
16     bless($self, $class);
17     $self->_prepare_parameters();
18
19     return $self;
20 }
21
22 sub get {
23     my $self = shift;
24     my $video = shift;
25     my $callurl;
26
27     $callurl = sprintf($self->_getval('URL'),
28         $self->_encode($video->{'TYPE'}),
29         $self->_encode($video->{'ID'}),
30         $self->_encode($video->{'TITLE'}),
31         $self->_encode($video->{'DLURL'}),
32         $self->_encode($video->{'URL'}));
33
34     $self->debug('Going to call %s', $callurl);
35
36     unless(defined(LWP::Simple::get($callurl))) {
37         $self->error("Error calling RPC");
38         return 0;
39     }
40
41     return 1;
42 }
43
44 sub _encode {
45     my $self = shift;
46     my $s = shift;
47
48     $s =~ s/(.)/sprintf("%%%02x", ord($1))/ge;
49
50     return $s;
51 }