=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/ServerTorrents.pl,v retrieving revision 1.9 retrieving revision 1.18 diff -u -r1.9 -r1.18 --- openbsd/OpenBSDTorrents/ServerTorrents.pl 2005/04/04 03:14:17 1.9 +++ openbsd/OpenBSDTorrents/ServerTorrents.pl 2005/05/20 18:51:51 1.18 @@ -1,15 +1,15 @@ #!/usr/bin/perl -T -#$Id: ServerTorrents.pl,v 1.9 2005/04/04 02:14:17 andrew Exp $ +#$Id: ServerTorrents.pl,v 1.18 2005/05/20 17:51:51 andrew Exp $ use strict; use warnings; use diagnostics; -use BT::MetaInfo; use LWP::UserAgent; use Time::Local; use lib 'lib'; use OpenBSDTorrents; +use BT::MetaInfo::Cached; %ENV = (); @@ -17,18 +17,10 @@ justme(); -my $url_torrents = 'http://openbsd.somedomain.net/dumptorrents.php'; -my $url_upload = 'http://openbsd.somedomain.net/newtorrents.php'; -my $url_delete = 'http://openbsd.somedomain.net/deltorrents.php'; -my $url_sanity = 'http://openbsd.somedomain.net/sanity.php'; - -my $user = 'torrentup'; -my $pass = 'ssapword'; - my @Sizes = ('', 'Ki', 'Mi', 'Gi', 'Ti'); my $ua = LWP::UserAgent->new; -my $response = $ua->get($url_torrents); +my $response = $ua->get($OBT->{URL_TORRENTS}); my %server_torrents; if ($response->is_success) { @@ -53,7 +45,7 @@ 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) { chomp; if (/^([^\/]+)$/) { @@ -65,20 +57,28 @@ my ($name, $year, $mon, $mday, $hour, $min) = /^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/; - my $time = "$year.$mon.$mday $hour:$min"; + my $t; + eval { + $t = BT::MetaInfo::Cached->new( + $_, + { + cache_root => + $OBT->{DIR_HOME} . '/FileCache' + } + ); + }; - $mon--; + if ($@) { + warn "Error reading torrent $_\n"; + return undef; + } - my $epoch = timegm(0,$min,$hour,$mday,$mon,$year); + my $epoch = $t->creation_date; $files{$name}{$epoch} = { file => $_, - year => $year, - mon => $mon, - mday => $mday, - hour => $hour, - min => $min, - time => $time, + details => $t, + name => $name, epoch => $epoch, }; @@ -100,7 +100,7 @@ # $files{$name}{$epoch}{hour} . ':' . # $files{$name}{$epoch}{min} . ':00'; - Upload_Torrent($torrent, $files{$name}{$epoch}{time}); + Upload_Torrent($files{$name}{$epoch}); } next; } @@ -115,25 +115,25 @@ } } -$ua->get($url_sanity); +$ua->get($OBT->{URL_SANITY}); sub Upload_Torrent { - my $file = shift; - my $time = shift; + my $torrent = shift; + my $t = $torrent->{'details'}; + my $file = $torrent->{'file'}; print "Uploading $file\n"; - my $t; - eval { $t = BT::MetaInfo->new("$TorrentDir/$file"); }; - if ($@) { - warn "Error reading torrent $file\n"; - return undef; - } - my $size = $t->total_size; + my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = + gmtime($t->creation_date); + $year += 1900; + $mon++; + my $time = sprintf "%04d.%02d.%02d %02d:%02d", + $year, $mon, $mday, $hour, $min; - my $i; + my $i = 0; while ($size > 1024) { $size /= 1024; $i++; @@ -150,13 +150,13 @@ $comment .= " [$size]"; $filename .= " [$time]"; - my $response = $ua->post($url_upload, { - username => $user, - password => $pass, - torrent => [ "$TorrentDir/$file" ], + my $response = $ua->post($OBT->{URL_UPLOAD}, { + username => $OBT->{UPLOAD_USER}, + password => $OBT->{UPLOAD_PASS}, + torrent => [ $OBT->{DIR_TORRENT} . "/$file" ], url => "/torrents/$file", filename => $filename, - filedate => $time, + filedate => $t->creation_date, info => $comment, hash => '', autoset => 'enabled', # -> checked="checked"