jj20051 Posted December 6, 2009 Share Posted December 6, 2009 Alright for the fun of it I decided to make a bet with a friend that I could make a clone of mininova (a torrent site). Now I realized right off the bat that I'd have to figure out how to read a torrent file to extract the title, seeds, leachers and the size of the file to be downloaded. I'm pretty sure this can be done with PHP but I'm just not sure how. Can anyone help me? I'm posting this before I get to far into the project to ensure I can have this ready to go before I'm finished with the rest of the site. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 You would look at preg_match or substr to accomplish extracting data, assuming it's plaintext. You can apply it like this: $torrent_file = file_get_contents('./torrents/example.torrent'); preg_match("/seeds/", $torrent_file); //Just an example If there are delimiters you can use explode which may be easier as it'll put it into an array.. Quote Link to comment Share on other sites More sharing options...
jj20051 Posted December 6, 2009 Author Share Posted December 6, 2009 While that didn't extract what I wanted it to it seems that in order to extract the seeds and leechers the PHP file would have to connect to the tracker and ask the tracker for the data. The problem is I'm not sure how i'd pull that off correctly. I realize i'd have to use cURL. Aside from that I'm lost. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 Just an example, It's not going to be easy if you don't know the basics atleast.. http://www.phpclasses.org/browse/package/3138.html There's a php torrent parser, you may need to sign up to download it but that site is useful. You can use an example there, it should have all you need. Quote Link to comment Share on other sites More sharing options...
jj20051 Posted December 6, 2009 Author Share Posted December 6, 2009 Thanks, I tried that before posting here though. The script just shoves all the data into an array and doesn't do 1/3 of what I need it to so its virtually worthless. Quote Link to comment Share on other sites More sharing options...
Altec Posted December 6, 2009 Share Posted December 6, 2009 A torrent file is not plain text, it's in a special format. I think there is a PHP class to parse them but I can't remember the name of it. Also, just a quick FYI, seeders and leachers are not listed in the torrent file. It simply holds a session hash that the torrent client sends to the tracker. The tracker is what responds to the torrent client with the seeders and leachers list. Quote Link to comment Share on other sites More sharing options...
jj20051 Posted December 6, 2009 Author Share Posted December 6, 2009 Also, just a quick FYI, seeders and leachers are not listed in the torrent file. It simply holds a session hash that the torrent client sends to the tracker. The tracker is what responds to the torrent client with the seeders and leachers list. Meant to mention that, thanks... Quote Link to comment Share on other sites More sharing options...
jj20051 Posted December 6, 2009 Author Share Posted December 6, 2009 Anyone else got any ideas, I'd love to hear them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.