fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / HTTPJSONGetter.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # A getter which POSTs the JSONified metadata to a remote URL
5
6 package videosite::HTTPJSONGetter;
7
8 use videosite::GetterBase;
9 @ISA = qw(videosite::GetterBase);
10
11 use strict;
12 use LWP::UserAgent;
13 use JSON -support_by_pp;
14
15 sub new {
16     my $class = shift;
17     my $self = $class->SUPER::new(
18         NAME => 'HTTPJSONGetter',
19         _PARAMS => {
20             URL => ['http://www.example.com/getjson.pl', "The URL to call in order to trigger a download. The JSON encoded information will be POSTed to this URL."]
21         },
22         @_,
23     );
24
25     return bless($self, $class);
26 }
27
28 sub get {
29     my $self = shift;
30     my $video = shift;
31     my $j = JSON->new();
32     my $ua = LWP::UserAgent->new('agent' => 'Mozilla/5.0');
33     my $jdata;
34     my $r;
35
36     $jdata = $j->encode($video);
37
38     $self->debug("Encoded metadata to %s", $jdata);
39     $r = $ua->post($self->_getval('URL'), {'json' => $jdata});
40     unless ($r->is_success()) {
41         $self->error("Error calling RPC: %s", $r->code());
42         return 0;
43     }
44
45     return 1;
46 }