| version 1.9, 2005/04/04 03:14:17 |
version 1.13, 2005/05/05 18:48:19 |
|
|
| use warnings; |
use warnings; |
| use diagnostics; |
use diagnostics; |
| |
|
| use BT::MetaInfo; |
|
| use LWP::UserAgent; |
use LWP::UserAgent; |
| use Time::Local; |
use Time::Local; |
| |
|
| use lib 'lib'; |
use lib 'lib'; |
| use OpenBSDTorrents; |
use OpenBSDTorrents; |
| |
use BT::OBTMetaInfo; |
| |
|
| %ENV = (); |
%ENV = (); |
| |
|
|
|
| |
|
| justme(); |
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 @Sizes = ('', 'Ki', 'Mi', 'Gi', 'Ti'); |
| 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; |
chomp; |
| if (/^([^\/]+)$/) { |
if (/^([^\/]+)$/) { |
|
|
| } |
} |
| } |
} |
| |
|
| $ua->get($url_sanity); |
$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::OBTMetaInfo->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 $size = $t->total_size; |
| |
|
| my $i; |
my $i = 0; |
| while ($size > 1024) { |
while ($size > 1024) { |
| $size /= 1024; |
$size /= 1024; |
| $i++; |
$i++; |
|
|
| $comment .= " [$size]"; |
$comment .= " [$size]"; |
| $filename .= " [$time]"; |
$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, |