| version 1.27, 2010/01/05 19:43:44 |
version 1.28, 2010/01/05 19:55:22 |
|
|
| Process_Dir( $OBT->{DIR_FTP} ); |
Process_Dir( $OBT->{DIR_FTP} ); |
| |
|
| my %files; |
my %files; |
| my %keep; |
|
| my @delete; |
my @delete; |
| foreach my $DIR ( $OBT->{DIR_NEW_TORRENT}, $OBT->{DIR_TORRENT} ) { |
foreach my $DIR ( $OBT->{DIR_NEW_TORRENT}, $OBT->{DIR_TORRENT} ) { |
| opendir DIR, $DIR |
opendir DIR, $DIR |
|
|
| } |
} |
| |
|
| #print Dump \%files; |
#print Dump \%files; |
| |
|
| |
my %keep; |
| foreach my $name ( sort keys %{ $files{torrent} } ) { |
foreach my $name ( sort keys %{ $files{torrent} } ) { |
| next unless $name =~ /^$Name_Filter/; |
next unless $name =~ /^$Name_Filter/; |
| |
|
|
|
| |
|
| $files{torrent}{$name}{$epoch}{info_hash} = $hash; |
$files{torrent}{$name}{$epoch}{info_hash} = $hash; |
| |
|
| if ( exists $keep{$name} ) { |
if ( exists $keep{$hash} ) { |
| if ( exists $keep{$name}{$hash} ) { |
if ( $keep{$hash}{epoch} == $epoch ) { |
| if ( $keep{$name}{$hash}{epoch} == $epoch ) { |
next; |
| next; |
|
| } |
|
| print "Removing [$name] [$hash]\n\t", |
|
| $keep{$name}{$hash}{path}, |
|
| "\n"; |
|
| push @delete, $keep{$name}{$hash}; |
|
| delete $files{torrent}{ $keep{$name}{$hash}{name} } |
|
| { $keep{$name}{$hash}{epoch} }; |
|
| $keep{$name}{$hash} = $files{torrent}{$name}{$epoch}; |
|
| print "Keeping additional instance of [$name] [$hash]\n\t", |
|
| $keep{$name}{$hash}{path}, |
|
| "\n"; |
|
| } |
} |
| else { |
print "Removing [$name] [$hash]\n\t", $keep{$hash}{path}, "\n"; |
| print "Removing old [$name] [$hash]\n"; |
push @delete, $keep{$hash}; |
| if ( $keep{$name}{$hash}{path} ) { |
delete $files{torrent}{ $keep{$hash}{name} } |
| print "\t", $keep{$name}{$hash}{path}, "\n"; |
{ $keep{$hash}{epoch} }; |
| } |
$keep{$hash} = $files{torrent}{$name}{$epoch}; |
| push @delete, $files{torrent}{$name}{$epoch}; |
print "Keeping additional instance of [$name] [$hash]\n\t", |
| delete $files{torrent}{$name}{$epoch}; |
$keep{$hash}{path}, |
| |
"\n"; |
| |
} |
| |
else { |
| |
print "Removing old [$name] [$hash]\n"; |
| |
if ( $keep{$hash}{path} ) { |
| |
print "\t", $keep{$hash}{path}, "\n"; |
| } |
} |
| |
push @delete, $files{torrent}{$name}{$epoch}; |
| |
delete $files{torrent}{$name}{$epoch}; |
| } |
} |
| else { |
else { |
| print "Keeping first instance of $name [$hash]\n\t", |
print "Keeping first instance of $name [$hash]\n\t", |
| $files{torrent}{$name}{$epoch}{path}, |
$files{torrent}{$name}{$epoch}{path}, |
| "\n"; |
"\n"; |
| $keep{$name}{$hash} = $files{torrent}{$name}{$epoch}; |
$keep{$hash} = $files{torrent}{$name}{$epoch}; |
| |
|
| } |
} |
| } |
} |
|
|
| } |
} |
| |
|
| #print Dump \%keep; |
#print Dump \%keep; |
| foreach my $name ( keys %keep ) { |
foreach my $hash ( keys %keep ) { |
| foreach my $hash ( keys %{ $keep{$name} } ) { |
my $file = $keep{$hash}{file} || q{}; |
| my $file = $keep{$name}{$hash}{file} || q{}; |
my $dir = $keep{$hash}{dir} || q{}; |
| my $dir = $keep{$name}{$hash}{dir} || q{}; |
if ( $dir eq $OBT->{DIR_NEW_TORRENT} ) { |
| if ( $dir eq $OBT->{DIR_NEW_TORRENT} ) { |
print "Moving $file to current torrents\n"; |
| print "Moving $file to current torrents\n"; |
rename( "$dir/$file", $OBT->{DIR_TORRENT} . "/" . $file ) |
| rename( "$dir/$file", $OBT->{DIR_TORRENT} . "/" . $file ) |
or die "Couldn't rename '$file': $!"; |
| or die "Couldn't rename '$file': $!"; |
|
| |
|
| my $name = $keep{$name}{$hash}{name}; |
my $name = $keep{$hash}{name}; |
| my $epoch = $keep{$name}{$hash}{epoch}; |
my $epoch = $keep{$hash}{epoch}; |
| |
|
| if ( exists $files{txt}{$name}{$epoch} ) { |
if ( exists $files{txt}{$name}{$epoch} ) { |
| my $m_file = $files{txt}{$name}{$epoch}{file}; |
my $m_file = $files{txt}{$name}{$epoch}{file}; |
| my $m_dir = $files{txt}{$name}{$epoch}{dir}; |
my $m_dir = $files{txt}{$name}{$epoch}{dir}; |
| rename( "$m_dir/$m_file", |
rename( "$m_dir/$m_file", $OBT->{DIR_TORRENT} . "/" . $m_file ) |
| $OBT->{DIR_TORRENT} . "/" . $m_file ) |
or die "Couldn't rename '$m_file': $!"; |
| or die "Couldn't rename '$m_file': $!"; |
|
| } |
|
| } |
} |
| } |
} |
| } |
} |