| version 1.10, 2005/04/06 23:56:50 |
version 1.15, 2005/05/06 21:03:55 |
|
|
| use warnings; |
use warnings; |
| use diagnostics; |
use diagnostics; |
| |
|
| use BT::MetaInfo; |
|
| |
|
| use lib 'lib'; |
use lib 'lib'; |
| |
use BT::MetaInfo::Cached; |
| use OpenBSDTorrents; |
use OpenBSDTorrents; |
| |
|
| %ENV = (); |
%ENV = (); |
| |
|
| use YAML; |
chdir($OBT->{DIR_FTP}) || die "Couldn't change dir to " . $OBT->{DIR_FTP} . ": $!"; |
| |
|
| my $StartDir = shift || $OBT->{BASENAME}; |
my $StartDir = ''; |
| $StartDir =~ s#/$##; |
if (@ARGV) { |
| |
foreach (@ARGV) { |
| |
s#/$##; |
| |
Process_Dir($_); |
| |
} |
| |
} else { |
| |
$StartDir = $OBT->{BASENAME}; |
| |
Process_Dir($StartDir); |
| |
} |
| |
|
| chdir($OBT->{DIR_FTP}) || die "Couldn't change dir to " . $OBT->{DIR_FTP} . ": $!"; |
|
| |
|
| Process_Dir($StartDir); |
|
| |
|
| sub Process_Dir |
sub Process_Dir |
| { |
{ |
| my $basedir = shift; |
my $basedir = shift; |
| |
|
| |
#return undef if $basedir =~ /packages/; |
| |
|
| my ($dirs, $files) = Get_Files_and_Dirs($basedir); |
my ($dirs, $files) = Get_Files_and_Dirs($basedir); |
| if (@$files) { |
if (@$files) { |
| my $torrent = Make_Torrent($basedir, $files); |
my $torrent = Make_Torrent($basedir, $files); |
| } |
} |
| |
|
| # don't recurse if we were called on a specific directory |
# don't recurse if we were started with a specific directory |
| return 1 if $StartDir ne $OBT->{BASENAME}; |
return 1 if $StartDir ne $OBT->{BASENAME}; |
| |
|
| foreach my $subdir (@$dirs) { |
foreach my $subdir (@$dirs) { |
|
|
| |
|
| eval { btmake($torrent, $comment, $files); }; |
eval { btmake($torrent, $comment, $files); }; |
| if ($@) { |
if ($@) { |
| print "Error creating $torrent\n"; |
print "Error creating $torrent\n$@\n"; |
| } |
} |
| |
|
| # system($BTMake, |
# system($BTMake, |
|
|
| my $announce = $OBT->{URL_TRACKER}; |
my $announce = $OBT->{URL_TRACKER}; |
| my $piece_len = 2 << ($OBT->{PIECE_LENGTH} - 1); |
my $piece_len = 2 << ($OBT->{PIECE_LENGTH} - 1); |
| |
|
| $torrent = $OBT->{DIR_TORRENT} . "/$torrent"; |
my $torrent_with_path = $OBT->{DIR_NEW_TORRENT} . "/$torrent"; |
| |
|
| my $t = BT::MetaInfo->new(); |
$t = BT::MetaInfo::Cached->new( |
| |
$torrent, |
| |
{ |
| |
cache_root => |
| |
$OBT->{DIR_HOME} . '/FileCache' |
| |
} |
| |
); |
| |
|
| $t->name($name); |
$t->name($name); |
| $t->announce($announce); |
$t->announce($announce); |
| unless ($announce =~ m!^http://[^/]+/!i) { |
unless ($announce =~ m!^http://[^/]+/!i) { |
|
|
| return 0; |
return 0; |
| } |
} |
| |
|
| $t->save("$torrent"); |
my $hash = $t->info_hash; |
| print "Created: $torrent\n"; |
$hash = unpack("H*", $hash); |
| #system("btinfo $torrent") if ($::opt_I); |
|
| |
$t->save($torrent_with_path); |
| |
print "Created: $torrent_with_path\n"; |
| } |
} |
| |
|