torrentz 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +24 -0
- data/Rakefile +2 -0
- data/lib/torrentz.rb +30 -0
- data/lib/torrentz/fetch.rb +84 -0
- data/lib/torrentz/logger.rb +9 -0
- data/lib/torrentz/search.rb +35 -0
- data/lib/torrentz/version.rb +3 -0
- data/torrentz.gemspec +20 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Albert Llop
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Torrentz
|
2
|
+
|
3
|
+
Torrentz is a ruby gem that uses the powerful results from torrentz.eu to
|
4
|
+
provide magnet and torrent url's for a certain search query.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
To search:
|
9
|
+
|
10
|
+
results = Torrentz::Search.new('The Big Bang Theory S05E04 720p').get
|
11
|
+
results.size # => 10
|
12
|
+
results.first.name # => "The Big Bang Theory S05E04 720p HDTV x264 ORENJI"
|
13
|
+
results.first.url # => "http://torrentz.eu/deb2b19012810caa8d700c82506d3b9974fb42f9"
|
14
|
+
|
15
|
+
To get the actual magnet and torrent urls:
|
16
|
+
|
17
|
+
results = Torrentz.get('The Big Bang Theory S05E04 720p')
|
18
|
+
results[:magnet] # => "magnet:?xt=urn:btih:09bb45c848ddc7f2687c..."
|
19
|
+
results[:torrent] # => "http://www.vertor.com/index.php?mod=download..."
|
20
|
+
|
21
|
+
It will try to always return a magnet and a torrent, iterating from all the results
|
22
|
+
that torrentz.eu gives.
|
23
|
+
|
24
|
+
For now, magnets come from piratebay, and torrent files from vertor.
|
data/Rakefile
ADDED
data/lib/torrentz.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "torrentz/version"
|
2
|
+
require "rack"
|
3
|
+
require "nokogiri"
|
4
|
+
require "open-uri"
|
5
|
+
|
6
|
+
require 'torrentz/logger'
|
7
|
+
require 'torrentz/search'
|
8
|
+
require 'torrentz/fetch'
|
9
|
+
|
10
|
+
module Torrentz
|
11
|
+
class << self
|
12
|
+
include Torrentz::Logger
|
13
|
+
|
14
|
+
def get(query)
|
15
|
+
search_results = Search.new(query).get
|
16
|
+
logger.info "Found #{search_results.size} candidates"
|
17
|
+
|
18
|
+
return nil if search_results.empty?
|
19
|
+
|
20
|
+
results = {}
|
21
|
+
|
22
|
+
search_results.each do |search_result|
|
23
|
+
results.merge!(Fetch.new(search_result.url).get)
|
24
|
+
break if results[:torrent] && results[:magnet]
|
25
|
+
end
|
26
|
+
|
27
|
+
results
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Torrentz
|
2
|
+
class Fetch
|
3
|
+
include Torrentz::Logger
|
4
|
+
|
5
|
+
def initialize(url)
|
6
|
+
@url = url
|
7
|
+
end
|
8
|
+
|
9
|
+
def get
|
10
|
+
{
|
11
|
+
:magnet => get_magnet,
|
12
|
+
:torrent => get_torrent
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def get_torrent
|
19
|
+
candidate_urls.each do |candidate_url|
|
20
|
+
case candidate_url
|
21
|
+
when /vertor\.com/
|
22
|
+
logger.info "Found Vertor: #{candidate_url}"
|
23
|
+
return Vertor.new(candidate_url).get
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_magnet
|
31
|
+
candidate_urls.each do |candidate_url|
|
32
|
+
case candidate_url
|
33
|
+
when /thepiratebay/
|
34
|
+
logger.info "Found Piratebay!"
|
35
|
+
return PirateBay.new(candidate_url).get
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def torrentz_doc
|
43
|
+
@torrentz_doc ||= Nokogiri::HTML(open(@url))
|
44
|
+
end
|
45
|
+
|
46
|
+
def candidate_urls
|
47
|
+
@candidate_urls ||= begin
|
48
|
+
torrentz_doc.css("div.download a[rel=e]").map{|a| a["href"]}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Simple
|
53
|
+
include Torrentz::Logger
|
54
|
+
|
55
|
+
def initialize(url)
|
56
|
+
@url = url
|
57
|
+
end
|
58
|
+
|
59
|
+
def doc
|
60
|
+
@doc ||= Nokogiri::HTML(open(@url))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Currently returns magnet links only.
|
66
|
+
class PirateBay < Simple
|
67
|
+
def get
|
68
|
+
a = doc.css(".download a").first['href']
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Returns torrent urls only.
|
74
|
+
class Vertor < Simple
|
75
|
+
def get
|
76
|
+
candidate = doc.css('ul.down_but li.bt a').map do |a|
|
77
|
+
a['href']
|
78
|
+
end.find do |url|
|
79
|
+
url =~ /mod=download/
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Torrentz
|
2
|
+
class Search
|
3
|
+
include Rack::Utils
|
4
|
+
|
5
|
+
URL = "http://torrentz.eu/feed?q="
|
6
|
+
|
7
|
+
def initialize(query)
|
8
|
+
@url = URL + escape(query)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get
|
12
|
+
@urls ||= urls_from(@url)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Result
|
16
|
+
attr_reader :url, :name
|
17
|
+
|
18
|
+
def initialize(url, name)
|
19
|
+
@url, @name = url, name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def urls_from(url)
|
26
|
+
doc = Nokogiri::XML(open(url))
|
27
|
+
urls = doc.xpath('//rss/channel/item/guid').map(&:text)
|
28
|
+
names = doc.xpath('//rss/channel/item/title').map(&:text)
|
29
|
+
|
30
|
+
urls.zip(names).map do |url, name|
|
31
|
+
Result.new(url, name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/torrentz.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/torrentz/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Albert Llop"]
|
6
|
+
gem.email = ["mrsimo@gmail.com"]
|
7
|
+
gem.description = %q{torrentz.eu ruby client to search and download torrentz & magnets}
|
8
|
+
gem.summary = %q{torrentz.eu ruby client to search and download torrentz & magnets}
|
9
|
+
gem.homepage = "https://github.com/mrsimo/ruby-torrentz"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "torrentz"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Torrentz::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "rack"
|
19
|
+
gem.add_dependency "nokogiri"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torrentz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Albert Llop
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70201271885300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70201271885300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nokogiri
|
27
|
+
requirement: &70201271884500 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70201271884500
|
36
|
+
description: torrentz.eu ruby client to search and download torrentz & magnets
|
37
|
+
email:
|
38
|
+
- mrsimo@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/torrentz.rb
|
49
|
+
- lib/torrentz/fetch.rb
|
50
|
+
- lib/torrentz/logger.rb
|
51
|
+
- lib/torrentz/search.rb
|
52
|
+
- lib/torrentz/version.rb
|
53
|
+
- torrentz.gemspec
|
54
|
+
homepage: https://github.com/mrsimo/ruby-torrentz
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.10
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: torrentz.eu ruby client to search and download torrentz & magnets
|
78
|
+
test_files: []
|