torrent_api 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -1
- data/Manifest +2 -0
- data/Rakefile +2 -2
- data/lib/pirate_bay/base.rb +23 -0
- data/lib/pirate_bay/details.rb +98 -0
- data/lib/pirate_bay/result.rb +2 -2
- data/lib/torrent_api.rb +1 -1
- data/torrent_api.gemspec +11 -12
- metadata +40 -59
data/CHANGELOG
CHANGED
@@ -4,4 +4,5 @@
|
|
4
4
|
v0.0.9 Migrated from tpb to torrent_api (now includes torrent_reactor and demonoid as searches)
|
5
5
|
v0.1.0 Fixed Demonoid. Stable performance on :all and :demonoid.
|
6
6
|
v0.1.1 Fixed Demonoid torrent links to be absolute, not relative.
|
7
|
-
v0.1.2 Fixed PirateBay filesizes to be in bytes.
|
7
|
+
v0.1.2 Fixed PirateBay filesizes to be in bytes.
|
8
|
+
v0.2.0 Added some PirateBay analysis methods for comments and their video/audio ratings. Specs begin.
|
data/Manifest
CHANGED
@@ -7,9 +7,11 @@ lib/demonoid/result.rb
|
|
7
7
|
lib/demonoid/result_set.rb
|
8
8
|
lib/pirate_bay/base.rb
|
9
9
|
lib/pirate_bay/categories.rb
|
10
|
+
lib/pirate_bay/details.rb
|
10
11
|
lib/pirate_bay/result.rb
|
11
12
|
lib/pirate_bay/result_set.rb
|
12
13
|
lib/torrent_api.rb
|
13
14
|
lib/torrent_reactor/base.rb
|
14
15
|
lib/torrent_reactor/result.rb
|
15
16
|
lib/torrent_reactor/result_set.rb
|
17
|
+
torrent_api.gemspec
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'echoe'
|
2
|
-
Echoe.new('torrent_api', '0.
|
2
|
+
Echoe.new('torrent_api', '0.2.0') do |p|
|
3
3
|
p.description = "An API to query popular torrent websites"
|
4
4
|
p.url = "http://www.github.com/hjhart/torrent_api"
|
5
5
|
p.author = "James Hart"
|
6
6
|
p.email = "hjhart@gmail.com"
|
7
|
-
p.ignore_pattern = ["tmp/**/*", "scripts/*"]
|
7
|
+
p.ignore_pattern = ["tmp/**/*", "scripts/*", "spec/**/*", "Gemfile*"]
|
8
8
|
p.development_dependencies = ['nokogiri', 'hpricot']
|
9
9
|
end
|
10
10
|
|
data/lib/pirate_bay/base.rb
CHANGED
@@ -39,6 +39,29 @@ module PirateBay
|
|
39
39
|
def cached_filename
|
40
40
|
File.join("tmp", "searches", "#{search_string}_#{category_id}_#{page}.html")
|
41
41
|
end
|
42
|
+
|
43
|
+
def get_quality
|
44
|
+
execute
|
45
|
+
results = @results.map do |result|
|
46
|
+
url = "http://www.thepiratebay.org/torrent/#{result.id}/"
|
47
|
+
html = open(url).read
|
48
|
+
p = PirateBay::Details.new html, :init
|
49
|
+
puts "Fetching results"
|
50
|
+
result = {
|
51
|
+
:seeds => result.seeds,
|
52
|
+
:size => result.size,
|
53
|
+
:name => result.name,
|
54
|
+
:video => p.video_quality_average,
|
55
|
+
:audio => p.audio_quality_average,
|
56
|
+
:url => url
|
57
|
+
}
|
58
|
+
puts "Results: #{result}"
|
59
|
+
result
|
60
|
+
end
|
61
|
+
|
62
|
+
results.reject { |a| a[:video].nan? }.sort_by { |a| a[:video] }
|
63
|
+
end
|
64
|
+
|
42
65
|
|
43
66
|
def fetch_search_results
|
44
67
|
url = "http://thepiratebay.org/search/#{search_string}/#{page}/7/#{category_id}" # highest seeded first
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
module PirateBay
|
4
|
+
class Details
|
5
|
+
def to_s
|
6
|
+
"#<PirateBay::Details: @id=#{@id}>"
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(html, type = :full)
|
10
|
+
@details_page_html = html
|
11
|
+
id_matches = html.match Regexp.new '<input type="hidden" name="id" value="(.*)"/>' rescue nil
|
12
|
+
@id = id_matches[1].to_i unless id_matches.nil?
|
13
|
+
@comment_pages_html = []
|
14
|
+
@scores = []
|
15
|
+
@type = type
|
16
|
+
end
|
17
|
+
|
18
|
+
def fetch_comments(params)
|
19
|
+
index = params[:page] - 1
|
20
|
+
if @comment_pages_html[index].nil?
|
21
|
+
uri = URI.parse('http://thepiratebay.org/ajax_details_comments.php')
|
22
|
+
res = Net::HTTP.post_form(uri, params)
|
23
|
+
response = res.body
|
24
|
+
@comment_pages_html[index] = response
|
25
|
+
end
|
26
|
+
@comment_pages_html[index]
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch_all_comments
|
30
|
+
comment_xhr_params.each do |params|
|
31
|
+
puts " fetching comments for #{params[:page]} of #{params[:pages]}"
|
32
|
+
fetch_comments params
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def scores
|
37
|
+
if @type == :full
|
38
|
+
fetch_all_comments if @comment_pages_html.empty?
|
39
|
+
full_html = @comment_pages_html.inject("") { |html, memo| memo += html }
|
40
|
+
document = Nokogiri::HTML(full_html)
|
41
|
+
else
|
42
|
+
document = Nokogiri::HTML(@details_page_html)
|
43
|
+
end
|
44
|
+
|
45
|
+
scores = document.css('div.comment').map { |comment|
|
46
|
+
PirateBay::Details.search_for_ratings(comment.inner_html)
|
47
|
+
}
|
48
|
+
@scores = scores.reject { |r| r.empty? }
|
49
|
+
end
|
50
|
+
|
51
|
+
def comment_xhr_params
|
52
|
+
document = Nokogiri::HTML(@details_page_html)
|
53
|
+
comment_link = document.css('div.browse-coms a').first
|
54
|
+
if comment_link.nil?
|
55
|
+
[{ page: 1, pages: 1, crc: "9b235c98e242f2617ae61dc416ec0de7", id: @id }]
|
56
|
+
else
|
57
|
+
params = PirateBay::Details.extract_xhr_params comment_link.attr('onclick')
|
58
|
+
results = Array.new(params[:pages]) { |i| i+1 }
|
59
|
+
results.map do |i|
|
60
|
+
{ page: i, pages: params[:pages], crc: params[:crc], id: params[:id] }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.extract_xhr_params(string)
|
67
|
+
page, pages, crc, id = /comPage\((\d+),(\d+),'(.+)', '(.+)'\);/.match(string).captures
|
68
|
+
page = page.to_i
|
69
|
+
pages = pages.to_i
|
70
|
+
{ page: page, pages: pages, crc: crc, id: id }
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def self.search_for_ratings string
|
75
|
+
video_score_matches = string.match(/(v|video) ?[:\=-]? ?([0-9]\.[0-9]|[0-9]{1,2})/i)
|
76
|
+
audio_score_matches = string.match(/(a|audio) ?[:\=-]? ?([0-9]\.[0-9]|[0-9]{1,2})/i)
|
77
|
+
ratings = {}
|
78
|
+
ratings[:v] = video_score_matches[2].to_f unless video_score_matches.nil?
|
79
|
+
ratings[:a] = audio_score_matches[2].to_f unless audio_score_matches.nil?
|
80
|
+
ratings.delete(:v) if ratings[:v] && ratings[:v] > 10
|
81
|
+
ratings.delete(:a) if ratings[:a] && ratings[:a] > 10
|
82
|
+
# puts "Incoming string of #{string} detected ratings of #{ratings}"
|
83
|
+
ratings
|
84
|
+
end
|
85
|
+
|
86
|
+
def video_quality_average
|
87
|
+
video_scores = scores.map { |score| score[:v] }.compact
|
88
|
+
sum_of_video_scores = video_scores.inject(0) { |score, memo| memo += score }
|
89
|
+
sum_of_video_scores / video_scores.size.to_f
|
90
|
+
end
|
91
|
+
|
92
|
+
def audio_quality_average
|
93
|
+
audio_scores = scores.map { |score| score[:a] }.compact
|
94
|
+
sum_of_audio_scores = audio_scores.inject(0) { |score, memo| memo += score }
|
95
|
+
sum_of_audio_scores / audio_scores.size.to_f
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/pirate_bay/result.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module PirateBay
|
2
2
|
class Result
|
3
|
-
attr_accessor :name, :seeds, :leeches, :category, :link, :magnet_link, :status, :size
|
3
|
+
attr_accessor :id, :name, :seeds, :leeches, :category, :link, :magnet_link, :status, :size
|
4
4
|
|
5
5
|
def initialize(row = nil)
|
6
6
|
if row.css("td")[1].css("img[alt='Trusted']").size > 0
|
@@ -18,7 +18,7 @@ module PirateBay
|
|
18
18
|
magnet_link = nil
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
self.id = row.inner_html.match(/torrent\/([\d]+)\//)[1]
|
22
22
|
self.name = row.css(".detName").first.content
|
23
23
|
self.seeds = row.css("td")[2].content.to_i
|
24
24
|
self.leeches = row.css("td")[3].content.to_i
|
data/lib/torrent_api.rb
CHANGED
@@ -10,7 +10,7 @@ require 'uri'
|
|
10
10
|
%w(result base result_set).each do |filename|
|
11
11
|
require File.join(File.dirname(__FILE__), 'torrent_reactor', filename)
|
12
12
|
end
|
13
|
-
%w(result base categories result_set).each do |filename|
|
13
|
+
%w(result base categories details result_set).each do |filename|
|
14
14
|
require File.join(File.dirname(__FILE__), 'pirate_bay', filename)
|
15
15
|
end
|
16
16
|
%w(result base result_set).each do |filename|
|
data/torrent_api.gemspec
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.
|
4
|
+
s.name = "torrent_api"
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["James Hart"]
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "README.markdown", "lib/demonoid/base.rb", "lib/demonoid/result.rb", "lib/demonoid/result_set.rb", "lib/pirate_bay/base.rb", "lib/pirate_bay/categories.rb", "lib/pirate_bay/result.rb", "lib/pirate_bay/result_set.rb", "lib/torrent_api.rb", "lib/torrent_reactor/base.rb", "lib/torrent_reactor/result.rb", "lib/torrent_reactor/result_set.rb"]
|
13
|
-
s.files = ["CHANGELOG", "Manifest", "README.markdown", "Rakefile", "lib/demonoid/base.rb", "lib/demonoid/result.rb", "lib/demonoid/result_set.rb", "lib/pirate_bay/base.rb", "lib/pirate_bay/categories.rb", "lib/pirate_bay/result.rb", "lib/pirate_bay/result_set.rb", "lib/torrent_api.rb", "lib/torrent_reactor/base.rb", "lib/torrent_reactor/result.rb", "lib/torrent_reactor/result_set.rb", "torrent_api.gemspec"]
|
14
|
-
s.homepage =
|
9
|
+
s.date = "2011-11-12"
|
10
|
+
s.description = "An API to query popular torrent websites"
|
11
|
+
s.email = "hjhart@gmail.com"
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "README.markdown", "lib/demonoid/base.rb", "lib/demonoid/result.rb", "lib/demonoid/result_set.rb", "lib/pirate_bay/base.rb", "lib/pirate_bay/categories.rb", "lib/pirate_bay/details.rb", "lib/pirate_bay/result.rb", "lib/pirate_bay/result_set.rb", "lib/torrent_api.rb", "lib/torrent_reactor/base.rb", "lib/torrent_reactor/result.rb", "lib/torrent_reactor/result_set.rb"]
|
13
|
+
s.files = ["CHANGELOG", "Manifest", "README.markdown", "Rakefile", "lib/demonoid/base.rb", "lib/demonoid/result.rb", "lib/demonoid/result_set.rb", "lib/pirate_bay/base.rb", "lib/pirate_bay/categories.rb", "lib/pirate_bay/details.rb", "lib/pirate_bay/result.rb", "lib/pirate_bay/result_set.rb", "lib/torrent_api.rb", "lib/torrent_reactor/base.rb", "lib/torrent_reactor/result.rb", "lib/torrent_reactor/result_set.rb", "torrent_api.gemspec"]
|
14
|
+
s.homepage = "http://www.github.com/hjhart/torrent_api"
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Torrent_api", "--main", "README.markdown"]
|
16
16
|
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project =
|
18
|
-
s.rubygems_version =
|
19
|
-
s.summary =
|
17
|
+
s.rubyforge_project = "torrent_api"
|
18
|
+
s.rubygems_version = "1.8.10"
|
19
|
+
s.summary = "An API to query popular torrent websites"
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
22
|
s.specification_version = 3
|
24
23
|
|
25
24
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
metadata
CHANGED
@@ -1,55 +1,43 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: torrent_api
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
version: 0.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- James Hart
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: nokogiri
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2153796560 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
31
22
|
type: :development
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: hpricot
|
35
23
|
prerelease: false
|
36
|
-
|
24
|
+
version_requirements: *2153796560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hpricot
|
27
|
+
requirement: &2153795880 !ruby/object:Gem::Requirement
|
37
28
|
none: false
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
- 0
|
43
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
44
33
|
type: :development
|
45
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153795880
|
46
36
|
description: An API to query popular torrent websites
|
47
37
|
email: hjhart@gmail.com
|
48
38
|
executables: []
|
49
|
-
|
50
39
|
extensions: []
|
51
|
-
|
52
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
53
41
|
- CHANGELOG
|
54
42
|
- README.markdown
|
55
43
|
- lib/demonoid/base.rb
|
@@ -57,13 +45,14 @@ extra_rdoc_files:
|
|
57
45
|
- lib/demonoid/result_set.rb
|
58
46
|
- lib/pirate_bay/base.rb
|
59
47
|
- lib/pirate_bay/categories.rb
|
48
|
+
- lib/pirate_bay/details.rb
|
60
49
|
- lib/pirate_bay/result.rb
|
61
50
|
- lib/pirate_bay/result_set.rb
|
62
51
|
- lib/torrent_api.rb
|
63
52
|
- lib/torrent_reactor/base.rb
|
64
53
|
- lib/torrent_reactor/result.rb
|
65
54
|
- lib/torrent_reactor/result_set.rb
|
66
|
-
files:
|
55
|
+
files:
|
67
56
|
- CHANGELOG
|
68
57
|
- Manifest
|
69
58
|
- README.markdown
|
@@ -73,6 +62,7 @@ files:
|
|
73
62
|
- lib/demonoid/result_set.rb
|
74
63
|
- lib/pirate_bay/base.rb
|
75
64
|
- lib/pirate_bay/categories.rb
|
65
|
+
- lib/pirate_bay/details.rb
|
76
66
|
- lib/pirate_bay/result.rb
|
77
67
|
- lib/pirate_bay/result_set.rb
|
78
68
|
- lib/torrent_api.rb
|
@@ -80,43 +70,34 @@ files:
|
|
80
70
|
- lib/torrent_reactor/result.rb
|
81
71
|
- lib/torrent_reactor/result_set.rb
|
82
72
|
- torrent_api.gemspec
|
83
|
-
has_rdoc: true
|
84
73
|
homepage: http://www.github.com/hjhart/torrent_api
|
85
74
|
licenses: []
|
86
|
-
|
87
75
|
post_install_message:
|
88
|
-
rdoc_options:
|
76
|
+
rdoc_options:
|
89
77
|
- --line-numbers
|
90
78
|
- --inline-source
|
91
79
|
- --title
|
92
80
|
- Torrent_api
|
93
81
|
- --main
|
94
82
|
- README.markdown
|
95
|
-
require_paths:
|
83
|
+
require_paths:
|
96
84
|
- lib
|
97
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
86
|
none: false
|
99
|
-
requirements:
|
100
|
-
- -
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
|
103
|
-
|
104
|
-
version: "0"
|
105
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
92
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
- 1
|
112
|
-
- 2
|
113
|
-
version: "1.2"
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.2'
|
114
97
|
requirements: []
|
115
|
-
|
116
98
|
rubyforge_project: torrent_api
|
117
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.8.10
|
118
100
|
signing_key:
|
119
101
|
specification_version: 3
|
120
102
|
summary: An API to query popular torrent websites
|
121
103
|
test_files: []
|
122
|
-
|