| version 1.2, 2005/03/24 00:42:07 |
version 1.10, 2005/04/07 00:05:28 |
|
|
| |
|
| %ENV = (); |
%ENV = (); |
| |
|
| use YAML; |
#use YAML; |
| |
|
| my $url_torrents = 'http://openbsd.somedomain.net/dumptorrents.php'; |
justme(); |
| my $url_upload = 'http://openbsd.somedomain.net/newtorrents.php'; |
|
| my $url_delete = 'http://openbsd.somedomain.net/deltorrents.php'; |
|
| |
|
| my $user = 'torrentup'; |
my @Sizes = ('', 'Ki', 'Mi', 'Gi', 'Ti'); |
| my $pass = 'ssapword'; |
|
| |
|
| my $ua = LWP::UserAgent->new; |
my $ua = LWP::UserAgent->new; |
| |
|
| my $response = $ua->get($url_torrents); |
my $response = $ua->get($OBT->{URL_TORRENTS}); |
| |
|
| my %server_torrents; |
my %server_torrents; |
| if ($response->is_success) { |
if ($response->is_success) { |
|
|
| |
|
| |
|
| my %files; |
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) { |
foreach (readdir DIR) { |
| |
chomp; |
| if (/^([^\/]+)$/) { |
if (/^([^\/]+)$/) { |
| $_ = $1; |
$_ = $1; |
| } else { |
} else { |
| die "Invalid character in $_: $!"; |
die "Invalid character in $_: $!"; |
| } |
} |
| next unless /\.torrent$/; |
next unless /\.torrent$/; |
| chomp; |
|
| my ($name, $year, $mon, $mday, $hour, $min) = |
my ($name, $year, $mon, $mday, $hour, $min) = |
| /^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/; |
/^(.*)-(\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); |
my $epoch = timegm(0,$min,$hour,$mday,$mon,$year); |
| |
|
| $files{$name}{$epoch} = { |
$files{$name}{$epoch} = { |
|
|
| mday => $mday, |
mday => $mday, |
| hour => $hour, |
hour => $hour, |
| min => $min, |
min => $min, |
| |
time => $time, |
| epoch => $epoch, |
epoch => $epoch, |
| }; |
}; |
| |
|
|
|
| #print "\t$epoch\n"; |
#print "\t$epoch\n"; |
| my $torrent = $files{$name}{$epoch}{file}; |
my $torrent = $files{$name}{$epoch}{file}; |
| unless (exists $server_torrents{$torrent} ) { |
unless (exists $server_torrents{$torrent} ) { |
| my $time = |
#my $time = |
| $files{$name}{$epoch}{year} . '-' . |
# $files{$name}{$epoch}{year} . '-' . |
| $files{$name}{$epoch}{mon} . '-' . |
# $files{$name}{$epoch}{mon} . '-' . |
| $files{$name}{$epoch}{mday} . ' ' . |
# $files{$name}{$epoch}{mday} . ' ' . |
| $files{$name}{$epoch}{hour} . ':' . |
# $files{$name}{$epoch}{hour} . ':' . |
| $files{$name}{$epoch}{min} . ':00'; |
# $files{$name}{$epoch}{min} . ':00'; |
| |
|
| Upload_Torrent($torrent, $time); |
Upload_Torrent($torrent, $files{$name}{$epoch}{time}); |
| } |
} |
| next; |
next; |
| } |
} |
|
|
| } |
} |
| } |
} |
| |
|
| |
$ua->get($OBT->{URL_SANITY}); |
| |
|
| sub Upload_Torrent |
sub Upload_Torrent |
| { |
{ |
|
|
| print "Uploading $file\n"; |
print "Uploading $file\n"; |
| |
|
| my $t; |
my $t; |
| eval { $t = BT::MetaInfo->new("$TorrentDir/$file"); }; |
eval { $t = BT::MetaInfo->new("$OBT->{DIR_TORRENT}/$file"); }; |
| if ($@) { |
if ($@) { |
| warn "Error reading torrent $file\n"; |
warn "Error reading torrent $file\n"; |
| return undef; |
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}; |
my $comment = $t->{comment}; |
| $comment =~ s/\n.*$//s; |
$comment =~ s/\n.*$//s; |
| |
|
| my ($filename) = $comment =~ /Files from ([^<]+)/; |
my ($filename) = $comment =~ /Files from (.+)/; |
| $filename =~ s#/# #g; |
$filename =~ s#/# #g; |
| |
|
| $filename .= ' (' . $time . ')'; |
$comment .= " [$size]"; |
| |
$filename .= " [$time]"; |
| |
|
| my $response = $ua->post($url_upload, { |
my $response = $ua->post($OBT->{URL_UPLOAD}, { |
| username => $user, |
username => $OBT->{UPLOAD_USER}, |
| password => $pass, |
password => $OBT->{UPLOAD_PASS}, |
| torrent => [ "$TorrentDir/$file" ], |
torrent => [ $OBT->{DIR_TORRENT} . "/$file" ], |
| url => "/torrents/$file", |
url => "/torrents/$file", |
| filename => $filename, |
filename => $filename, |
| filedate => $time, |
filedate => $time, |
|
|
| }, Content_Type => 'form-data'); |
}, Content_Type => 'form-data'); |
| |
|
| if ($response->is_success) { |
if ($response->is_success) { |
| print "Uploaded $file\n"; |
print STDERR "Uploaded $file\n"; |
| #print $response->content; |
#print $response->content; |
| } else { |
} else { |
| die $response->status_line; |
die $response->status_line; |