BTMetafile
A while ago i started with BTMetafile as a php class that can create BitTorrent metafiles. As of now, it can generate the metafile structure and bencodes single files or directories properly (bencoding is done through a separate BTBencode class). Yet it lacks a class for decoding.
Class BTMetafile can be obtained from http://svn.var.cc/svn/phpbtmc/btmetafile.php (user anonymous, no password)
Usage:
$encoder = new BTBencode();
$opts = array('encoder' => $encoder,
'announceurl' => 'http://var.cc:6969/announce');
$m = new BTMetafile($opts);
$m->makeMetafile('/tmp/test.mp3');
$m->saveMetafile('/tmp/test.mp3.torrent');
Comments
Thanks very much for posting this. I haven't had a chance to test it yet but if it works as advertised then you just made my life a lot easier trying to add some torrent functionality to a community file archive I look after.
If it all works out I'll drop a note when it is in place so you can check it out.
Cheers
http://industrial.org
Hi
Please feel free to also drop a note in case it doesn't works out :)
I tested it with the original python bt client and Azureus.
Howdy. I found a bug which I have corrected. The problem is that dictionaries are supposed to be sorted which they were't being. The problem is in the function BTMetafil::makeMetafile() - essentially you need to do some key sorts on the arrays. Here's the changed lines:
$info = $this->makeinfo($file);
ksort($info);
$this->metainfostruct['info'] = $info;
ksort($this->metainfostruct);
Before sorting I would get errors from the Python client. After sorting all is happy.
Cheers!
http://industrial.org
http://ampfea.org
Indeed - i recognized that i confused the getFileInfo() method so that the pieces key appeard first. Is fixed in svn and added the ksort() as well.
Thanks!
s
No new comments allowed (anymore) on this post.








