=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/ServerTorrents.pl,v retrieving revision 1.3 retrieving revision 1.11 diff -u -r1.3 -r1.11 --- openbsd/OpenBSDTorrents/ServerTorrents.pl 2005/03/24 19:49:51 1.3 +++ openbsd/OpenBSDTorrents/ServerTorrents.pl 2005/05/02 21:26:04 1.11 @@ -1,10 +1,10 @@ #!/usr/bin/perl -T -#$Id: ServerTorrents.pl,v 1.3 2005/03/24 19:49:51 andrew Exp $ +#$Id: ServerTorrents.pl,v 1.11 2005/05/02 20:26:04 andrew Exp $ use strict; use warnings; use diagnostics; -use BT::MetaInfo; +use BT::OBTMetaInfo; use LWP::UserAgent; use Time::Local; @@ -13,20 +13,14 @@ %ENV = (); +#use YAML; -use YAML; +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 $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) { @@ -51,18 +45,22 @@ 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 (/^([^\/]+)$/) { $_ = $1; } else { die "Invalid character in $_: $!"; } next unless /\.torrent$/; - chomp; my ($name, $year, $mon, $mday, $hour, $min) = /^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/; + my $time = "$year.$mon.$mday $hour:$min"; + + $mon--; + my $epoch = timegm(0,$min,$hour,$mday,$mon,$year); $files{$name}{$epoch} = { @@ -72,6 +70,7 @@ mday => $mday, hour => $hour, min => $min, + time => $time, epoch => $epoch, }; @@ -86,14 +85,14 @@ #print "\t$epoch\n"; my $torrent = $files{$name}{$epoch}{file}; unless (exists $server_torrents{$torrent} ) { - my $time = - $files{$name}{$epoch}{year} . '-' . - $files{$name}{$epoch}{mon} . '-' . - $files{$name}{$epoch}{mday} . ' ' . - $files{$name}{$epoch}{hour} . ':' . - $files{$name}{$epoch}{min} . ':00'; + #my $time = + # $files{$name}{$epoch}{year} . '-' . + # $files{$name}{$epoch}{mon} . '-' . + # $files{$name}{$epoch}{mday} . ' ' . + # $files{$name}{$epoch}{hour} . ':' . + # $files{$name}{$epoch}{min} . ':00'; - Upload_Torrent($torrent, $time); + Upload_Torrent($torrent, $files{$name}{$epoch}{time}); } next; } @@ -108,6 +107,7 @@ } } +$ua->get($OBT->{URL_SANITY}); sub Upload_Torrent { @@ -117,7 +117,7 @@ print "Uploading $file\n"; my $t; - eval { $t = BT::MetaInfo->new("$TorrentDir/$file"); }; + eval { $t = BT::OBTMetaInfo->new("$OBT->{DIR_TORRENT}/$file"); }; if ($@) { warn "Error reading torrent $file\n"; return undef; @@ -142,10 +142,10 @@ $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, @@ -155,7 +155,7 @@ }, Content_Type => 'form-data'); if ($response->is_success) { - print "Uploaded $file\n"; + print STDERR "Uploaded $file\n"; #print $response->content; } else { die $response->status_line;