From 1ecf932c3bc66f79608bc057184af51fe323bcb7 Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Fri, 27 May 2011 09:21:20 +0200 Subject: [PATCH] Add HTTPJSONGetter --- videosite/HTTPJSONGetter.pm | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 videosite/HTTPJSONGetter.pm diff --git a/videosite/HTTPJSONGetter.pm b/videosite/HTTPJSONGetter.pm new file mode 100644 index 0000000..87a6d83 --- /dev/null +++ b/videosite/HTTPJSONGetter.pm @@ -0,0 +1,46 @@ +# (c) 2007 by Ralf Ertzinger +# licensed under GNU GPL v2 +# +# A getter which POSTs the JSONified metadata to a remote URL + +package videosite::HTTPJSONGetter; + +use videosite::GetterBase; +@ISA = qw(videosite::GetterBase); + +use strict; +use LWP::UserAgent; +use JSON -support_by_pp; + +sub new { + my $class = shift; + my $self = $class->SUPER::new(); + + $self->{'NAME'} = 'HTTPJSONGetter'; + $self->{'_PARAMS'} = {'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."]}; + + bless($self, $class); + $self->_prepare_parameters(); + + return $self; +} + +sub get { + my $self = shift; + my $video = shift; + my $j = JSON->new(); + my $ua = LWP::UserAgent->new('agent' => 'Mozilla/5.0'); + my $jdata; + my $r; + + $jdata = $j->encode($video); + + $self->debug("Encoded metadata to %s", $jdata); + $r = $ua->post($self->_getval('URL'), {'json' => $jdata}); + unless ($r->is_success()) { + $self->error("Error calling RPC: %s", $r->code()); + return 0; + } + + return 1; +} -- 1.8.3.1