[BACK]Return to CurrentTorrents.pl CVS log [TXT][DIR] Up to [local] / openbsd / OpenBSDTorrents

Annotation of openbsd/OpenBSDTorrents/CurrentTorrents.pl, Revision 1.2

1.1       andrew      1: #!/usr/bin/perl -T
1.2     ! andrew      2: #$Id: CurrentTorrents.pl,v 1.1 2005/03/23 00:15:55 andrew Exp andrew $
1.1       andrew      3: use strict;
                      4: use warnings;
                      5: use diagnostics;
                      6:
                      7: use BT::MetaInfo;
1.2     ! andrew      8: use Time::Local;
1.1       andrew      9:
                     10: use lib 'lib';
                     11: use OpenBSDTorrents;
                     12:
                     13: %ENV = ();
                     14:
1.2     ! andrew     15: #use YAML;
1.1       andrew     16:
1.2     ! andrew     17: my %files;
        !            18: opendir DIR, $TorrentDir or die "Couldn't opendir $TorrentDir: $!";
        !            19: foreach (readdir DIR) {
        !            20:        if (/^([^\/]+)$/) {
        !            21:                $_ = $1;
        !            22:        } else {
        !            23:                die "Invalid character in $_: $!";
        !            24:        }
        !            25:        next unless /\.torrent$/;
        !            26:        my ($name, $year, $mon, $mday, $hour, $min) =
        !            27:           /^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/;
        !            28:
        !            29:        my $epoch = timegm(0,$min,$hour,$mday,$mon,$year);
        !            30:
        !            31:         my $t = BT::MetaInfo->new("$TorrentDir/$_");
        !            32:        my $hash = $t->info_hash;
        !            33:        $hash = unpack("H*", $hash);
        !            34:
        !            35:        $files{$name}{$epoch} = {
        !            36:                file      => $_,
        !            37:                comment   => $t->{comment},
        !            38:                year      => $year,
        !            39:                mon       => $mon,
        !            40:                mday      => $mday,
        !            41:                hour      => $hour,
        !            42:                min       => $min,
        !            43:                epoch     => $epoch,
        !            44:                info_hash => $hash,
        !            45:        };
        !            46:
        !            47: }
        !            48: closedir DIR;
        !            49:
        !            50:
        !            51: my %keep;
        !            52: my @delete;
        !            53: foreach my $name (keys %files) {
        !            54:        foreach my $time ( sort { $b <=> $a } keys %{ $files{$name} } ) {
        !            55:                #print "$name - $time\n";
        !            56:                my $hash = $files{$name}{$time}{info_hash};
        !            57:                if (exists $keep{$name}) {
        !            58:                        if (exists $keep{$name}{$hash}) {
        !            59:                                push @delete, $keep{$name}{$hash};
        !            60:                                $keep{$name}{$hash} =
        !            61:                                        $files{$name}{$time}{file};
        !            62:                        } else {
        !            63:                                push @delete, $files{$name}{$time}{file};
        !            64:                        }
        !            65:                } else {
        !            66:                        $keep{$name}{$hash} =
        !            67:                                $files{$name}{$time}{file};
        !            68:
        !            69:                }
        !            70:        }
        !            71: }
        !            72:
        !            73: #print Dump \%files, \%keep, \@delete;
        !            74:
        !            75: foreach (@delete) {
        !            76:        unlink "$TorrentDir/$_" or die "Couldn't unlink $_";
        !            77: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>