=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/ServerTorrents.pl,v retrieving revision 1.1 retrieving revision 1.8 diff -u -r1.1 -r1.8 --- openbsd/OpenBSDTorrents/ServerTorrents.pl 2005/03/24 00:22:09 1.1 +++ openbsd/OpenBSDTorrents/ServerTorrents.pl 2005/04/01 01:20:15 1.8 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -#$Id: ServerTorrents.pl,v 1.1 2005/03/24 00:22:09 andrew Exp $ +#$Id: ServerTorrents.pl,v 1.8 2005/04/01 01:20:15 andrew Exp $ use strict; use warnings; use diagnostics; @@ -13,15 +13,19 @@ %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 $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); @@ -51,16 +55,18 @@ my %files; opendir DIR, $TorrentDir or die "Couldn't opendir $TorrentDir: $!"; 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})/; + $mon--; + my $epoch = timegm(0,$min,$hour,$mday,$mon,$year); $files{$name}{$epoch} = { @@ -98,11 +104,15 @@ } foreach my $file (keys %server_torrents) { - unless (exists $files{$file}) { + my ($name, $year, $mon, $mday, $hour, $min) = + $file =~ + /^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/; + unless (exists $files{$name}) { Delete_Torrent($file); } } +$ua->get($url_sanity); sub Upload_Torrent { @@ -118,13 +128,24 @@ return undef; } + my $size = $t->total_size; + + my $i; + while ($size > 1024) { + $size /= 1024; + $i++; + } + $size = sprintf('%.2f', $size); + $size .= $Sizes[$i] . 'B'; + my $comment = $t->{comment}; $comment =~ s/\n.*$//s; - - my ($filename) = $comment =~ /Files from ([^<]+)/; + + my ($filename) = $comment =~ /Files from (.+)/; $filename =~ s#/# #g; - $filename .= ' (' . $time . ')'; + $comment .= " [$size]"; + $filename .= " [$time]"; my $response = $ua->post($url_upload, { username => $user, @@ -139,7 +160,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;