diff options
author | Othmar Gsenger <otti@wirdorange.org> | 2011-01-14 00:17:57 +0000 |
---|---|---|
committer | Othmar Gsenger <otti@wirdorange.org> | 2011-01-14 00:17:57 +0000 |
commit | a60811a6efa731d8229b713fbb16cd9770ec143d (patch) | |
tree | f5049cacbf9ceac6b7cf13da001ea25979c20cfa | |
parent | da files (diff) |
added modules
-rw-r--r-- | local/nzbget.pm | 22 | ||||
-rwxr-xr-x | local/nzbindex.pm | 46 | ||||
-rw-r--r-- | local/params.pm | 31 | ||||
-rwxr-xr-x | log.pl | 6 | ||||
-rwxr-xr-x | search.pl | 50 |
5 files changed, 120 insertions, 35 deletions
diff --git a/local/nzbget.pm b/local/nzbget.pm new file mode 100644 index 0000000..ea3b47a --- /dev/null +++ b/local/nzbget.pm @@ -0,0 +1,22 @@ +package local::nzbget; +require Exporter; +require RPC::XML; +require RPC::XML::Client; +use strict; +use base "Exporter"; + +sub new +{ + my $invocant = shift; + my $class = ref($invocant) || $invocant; + # my $self = $class->SUPER::new(@_); + my $self=bless {@_}, $class; + $self->{cli} = RPC::XML::Client->new('http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc'); + return $self; +} + +sub send_request +{ + my $self = shift; + return $self->{cli}->send_request(@_) or die "Can't connect to nzbget"; +} diff --git a/local/nzbindex.pm b/local/nzbindex.pm new file mode 100755 index 0000000..8352a5d --- /dev/null +++ b/local/nzbindex.pm @@ -0,0 +1,46 @@ +package local::nzbget; +require Exporter; +use strict; +use base "Exporter"; +use URI::Escape; +use XML::Parser; +use XML::SimpleObject; +use LWP::Simple; + +sub new +{ + my $invocant = shift; + my $class = ref($invocant) || $invocant; + # my $self = $class->SUPER::new(@_); + my $self=bless {@_}, $class; + return $self; +} + +sub search +{ + my $self=shift; + my %params=@_; + my @result; + my $request=''; + for my $key (keys %params) { + $request.= uri_escape($key)."=".$params{$key}.'&'; + } + $request =~ s/\&$//; + my $feed = get('http://nzbindex.com/rss/?'.$request); + die "Couldn't get connect to search site" unless defined $feed; + my $p1 = new XML::Parser(Style => 'Tree'); + my $xso = XML::SimpleObject->new($p1->parse($feed)); + if ($xso->child('rss')->child('channel')) + { + print CGI::start_table(); + foreach my $item ($xso->child('rss')->child('channel')->children('item')) { + next if not $item; + my $title = $item->child('title')->value; + my $description = $item->child('description')->value; + my $nzburl = $item->child('enclosure')->attribute("url"); + push @result,{url=>$nzburl,title=>$title,description=>$description}; + } + } + return @result; +} + diff --git a/local/params.pm b/local/params.pm new file mode 100644 index 0000000..969d0fe --- /dev/null +++ b/local/params.pm @@ -0,0 +1,31 @@ +package local::params; +require Exporter; +use CGI qw(:standard); +use strict; +use base "Exporter"; + +sub new +{ + my $invocant = shift; + my $class = ref($invocant) || $invocant; + # my $self = $class->SUPER::new(@_); + my $self=bless {@_}, $class; + return $self; +} + +sub has_params +{ + my $self=shift; + return param()?1:0; +} + +sub get_as_hash +{ + my $self = shift; + my %result; + for my $key (param) { + $result{$key}=param($key); + } + + return %result; +} @@ -1,8 +1,6 @@ #!/usr/bin/perl use strict; - -require RPC::XML; -require RPC::XML::Client; +use local::nzbget; use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; use URI::Escape; @@ -11,7 +9,7 @@ print header; print start_html('nzbget status'); print hr(); -my $cli = RPC::XML::Client->new('http://nzbget:tegbzn6789@127.0.0.1:6789/xmlrpc'); +my $cli = new local::nzbget; print CGI::start_table(); my $status = $cli->send_request('status') or die "Can't connect to nubget"; print Tr(td['download speed', 'cur', int($status->{DownloadRate}->value/(1024*1024)).'MB/s','average',int($status->{AverageDownloadRate}->value/(1024*1024)).'MB/s']); @@ -3,12 +3,12 @@ use strict; use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; use URI::Escape; +use local::params; +use local::nzbindex; print header; print start_html('nzbget status'); -use XML::Parser; -use XML::SimpleObject; print CGI::start_table(); print CGI::start_form(-action=>'/cgi-bin/nzbget/search.pl'); @@ -25,36 +25,24 @@ print table( Tr(td([submit()])), ); print CGI::end_form; -if (param()) +my $param_obj=new local::params; +if ($param_obj->has_params()) { - my $request=''; - for my $key (param) { - $request.= "$key=".param($key).'&'; - } - $request =~ s/\&$//; - use LWP::Simple; - my $feed = get('http://nzbindex.com/rss/?'.$request); - die "Couldn't get connect to search site" unless defined $feed; - my $p1 = new XML::Parser(Style => 'Tree'); - my $xso = XML::SimpleObject->new($p1->parse($feed)); - my $i=0; - if ($xso->child('rss')->child('channel')) - { - print CGI::start_table(); - foreach my $item ($xso->child('rss')->child('channel')->children('item')) { - next if not $item; - $i++; - my $title = $item->child('title')->value; - my $description = $item->child('description')->value; - my $nzburl = $item->child('enclosure')->attribute("url"); - print Tr(td([ - a({href=>"./enqueue.pl?url=".uri_escape($nzburl)."&name=".uri_escape(param('q'))},$title).' '. - a({href=>"./enqueue.pl?url=".uri_escape($nzburl)."&name=".uri_escape(param('q'))."&cat=music"},'Music'). - $description])); - } - print CGI::end_table(); - } - print hr().'nothing found' if not $i; + my $nzbindex=new local::nzbindex; + my @search = $nzbindex->search($param_obj->get_as_hash()); + if (@search) + { + print CGI::start_table(); + foreach my $item (@search) { + print Tr(td([ + a({href=>"./enqueue.pl?url=".uri_escape($item->{url})."&name=".uri_escape(param('q'))},$item->{title}).' '. + a({href=>"./enqueue.pl?url=".uri_escape($item->{url})."&name=".uri_escape(param('q'))."&cat=music"},'Music'). + $item->{description}])); + } + print CGI::end_table(); + } else { + print hr().'nothing found'; + } } print end_html; |