version 1.28, 2010/01/07 18:50:02 |
version 1.31, 2012/09/01 17:36:37 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
#$RedRiver: ServerTorrents.pl,v 1.27 2008/12/29 22:04:00 andrew Exp $ |
#$RedRiver: ServerTorrents.pl,v 1.29 2010/03/08 20:19:37 andrew Exp $ |
use strict; |
use strict; |
use warnings; |
use warnings; |
use diagnostics; |
use diagnostics; |
|
|
if ( !exists $server_torrents{$hash} ) { |
if ( !exists $server_torrents{$hash} ) { |
Upload_Torrent( $torrents{$hash} ); |
Upload_Torrent( $torrents{$hash} ); |
} |
} |
|
elsif ( $server_torrents{$hash}{disabled} ) { |
|
Update_Torrent( $server_torrents{$hash}{name}, $hash ); |
|
} |
} |
} |
closedir DIR; |
closedir DIR; |
|
|
|
|
if ( ( !exists $torrents{$hash} ) |
if ( ( !exists $torrents{$hash} ) |
&& ( !$server_torrents{$hash}{disabled} ) ) |
&& ( !$server_torrents{$hash}{disabled} ) ) |
{ |
{ |
Delete_Torrent( $server_torrents{$hash}{name}, $hash ); |
Update_Torrent( $server_torrents{$hash}{name}, $hash, 1 ); |
} |
} |
} |
} |
|
|
|
|
my $t = $torrent->{'details'}; |
my $t = $torrent->{'details'}; |
|
|
my $file = $torrent->{'file'}; |
my $file = $torrent->{'file'}; |
print "Uploading $file\n"; |
#print "Uploading $file\n"; |
|
|
my $size = $t->total_size; |
my $size = $t->total_size; |
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday ) |
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday ) |
|
|
} |
} |
} |
} |
|
|
sub Delete_Torrent { |
sub Update_Torrent { |
my $filename = shift; |
my $filename = shift; |
my $hash = shift; |
my $hash = shift; |
|
my $disable = shift || 0; |
die "No hash passed!" unless $hash; |
die "No hash passed!" unless $hash; |
|
|
print "Removing $filename [$hash]\n"; |
#print "Removing $filename [$hash]\n"; |
|
|
my $response = $ua->post( |
my $response = $ua->post( |
$OBT->{'URL_DELETE'}, |
$OBT->{'URL_UPDATE'}, |
{ username => $OBT->{UPLOAD_USER}, |
{ username => $OBT->{UPLOAD_USER}, |
password => $OBT->{UPLOAD_PASS}, |
password => $OBT->{UPLOAD_PASS}, |
filename => $filename, |
|
hash => $hash, |
hash => $hash, |
|
disable => $disable, |
}, |
}, |
Content_Type => 'form-data' |
Content_Type => 'form-data' |
); |
); |
|
my $status = $disable ? 'Disabled' : 'Enabled'; |
|
|
if ( $response->is_success ) { |
if ( $response->is_success ) { |
my ($result) = $response->content =~ /class="error"\>([^<]+)\</; |
my ($result) = $response->content =~ /class="error"\>([^<]+)\</; |
|
|
if ( $result eq 'Torrent was removed successfully.' ) { |
if ( $result eq 'Torrent disabled set to ' . $disable ) { |
print STDERR "Removed $filename [$hash]\n"; |
print STDERR "$status $filename [$hash]\n"; |
} |
} |
elsif ($result) { |
elsif ($result) { |
print STDERR "Error: $result (removing $filename [$hash])\n"; |
print STDERR "Error: $result (removing $filename [$hash])\n"; |