pirata 0.1.5 → 0.2.0
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.
- checksums.yaml +5 -13
- data/lib/pirata/config.rb +12 -5
- data/lib/pirata/search.rb +27 -24
- data/lib/pirata/torrent.rb +32 -27
- data/lib/pirata/user.rb +7 -7
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OTY5YzNhZTU2ODU0OTZmZWM3ODQyYjk1NzhlMjRhMzA5MjI5OTdhYw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1560be96fd8d128cca19f40579ee6e32d4cf545a
|
4
|
+
data.tar.gz: 6625a8d7d1974015049313e0c6cf9f5de99d6706
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OTFiZjUyNzhkM2NhMmY1MGEzM2Y0OTc3Y2MyMDdiNzk0NGY3NmMwMGM0Mzcw
|
11
|
-
OGNlMmQyMWE5MTkwNjA2ZDYwNDMwN2ExMzEzZjA2YzhmZDY3ODU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YjMxZjYzZDAyMDcxNjUyYzQ3ODFlNDEzNmNlNmNiNzVlMzM3OTdhYzI0MjVl
|
14
|
-
ZDUyOTQ5MDU3MWY3ZmEzYTcyZjg4ZGU1OGRmZjM4Y2M3OWI0NzUxNzliODk2
|
15
|
-
MjFjZTRkYzVhYTA4MmYzMGQ1NTZmOWRkZTcyODU1ZWE1YzVkZDY=
|
6
|
+
metadata.gz: 7810208447957abe600a601183d08475f4a58a1969cfeadf9bd846345f1349b130ffa9dd702bfa651187b35364f41ca4297e2a87f7401ef33101573cf69e76ca
|
7
|
+
data.tar.gz: 9621488683654876273b67761aeb2e255b0ad846a5b2b3129a80f0319abe1aae83032fd00cfc272acb4639f2ae46e668abc856c9de0b59527f70001eb019948d
|
data/lib/pirata/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Pirata
|
2
2
|
module Config
|
3
|
-
|
3
|
+
|
4
4
|
# This is the base URL to query against. Depending on server/mirror
|
5
5
|
# availability, blocked URLs, etc, you may need to change this. A
|
6
6
|
# list of available mirrors for ThePirateBay may be found at
|
@@ -9,8 +9,15 @@ module Pirata
|
|
9
9
|
# Note that all URLs should yeild the same results. You are advised
|
10
10
|
# to pick a mirror that is closest to your application server for best
|
11
11
|
# results though.
|
12
|
-
|
13
|
-
BASE_URL = "http://thepiratebay.
|
14
|
-
|
12
|
+
|
13
|
+
BASE_URL = "http://thepiratebay.mn"
|
14
|
+
|
15
|
+
# This is the rule used when following HTTPS <-> HTTP redirects.
|
16
|
+
# It accepts :all and :safe
|
17
|
+
# :safe will allow HTTP -> HTTPS redirections
|
18
|
+
# :all will allow both HTTP -> HTTPS redirections as well as HTTPS -> HTTP
|
19
|
+
|
20
|
+
REDIRECT = :all
|
21
|
+
|
15
22
|
end
|
16
|
-
end
|
23
|
+
end
|
data/lib/pirata/search.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
+
require 'open_uri_redirections'
|
2
3
|
require 'open-uri'
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
4
|
+
require 'pirata/config'
|
5
|
+
require 'pirata/torrent'
|
6
|
+
require 'pirata/user'
|
7
|
+
require 'pirata/category'
|
8
|
+
require 'pirata/sort'
|
8
9
|
|
9
10
|
module Pirata
|
10
11
|
class Search
|
11
|
-
|
12
|
+
|
12
13
|
attr_accessor :results, :pages
|
13
14
|
attr_reader :category, :sort_type, :query
|
14
|
-
|
15
|
+
|
15
16
|
def initialize(query, sort_type = Pirata::Sort::RELEVANCE, categories = ["0"])
|
16
17
|
@sort_type = sort_type
|
17
18
|
@category = categories.join(',')
|
@@ -19,58 +20,60 @@ module Pirata
|
|
19
20
|
@query = query
|
20
21
|
@results = search()
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
# Perform a search and return an array of Torrent objects
|
24
25
|
def search(page = 0)
|
25
26
|
#build URL ex: http://thepiratebay.se/search/cats/0/99/0
|
26
27
|
url = Pirata::Config::BASE_URL + "/search/#{URI.escape(@query)}" + "/#{page.to_s}" + "/#{@sort_type}" + "/#{@category}"
|
27
|
-
html = Nokogiri::HTML(open(url))
|
28
|
+
html = Nokogiri::HTML(open(url, :allow_redirections => Pirata::Config::REDIRECT))
|
28
29
|
Pirata::Search::parse_search_page(html, self)
|
29
30
|
end
|
30
|
-
|
31
|
+
|
31
32
|
# Return the n page results of a search, assuming it is multipage
|
32
33
|
def search_page(page)
|
33
34
|
raise "Search must be multipage to search pages" if !multipage?
|
34
35
|
raise "Page must be a valid, positive integer" if page.class != Fixnum || page < 0
|
35
36
|
raise "Invalid page range" if page > @pages
|
36
|
-
|
37
|
+
|
37
38
|
self.search(page)
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
# Return the n most recent torrents from a category
|
41
42
|
# Searches all categories if none supplied
|
42
43
|
def self.top(category = "all")
|
43
|
-
|
44
|
+
url = Pirata::Config::BASE_URL + '/top/' + URI.escape(category)
|
45
|
+
html = Nokogiri::HTML(open(url, :allow_redirections => Pirata::Config::REDIRECT))
|
44
46
|
Pirata::Search::parse_search_page(html)
|
45
47
|
end
|
46
|
-
|
48
|
+
|
47
49
|
# Return an array of the 30 most recent Torrents
|
48
50
|
def self.recent
|
49
|
-
|
51
|
+
url = Pirata::Config::BASE_URL + '/recent'
|
52
|
+
html = Nokogiri::HTML(open(url, :allow_redirections => Pirata::Config::REDIRECT))
|
50
53
|
Pirata::Search::parse_search_page(html)
|
51
54
|
end
|
52
|
-
|
55
|
+
|
53
56
|
def multipage?
|
54
57
|
@pages > 0
|
55
58
|
end
|
56
|
-
|
59
|
+
|
57
60
|
private #---------------------------------------------
|
58
|
-
|
61
|
+
|
59
62
|
# From a results table, collect and build all Torrents
|
60
63
|
# into an array
|
61
64
|
def self.parse_search_page(html, search_object = nil)
|
62
65
|
results = []
|
63
|
-
|
64
|
-
begin
|
66
|
+
|
67
|
+
begin
|
65
68
|
search_object.pages = html.css('#content div a')[-2].text.to_i
|
66
69
|
rescue
|
67
|
-
end
|
68
|
-
|
70
|
+
end
|
71
|
+
|
69
72
|
html.css('#searchResult tr').each do |row|
|
70
73
|
title = row.search('.detLink').text
|
71
74
|
next if title == ''
|
72
75
|
h = {}
|
73
|
-
|
76
|
+
|
74
77
|
begin
|
75
78
|
h[:title] = title
|
76
79
|
h[:category] = row.search('td a')[0].text
|
@@ -88,6 +91,6 @@ module Pirata
|
|
88
91
|
end
|
89
92
|
results
|
90
93
|
end
|
91
|
-
|
94
|
+
|
92
95
|
end
|
93
96
|
end
|
data/lib/pirata/torrent.rb
CHANGED
@@ -1,118 +1,123 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'open-uri'
|
3
|
+
require 'open_uri_redirections'
|
3
4
|
require 'time'
|
4
|
-
require 'config'
|
5
|
+
require 'pirata/config'
|
5
6
|
|
6
7
|
module Pirata
|
7
8
|
class Torrent
|
8
9
|
|
10
|
+
attr_reader :title
|
11
|
+
|
9
12
|
def initialize(params_hash)
|
10
13
|
@params = params_hash
|
14
|
+
@title = params_hash[:title]
|
11
15
|
end
|
12
|
-
|
13
|
-
def title
|
14
|
-
|
15
|
-
end
|
16
|
-
|
16
|
+
|
17
|
+
# def title
|
18
|
+
# @params[:title]
|
19
|
+
# end
|
20
|
+
|
17
21
|
def category
|
18
22
|
@params[:category]
|
19
23
|
end
|
20
|
-
|
24
|
+
|
21
25
|
def title
|
22
26
|
@params[:title]
|
23
27
|
end
|
24
|
-
|
28
|
+
|
25
29
|
def url
|
26
30
|
@params[:url]
|
27
31
|
end
|
28
|
-
|
32
|
+
|
29
33
|
def id
|
30
34
|
@params[:id]
|
31
35
|
end
|
32
|
-
|
36
|
+
|
33
37
|
def magnet
|
34
38
|
unless @params[:magnet]
|
35
39
|
update_params
|
36
40
|
end
|
37
41
|
@params[:magnet]
|
38
42
|
end
|
39
|
-
|
43
|
+
|
40
44
|
def seeders
|
41
45
|
unless @params[:seeders]
|
42
46
|
update_params
|
43
47
|
end
|
44
48
|
@params[:seeders]
|
45
49
|
end
|
46
|
-
|
50
|
+
|
47
51
|
def leechers
|
48
52
|
unless @params[:leechers]
|
49
53
|
update_params
|
50
54
|
end
|
51
55
|
@params[:leechers]
|
52
56
|
end
|
53
|
-
|
57
|
+
|
54
58
|
def uploader
|
55
59
|
unless @params[:uploader]
|
56
60
|
update_params
|
57
61
|
end
|
58
62
|
@params[:uploader]
|
59
63
|
end
|
60
|
-
|
64
|
+
|
61
65
|
def files
|
62
66
|
unless @params[:files]
|
63
67
|
update_params
|
64
68
|
end
|
65
69
|
@params[:files]
|
66
70
|
end
|
67
|
-
|
71
|
+
|
68
72
|
def size
|
69
73
|
unless @params[:size]
|
70
74
|
update_params
|
71
75
|
end
|
72
76
|
@params[:size]
|
73
77
|
end
|
74
|
-
|
78
|
+
|
75
79
|
def date
|
76
80
|
unless @params[:date]
|
77
81
|
update_params
|
78
82
|
end
|
79
83
|
@params[:date]
|
80
84
|
end
|
81
|
-
|
85
|
+
|
82
86
|
def comments
|
83
87
|
unless @params[:comments]
|
84
88
|
update_params
|
85
89
|
end
|
86
90
|
@params[:comments]
|
87
91
|
end
|
88
|
-
|
92
|
+
|
89
93
|
def hash
|
90
94
|
unless @params[:hash]
|
91
95
|
update_params
|
92
96
|
end
|
93
97
|
@params[:hash]
|
94
98
|
end
|
95
|
-
|
99
|
+
|
96
100
|
# Return a Torrent object from a corresponding ID
|
97
101
|
def self.find_by_id(id)
|
98
102
|
raise "Invalid torrent ID format. Must be an integer" if id.class != Fixnum
|
99
|
-
|
103
|
+
url = Pirata::Config::BASE_URL + "/torrent" + "/#{URI.escape(id.to_s)}"
|
104
|
+
html = Nokogiri::HTML(open(url, :allow_redirections => Pirata::Config::REDIRECT))
|
100
105
|
results_hash = parse_torrent_page(html)
|
101
106
|
Pirata::Torrent.new(results_hash)
|
102
107
|
end
|
103
|
-
|
108
|
+
|
104
109
|
def update_params
|
105
|
-
html = Nokogiri::HTML(open(@params[:url]))
|
110
|
+
html = Nokogiri::HTML(open(@params[:url], :allow_redirections => Pirata::Config::REDIRECT))
|
106
111
|
updated_params = Pirata::Torrent.parse_torrent_page(html)
|
107
112
|
@params.merge!(updated_params)
|
108
113
|
end
|
109
|
-
|
114
|
+
|
110
115
|
private #-------------------------------------------------
|
111
|
-
|
116
|
+
|
112
117
|
def self.parse_torrent_page(html)
|
113
118
|
if html.css("#err").text.include?("404")
|
114
119
|
raise "No torrent for supplied ID found"
|
115
|
-
else
|
120
|
+
else
|
116
121
|
row = html.css('#detailsframe').first
|
117
122
|
h = {
|
118
123
|
:title => row.search('#title')[0].text.strip,
|
@@ -130,6 +135,6 @@ module Pirata
|
|
130
135
|
end
|
131
136
|
nil
|
132
137
|
end
|
133
|
-
|
138
|
+
|
134
139
|
end
|
135
|
-
end
|
140
|
+
end
|
data/lib/pirata/user.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'config'
|
1
|
+
require 'pirata/config'
|
2
2
|
|
3
3
|
module Pirata
|
4
4
|
class User
|
5
|
-
|
5
|
+
|
6
6
|
attr_reader :profile_url, :username
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(username)
|
9
9
|
@username = username
|
10
|
-
@profile_url = "#{Pirata::Config::BASE_URL}/user/#{@username}"
|
10
|
+
@profile_url = "#{Pirata::Config::BASE_URL}/user/#{@username}"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def to_s
|
14
|
-
@username
|
14
|
+
@username
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pirata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Lindsay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: open_uri_redirections
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
27
41
|
description: A Ruby gem that exposes an API for using The Pirate Bay torrent tracker
|
28
42
|
service.
|
29
43
|
email: clindsay107@gmail.com
|
@@ -49,17 +63,17 @@ require_paths:
|
|
49
63
|
- lib/pirata
|
50
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
70
|
requirements:
|
57
|
-
- -
|
71
|
+
- - ">="
|
58
72
|
- !ruby/object:Gem::Version
|
59
73
|
version: '0'
|
60
74
|
requirements: []
|
61
75
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.4.6
|
63
77
|
signing_key:
|
64
78
|
specification_version: 4
|
65
79
|
summary: Pirata - a Ruby API for The Pirate Bay
|