version 1.6, 2005/03/25 03:12:05 |
version 1.12, 2005/05/02 21:27:00 |
|
|
|
|
justme(); |
justme(); |
|
|
|
my $Name_Filter = shift || ''; |
|
if ($Name_Filter =~ /^(\w*)$/) { |
|
$Name_Filter = $1; |
|
} else { |
|
die "Invalid filter: $Name_Filter"; |
|
} |
|
|
my %files; |
my %files; |
opendir DIR, $TorrentDir or die "Couldn't opendir $TorrentDir: $!"; |
opendir DIR, $OBT->{DIR_TORRENT} |
|
or die "Couldn't opendir $OBT->{DIR_TORRENT}: $!"; |
foreach (readdir DIR) { |
foreach (readdir DIR) { |
if (/^([^\/]+)$/) { |
if (/^([^\/]+)$/) { |
$_ = $1; |
$_ = $1; |
|
|
my ($name, $year, $mon, $mday, $hour, $min) = |
my ($name, $year, $mon, $mday, $hour, $min) = |
/^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/; |
/^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/; |
|
|
|
$mon--; |
my $epoch = timegm(0,$min,$hour,$mday,$mon,$year); |
my $epoch = timegm(0,$min,$hour,$mday,$mon,$year); |
|
|
print "Adding $_\n"; |
#print "Adding $_\n"; |
|
|
$files{$name}{$epoch} = { |
$files{$name}{$epoch} = { |
file => $_, |
file => $_, |
|
|
my %keep; |
my %keep; |
my @delete; |
my @delete; |
foreach my $name (keys %files) { |
foreach my $name (keys %files) { |
#print "$name\n"; |
next unless $name =~ /^$Name_Filter/; |
|
print "Checking $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}; |
|
|
my $t; |
my $t; |
eval { $t = BT::MetaInfo->new("$TorrentDir/$torrent"); }; |
eval { $t = BT::MetaInfo->new($OBT->{DIR_TORRENT} . "/$torrent"); }; |
if ($@) { |
if ($@) { |
warn "Error reading torrent $torrent\n"; |
warn "Error reading torrent $torrent\n"; |
next; |
next; |
|
|
$files{$name}{$epoch}{comment} = $t->{comment}; |
$files{$name}{$epoch}{comment} = $t->{comment}; |
my ($path) = $t->{comment} =~ /Files from ([^\n]+)\n/s; |
my ($path) = $t->{comment} =~ /Files from ([^\n]+)\n/s; |
|
|
unless (-d "$BaseDir/$path") { |
unless (-d $OBT->{DIR_FTP} . "/$path") { |
print "Deleting $files{$name}{$epoch}{file} the path doesn't exist.\n"; |
#print "Deleting $files{$name}{$epoch}{file} the path doesn't exist.\n"; |
push @delete, $files{$name}{$epoch}{file}; |
push @delete, $files{$name}{$epoch}{file}; |
} |
} |
|
|
if (keys %{ $files{$name} } == 1) { |
if (keys %{ $files{$name} } == 1) { |
print "Skipping torrent for $name there is only one.\n"; |
#print "Skipping torrent for $name there is only one.\n"; |
next; |
next; |
} |
} |
|
|
|
|
|
|
foreach (@delete) { |
foreach (@delete) { |
print "Deleting '$_'\n"; |
print "Deleting '$_'\n"; |
unlink "$TorrentDir/$_" or die "Couldn't unlink $_"; |
unlink $OBT->{DIR_TORRENT} . "/$_" or die "Couldn't unlink $_"; |
} |
} |