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