Skip to content

Commit

Permalink
make the web_seed work for multi-file torrents
Browse files Browse the repository at this point in the history
Also some other cleanup of creating torrents.
  • Loading branch information
afresh1 committed Oct 14, 2012
1 parent de850d3 commit 49957e3
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions MakeTorrents.pl
Expand Up @@ -97,7 +97,7 @@ sub Make_Torrent {


$t = Name_Torrent($renamed); $t = Name_Torrent($renamed);
$c = $f; $c = $f;
$torrents{$t}{name} = $renamed; $f = $renamed;
} }
elsif ( my ($ext) = $file =~ /$SONG_REGEX/xms ) { elsif ( my ($ext) = $file =~ /$SONG_REGEX/xms ) {
my $destdir = dirname($f) . '/' . $ext; my $destdir = dirname($f) . '/' . $ext;
Expand All @@ -112,11 +112,13 @@ sub Make_Torrent {
or die "Couldn't link $root/{$f to $destfile}: $!"; or die "Couldn't link $root/{$f to $destfile}: $!";


$t = Name_Torrent($destdir); $t = Name_Torrent($destdir);
$f = $destdir; $f = $destfile;
$c = "$ext files from $basedir"; $c = "$ext files from $basedir";


$torrents{$t}{name} = $destdir; $torrents{$t}{dir} = $destdir;
$torrents{$t}{files} = []; }
else {
$torrents{$t}{dir} = $basedir;
} }


$torrents{$t}{comment} = $c; $torrents{$t}{comment} = $c;
Expand All @@ -133,38 +135,33 @@ sub Make_Torrent {
. ( scalar @{ $torrents{$t}{files} } ) . ( scalar @{ $torrents{$t}{files} } )
. " files)\n"; . " files)\n";


my $n = $torrents{$t}{name} || $OBT->{BASENAME}; eval { btmake( $t, $torrents{$t} ); };
my $c = $torrents{$t}{comment}; warn "Error creating $t\n$@\n" if $@;
$c .= "\nCreated by andrew fresh (andrew\@afresh1.com)\n"
. "http://OpenBSD.somedomain.net/";

eval { btmake( $t, $n, $c, $torrents{$t}{files} ); };
if ($@) {
print "Error creating $t\n$@\n";
}
} }


return [ keys %torrents ]; return [ keys %torrents ];
} }


sub btmake { sub btmake {
my $torrent = shift; my ($t, $opts) = @_;
my $name = shift;
my $comment = shift;
my $files = shift;


my $source = $opts->{dir} || $opts->{files}->[0];

my $torrent_with_path = $OBT->{DIR_NEW_TORRENT} . "/$t";
my $announce = $OBT->{URL_TRACKER}; my $announce = $OBT->{URL_TRACKER};
my $web_seed = $OBT->{URL_WEBSEED} . $name; my $web_seed = $OBT->{URL_WEBSEED};
$web_seed .= $source if @{ $opts->{files} } == 1;


my $torrent_with_path = $OBT->{DIR_NEW_TORRENT} . "/$torrent"; my $comment = join "\n", $opts->{comment},
'Created by andrew fresh (andrew@afresh1.com)',
'http://OpenBSD.somedomain.net/';


system '/usr/local/bin/mktorrent', system '/usr/local/bin/mktorrent',
'-o', $torrent_with_path,
'-a', $announce, '-a', $announce,
'-w', $web_seed, '-w', $web_seed,
'-n', $name,
'-c', $comment, '-c', $comment,
'-o', $torrent_with_path, $source;
@{$files};


print "Created: $torrent_with_path\n"; print "Created: $torrent_with_path\n";
} }
Expand Down

0 comments on commit 49957e3

Please sign in to comment.