the_pirate_bay 0.0.8.1 → 0.0.9
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/lib/the_pirate_bay/torrent.rb +24 -24
- data/lib/the_pirate_bay/version.rb +1 -1
- data/spec/the_pirate_bay/torrent_spec.rb +8 -8
- metadata +2 -2
@@ -1,10 +1,10 @@
|
|
1
1
|
module ThePirateBay
|
2
2
|
class Torrent < API
|
3
3
|
include Model
|
4
|
-
|
4
|
+
|
5
5
|
ATTRS_MAP = {
|
6
|
-
:name => "Title",
|
7
|
-
:description => "Description",
|
6
|
+
:name => "Title",
|
7
|
+
:description => "Description",
|
8
8
|
:seeders => "Seeders",
|
9
9
|
:leechers => "Leechers",
|
10
10
|
:quality => "Quality",
|
@@ -20,21 +20,21 @@ module ThePirateBay
|
|
20
20
|
:tags => "Tag(s)",
|
21
21
|
:imdb_id => "Info"
|
22
22
|
}.freeze
|
23
|
-
|
23
|
+
|
24
24
|
ATTRS = [:id, :magnet_uri, *ATTRS_MAP.keys].freeze
|
25
25
|
SKIP_ATTRS = [:hash, :imdb_id].freeze
|
26
|
-
|
26
|
+
|
27
27
|
# Torrent attributes:
|
28
28
|
# id, name, magnet_uri, description, seeders, leechers, quality, size, type, hash,
|
29
29
|
# uploaded_at, uploaded_by, comments_count, files_count, spoken_language, written_language, tags, imdb_id
|
30
|
-
|
30
|
+
|
31
31
|
attr_accessor *ATTRS, :comments, :uploader, :html
|
32
32
|
|
33
33
|
class << self
|
34
|
-
|
34
|
+
|
35
35
|
# Public: Search for a torrent.
|
36
36
|
#
|
37
|
-
# Send your query as the only parameter,
|
37
|
+
# Send your query as the only parameter,
|
38
38
|
# just like you would in ThePirateBay.se
|
39
39
|
#
|
40
40
|
# query - A string of keywords to search for.
|
@@ -46,7 +46,7 @@ module ThePirateBay
|
|
46
46
|
#
|
47
47
|
# Returns an array of ThePirateBay::Torrent::Collection objects.
|
48
48
|
def search(query)
|
49
|
-
html = request("search
|
49
|
+
html = request("search/#{query}") # Returns search html
|
50
50
|
|
51
51
|
# Get torrents table rows from html
|
52
52
|
# and return as ruby objects
|
@@ -54,7 +54,7 @@ module ThePirateBay
|
|
54
54
|
Torrent::Collection.new(torrent_html)
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
# Public: Find a torrent by ID.
|
59
59
|
#
|
60
60
|
# Retrieve torrent information from ThePirateBay.se/torrent/:id
|
@@ -69,27 +69,27 @@ module ThePirateBay
|
|
69
69
|
# Returns an instance of ThePirateBay::Torrent
|
70
70
|
def find(id)
|
71
71
|
html = request("torrent/#{id}") # Returns torrent html
|
72
|
-
|
72
|
+
|
73
73
|
# Initialize Torrent from html
|
74
74
|
new(id, html)
|
75
75
|
end
|
76
76
|
alias :get :find
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def initialize(id, html)
|
80
80
|
# Save html doc to get special attributes
|
81
81
|
@id, @html = id, html
|
82
|
-
|
82
|
+
|
83
83
|
# Get attributes and values html lists
|
84
84
|
attrs = html.css("#details dt").map(&:text).map { |a| a.gsub(":", "") }
|
85
85
|
values = html.css("#details dd").map(&:text)
|
86
|
-
|
86
|
+
|
87
87
|
# Set instance attributes
|
88
88
|
set_attributes(attrs, values)
|
89
|
-
|
89
|
+
|
90
90
|
return self
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
# Set torrent attributes from html lists
|
94
94
|
def set_attributes(attrs, values)
|
95
95
|
attrs.zip(values).each do |dirty_attr, value|
|
@@ -104,7 +104,7 @@ module ThePirateBay
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
def name
|
109
109
|
@name ||= html.css("div#title").text.sanitize!
|
110
110
|
end
|
@@ -116,24 +116,24 @@ module ThePirateBay
|
|
116
116
|
def hash
|
117
117
|
@hash ||= html.css("#details dd")[-1].next.text.strip
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def description
|
121
121
|
@description ||= html.css("div.nfo").text.strip
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
private
|
125
|
-
|
125
|
+
|
126
126
|
def attributes_map
|
127
127
|
ATTRS_MAP
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def class_attributes
|
131
131
|
ATTRS
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
def skip_attributes
|
135
135
|
SKIP_ATTRS
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
end # Torrent
|
139
|
-
end # ThePirateBay
|
139
|
+
end # ThePirateBay
|
@@ -2,27 +2,27 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ThePirateBay::Torrent do
|
4
4
|
let(:api) { ThePirateBay.new }
|
5
|
-
|
5
|
+
|
6
6
|
context ".search" do
|
7
|
-
before
|
8
|
-
stub_get("search
|
7
|
+
before do
|
8
|
+
stub_get("search/Fringe").
|
9
9
|
to_return(:status => 200, :body => fixture("torrent/search.html"))
|
10
10
|
@torrents = api.torrents.search("Fringe")
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "returns torrents results" do
|
14
14
|
@torrents.class.should == Array
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "instantiates torrents collection objects" do
|
18
18
|
@torrents.first.class.should == ThePirateBay::Torrent::Collection
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "assigns torrents attributes" do
|
22
22
|
@torrents.first.id.should == "7810640"
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
context ".find" do
|
27
27
|
it "returns a particular torrent" do
|
28
28
|
stub_get("torrent/7723168").
|
@@ -31,4 +31,4 @@ describe ThePirateBay::Torrent do
|
|
31
31
|
torrent.name.should == "Fringe S05E03 HDTV x264-LOL [eztv]"
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_pirate_bay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|