Search and download torrents from your favorite bittorrent tracker using Ruby 1.9.
Download and get information like:
Version 1.0 is no longer maintained. I might release version 2.0 in the future.
Torrents.the_pirate_bay.search("chuck").results
Torrents.the_pirate_bay.results
Torrents.the_pirate_bay.category(:movies).results
The page
method can be places anywhere before the results
method.
It starts counting from 1
and goes up, no matter what is used on the site it self.
Torrents.the_pirate_bay.page(6).results
Some trackers requires cookies to work, even though The Pirate Bay is not one of them.
Torrents.the_pirate_bay.cookies({
user_id: "123",
hash: "c4656002ce46f9b418ce72daccfa5424"
}).results
Here is an example of how to step through the 10 first pages.
torrents = Torrents.the_pirate_bay.step
10.times { torrents.results }
You just add the step method and it will increment page
everytime you apply the results
method.
As soon as you apply the results
method on the query it will try to execute your request.
If you for example want to activate the debugger, define some cookies or specify a page, then you might do something like this.
Torrents.the_pirate_bay.page(5).debug(true).cookies(:my_cookie => "value").results
It will return a list of Container::Torrent
object if the request was sucessfull, otherwise an empty list.
If you have access to a single details link and want to get some useful data from it, then find_by_details
might fit you needs.
The method takes the url as an argument and returns a single Container::Torrent
object.
Torrents.the_pirate_bay.find_by_details("http://thepiratebay.org/torrent/6173093/")
The class has some nice accessors that might be useful.
dead?
will be true.tid
method, also known as torrent id
is a truly unique identifier for all torrents. It is generated using a MD5 with the torrent domain and the id
method as a seed.tid
method.:english
. Read more about it here.Note: The seeders
, movie
, subtitle
, imdb_id
and ìmdb
method will do another request to the tracker, which means that it will take a bit longer to load then the other methods.
Here is an example
Torrents.torrentleech.cookies({
:member_id => "123",
:pass_hash => "value",
:PHPSESSID => "value"
}).results
All values you pass to cookies
must be of type string, like in the example above.
General note: The cookies you pass might be browser and IP-adress sensitive. Which means that it might only work in the current browser using the current Internet connection.
Torrentleech note: Remember to check the Remember Me checkbox before using your browsers cookies.
I decided in the beginning of the project to rescue parse errors during the runtime and instead print them as warnings.
The trackers parser, this one for example, isn't always returning the right data.
Due to the lack of useful CSS selectors on the given tracker. It returns 32 rows, the first and the last containing the header and the footer of the table. The unwanted results will be thrown away by the validator, but may raise errors during the run time. The easiest way to solve it was to just isolate the tracker, if it raised an error we return nil.
You can read errors in two ways.
Activate the debugger by adding the debug
method to your query. The errors will be printed as warnings in the console.
Torrents.the_pirate_bay.debug(true).results
Request a list of errors using the errors
method.
p Torrents.the_pirate_bay.errors
# => ["...undefined method `attr' for nil:NilClass>...", "32 torrents where found, 2 where not valid", "..."]
Here is how to access an implemented tracker. The first static method to apply is the name of the tracker in lower non camel cased letters.
The Pirate Bay becomes the_pirate_bay
, TTI becomes tti
and Torrentleech torrentleech
.
Here is an example.
Torrents.torrentleech.cookies({:my_cookie => "value"}).results
Take a look at the tests for all trackers to get to know more.
I'm about to write a wiki that describes how to add you own site. Until then, take a look at the parser for The Pirate Bay.
All heavy lifting has already been done, so adding another tracker should be quite easy.
I'm using Nokogiri to parse data from the site, which in most cases means that you don't have to mess with regular expressions.
Don't know Nokogiri? Take a look at this awesome screen cast by Ryan Bates.
You don't have to take care about exceptions, Torrents does that for you.
Before you use Torrents make sure you have permission from the tracker in question to use their data.
[sudo] gem install torrents
Add gem 'torrents'
to your Gemfile and run bundle
.
Torrents is tested in OS X 10.6.6 using Ruby 1.9.2.
Torrents is released under the MIT license.