From d26fa8c1e0886c813de5364ee6570c860c6ce12c Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Thu, 31 Mar 2011 19:05:23 +0000 Subject: hopfully repaired this after backup loss --- nzbget/download.pm | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 nzbget/download.pm (limited to 'nzbget/download.pm') diff --git a/nzbget/download.pm b/nzbget/download.pm new file mode 100644 index 0000000..39394e7 --- /dev/null +++ b/nzbget/download.pm @@ -0,0 +1,95 @@ +package nzbget::download; +use strict; +use Apache2::Const -compile => qw(OK REDIRECT); +use CGI qw(:standard); +use CGI::Carp 'fatalsToBrowser'; +use local::nzbget; +use local::db; +use local::user; +use utf8; +#use CGI::Ajax; + +sub handler +{ + print header(); + print Show_HTML(); +# my $cgi = new CGI; +# my $pjx = new CGI::Ajax( 'get_download_speed' => \&get_download_speed, +# 'get_download_table' => \&get_download_table +# ); +# print $pjx->build_html( $cgi, \&Show_HTML); + return Apache2::Const::OK; +} + +sub get_download_speed +{ + my $cli = new local::nzbget; + my $status = $cli->send_request('status') or die "Can't connect to nzbget"; + my $speed = int($status->{DownloadRate}/(1024*1024)); + return $speed?$speed.'MB/s':int($status->{DownloadRate}/1024).'KB/s'; +} + +sub get_download_table +{ + my $user = new local::user(%ENV); + my $html; + my $cli = new local::nzbget; + my $row = $cli->send_request('listgroups') or die "Can't connect to nzbget"; + $html.= CGI::start_table(); + $html.= Tr(th([qw/Kategorie Name Besitzer Größe(MB) Fortschritt Abbrechen/])); + foreach my $value ( @$row) + { + my ($download) = local::db::download->retrieve($value->{NZBNicename}) or die ' Error in groups'; + my $remaining=$value->{RemainingSizeMB}; + my $total=$value->{FileSizeMB}; + my $percent = int(100-100*$remaining/$total); + if (not $download->size) + { + $download->size($total); + $download->update(); + $user->obj->quota_used($user->obj->quota_used+$total); + $user->obj->update(); + } + my $cancel; + if ($download->processing == 1) + { + $html.=Tr(td([$download->category->name,$download->name,$download->owner->name,$total,'unpacking',''])); + } else { + $cancel=a({href=>'cancel?id='.$value->{NZBNicename}},'Abbrechen') if ($download->owner->owner_id() eq $user->get_id()); + $html.= Tr(td([$download->category->name,$download->name,$download->owner->name,$total,$percent.'%',$cancel])); + } + #foreach my $key (keys %$value) + #{ + # $html.= Tr(td([$key,$value->{$key}])); + #} + } + $html.= CGI::end_table(); + return $html; +} + +sub Show_HTML +{ + use local::menu; + my $menu= new local::menu(%ENV); + my $html= $menu->start_html('nzbget status'); + + $html.= < +LALALA + ; +# $html.= < +#LALALA +# ; + $html.= table({class=>'nohigh'},Tr(td['download speed   '. span({id=>'speed'},get_download_speed())]),Tr(td([' ']))); + $html.= div({id=>'dls'},get_download_table()); + + $html.= $menu->end_html(); + return $html +} + +1; -- cgit v1.2.3