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 /local | |
parent | da files (diff) |
added modules
Diffstat (limited to 'local')
-rw-r--r-- | local/nzbget.pm | 22 | ||||
-rwxr-xr-x | local/nzbindex.pm | 46 | ||||
-rw-r--r-- | local/params.pm | 31 |
3 files changed, 99 insertions, 0 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; +} |