added torrent creation prototypes
git-svn-id: http://yolanda.mister-muffin.de/svn@234 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
f7ea26799b
commit
6262fd714e
2 changed files with 82 additions and 0 deletions
1
trunk/torrentaction/1.torrent
Normal file
1
trunk/torrentaction/1.torrent
Normal file
|
@ -0,0 +1 @@
|
|||
d8:announce30:http://my.tracker.tld/announce13:announce-listll8:tracker1ee7:comment9:kommentar10:created by7:yolanda13:creation datei2342134213e9:httpseedsl17:mydomain.tld/seede4:infod6:lengthi4020619e4:name9:some name12:piece lengthi262144e6:pieces320:Lz7xm* òŽ0/-
”óÔÔaGô“D<13>G¾Ü]v¬bÄ+õ‡¸ýØÏÿ-©¯;·2A–)<29>PŒÁ¼‹"-#ÒŸTA\dk -BD©ãÿr¦‘YN<12>3ôÙ–(Þ‡cû£V(¡®ÒQ<C392>*†Öbžq'È<>eY1¬•QÚJ€oôÂþ®úºµ ¤Eîl݃_yn.-H…<48>Œê³Fëî1úÆQµŒµ”ÕØ΂‰Ô9_ÿ˜Â÷‹xÁ^²VrY&:G?ŽúËÑ£G7i¯3ÓÞÃ1·Œ6B¼CnÀб¯îÏô0ƒ']€³Úp‡½»ƒõ<C692>ƒ„ËÅ¡ß=¢~m2‰R}4ï¼2Ðî³N„á/â”qó·'܆žz«®G²å,°pÖߒÂ$%%.н‹ö¥^ŽsÔp¢ee
|
81
trunk/torrentaction/torrent.pl
Normal file
81
trunk/torrentaction/torrent.pl
Normal file
|
@ -0,0 +1,81 @@
|
|||
$database = 'yolanda';
|
||||
$dbhost = 'localhost';
|
||||
$dbuser = 'root';
|
||||
$dbpass = '';
|
||||
$root = '/var/www/yolanda';
|
||||
|
||||
|
||||
use Digest::SHA qw{sha1};
|
||||
|
||||
open(FILE, "<$root/videos/1");
|
||||
while (my $BytesRead = read (FILE, $buff, 262144))
|
||||
{
|
||||
$hash .= sha1($buff);
|
||||
}
|
||||
close(FILE);
|
||||
|
||||
%torrent = (
|
||||
'announce' => 'http://my.tracker.tld/announce',
|
||||
'announce-list' =>
|
||||
[
|
||||
[
|
||||
'tracker1'
|
||||
]
|
||||
],
|
||||
'creation date' => 2342134213,
|
||||
'comment' => 'kommentar',
|
||||
'created by' => 'yolanda',
|
||||
'httpseeds' =>
|
||||
[
|
||||
'mydomain.tld/seed'
|
||||
],
|
||||
'info' =>
|
||||
{
|
||||
'length' => -s "$root/videos/1",
|
||||
'name' => 'some name',
|
||||
'piece length' => 262144,
|
||||
'pieces' => $hash
|
||||
}
|
||||
);
|
||||
|
||||
open(TORRENT, ">$root/1.torrent");
|
||||
print TORRENT bencode(\%torrent);
|
||||
close(TORRENT);
|
||||
|
||||
sub bencode {
|
||||
no locale;
|
||||
my $item = shift;
|
||||
my $line = '';
|
||||
|
||||
if(ref($item) eq 'HASH')
|
||||
{
|
||||
$line = 'd';
|
||||
foreach my $key (sort(keys %{$item}))
|
||||
{
|
||||
$line .= bencode($key);
|
||||
$line .= bencode(${$item}{$key});
|
||||
}
|
||||
$line .= 'e';
|
||||
}
|
||||
elsif(ref($item) eq 'ARRAY')
|
||||
{
|
||||
$line = 'l';
|
||||
foreach my $l (@{$item})
|
||||
{
|
||||
$line .= bencode($l);
|
||||
}
|
||||
$line .= 'e';
|
||||
}
|
||||
elsif($item =~ /^\d+$/)
|
||||
{
|
||||
$line = 'i';
|
||||
$line .= $item;
|
||||
$line .= 'e';
|
||||
}
|
||||
else
|
||||
{
|
||||
$line = length($item).":";
|
||||
$line .= $item;
|
||||
}
|
||||
return $line;
|
||||
}
|
Loading…
Reference in a new issue