summaryrefslogtreecommitdiff
path: root/search.pl
diff options
context:
space:
mode:
Diffstat (limited to 'search.pl')
-rwxr-xr-xsearch.pl50
1 files changed, 19 insertions, 31 deletions
diff --git a/search.pl b/search.pl
index 8087d3e..66aafef 100755
--- a/search.pl
+++ b/search.pl
@@ -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;