version 1.17, 2005/05/20 18:18:13 |
version 1.21, 2006/05/15 19:47:04 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
#$Id$ |
#$RedRiver: ServerTorrents.pl,v 1.20 2005/06/03 01:32:40 andrew Exp $ |
use strict; |
use strict; |
use warnings; |
use warnings; |
use diagnostics; |
use diagnostics; |
|
|
s/^\s+//; |
s/^\s+//; |
s/\s+$//; |
s/\s+$//; |
next unless $_; |
next unless $_; |
my ($name, $hash) = split /\t/; |
my ($name, $hash, $disabled) = split /\t/; |
next if $name eq 'File'; |
next if $name eq 'File'; |
|
|
$name =~ s#^/torrents/##; |
$name =~ s#^/torrents/##; |
$server_torrents{$name} = $hash; |
$server_torrents{$name}{$hash} = $disabled; |
} |
} |
} |
} |
} else { |
} else { |
|
|
my $t; |
my $t; |
eval { |
eval { |
$t = BT::MetaInfo::Cached->new( |
$t = BT::MetaInfo::Cached->new( |
$_, |
$OBT->{DIR_TORRENT} . '/' . $_, |
{ |
{ |
cache_root => |
cache_root => |
$OBT->{DIR_HOME} . '/FileCache' |
$OBT->{DIR_HOME} . '/FileCache' |
|
|
|
|
if ($@) { |
if ($@) { |
warn "Error reading torrent $_\n"; |
warn "Error reading torrent $_\n"; |
return undef; |
next; |
} |
} |
|
|
my $epoch = $t->creation_date; |
my $epoch = $t->creation_date; |
|
|
} |
} |
closedir DIR; |
closedir DIR; |
|
|
#print Dump \%server_torrents, \%files; |
#use Data::Dumper; |
|
#print Dumper \%server_torrents;#, \%files; |
|
#exit; |
|
|
foreach my $name (keys %files) { |
my %torrents; |
|
FILE: foreach my $name (keys %files) { |
#print "$name\n"; |
#print "$name\n"; |
foreach my $epoch ( sort { $b <=> $a } keys %{ $files{$name} } ) { |
foreach my $epoch ( sort { $b <=> $a } keys %{ $files{$name} } ) { |
#print "\t$epoch\n"; |
#print "\t$epoch\n"; |
my $torrent = $files{$name}{$epoch}{file}; |
my $torrent = $files{$name}{$epoch}{file}; |
unless (exists $server_torrents{$torrent} ) { |
|
#my $time = |
my $hash = $files{$name}{$epoch}{'details'}->info_hash; |
# $files{$name}{$epoch}{year} . '-' . |
$hash = unpack("H*", $hash); |
# $files{$name}{$epoch}{mon} . '-' . |
|
# $files{$name}{$epoch}{mday} . ' ' . |
$torrents{$torrent}{$hash} = $files{$name}{$epoch}; |
# $files{$name}{$epoch}{hour} . ':' . |
|
# $files{$name}{$epoch}{min} . ':00'; |
unless (exists $server_torrents{$torrent}{$hash}) { |
|
|
Upload_Torrent($files{$name}{$epoch}); |
Upload_Torrent($files{$name}{$epoch}); |
} |
} |
next; |
|
} |
} |
} |
} |
|
|
foreach my $file (keys %server_torrents) { |
foreach my $torrent (keys %server_torrents) { |
my ($name, $year, $mon, $mday, $hour, $min) = |
foreach my $hash (keys %{ $server_torrents{$torrent} }) { |
$file =~ |
unless ( |
/^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/; |
exists $torrents{$torrent}{$hash} || |
unless (exists $files{$name}) { |
$server_torrents{$torrent}{$hash} == 1 |
Delete_Torrent($file); |
) { |
|
Delete_Torrent($torrent, $hash); |
|
} |
} |
} |
} |
} |
|
|
|
|
my $time = sprintf "%04d.%02d.%02d %02d:%02d", |
my $time = sprintf "%04d.%02d.%02d %02d:%02d", |
$year, $mon, $mday, $hour, $min; |
$year, $mon, $mday, $hour, $min; |
|
|
|
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = |
|
localtime($t->creation_date); |
|
$year += 1900; |
|
$mon++; |
|
my $sql_time = sprintf "%04d-%02d-%02d %02d:%02d", |
|
$year, $mon, $mday, $hour, $min; |
|
|
my $i = 0; |
my $i = 0; |
while ($size > 1024) { |
while ($size > 1024) { |
$size /= 1024; |
$size /= 1024; |
|
|
torrent => [ $OBT->{DIR_TORRENT} . "/$file" ], |
torrent => [ $OBT->{DIR_TORRENT} . "/$file" ], |
url => "/torrents/$file", |
url => "/torrents/$file", |
filename => $filename, |
filename => $filename, |
filedate => $time, |
filedate => $sql_time, |
info => $comment, |
info => $comment, |
hash => '', |
hash => '', |
autoset => 'enabled', # -> checked="checked" |
autoset => 'enabled', # -> checked="checked" |
|
|
|
|
sub Delete_Torrent |
sub Delete_Torrent |
{ |
{ |
my $file = shift; |
my $filename = shift; |
print "Will delete $file soon enough\n"; |
my $hash = shift; |
|
die "No hash passed!" unless $hash; |
|
|
|
print "Disabling $filename\n"; |
|
|
|
my $response = $ua->post($OBT->{'URL_DELETE'}, { |
|
username => $OBT->{UPLOAD_USER}, |
|
password => $OBT->{UPLOAD_PASS}, |
|
filename => $filename, |
|
hash => $hash, |
|
}, Content_Type => 'form-data'); |
|
|
|
if ($response->is_success) { |
|
#print $response->content; |
|
if ($response->content =~ /Torrent was removed successfully/) { |
|
print STDERR "Disabled $filename\n"; |
|
} else { |
|
print STDERR "An error occoured removing $filename\n"; |
|
} |
|
} else { |
|
die $response->status_line; |
|
} |
} |
} |