hail_hydra 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6f53bbe774e5705064031d66a2983d112fcf4454
4
- data.tar.gz: c044b92d1548395ec1c85d5a2108d7ef647ed0f8
2
+ SHA256:
3
+ metadata.gz: 04c83ffc08ca929f1f599298dab744399f0f3944394a2d5c9d4abb491d270acb
4
+ data.tar.gz: ae11202df9131ed6fb05af82a729f94e3c2c812e4c7969390aee58ef9000f98d
5
5
  SHA512:
6
- metadata.gz: 83fd9f953c286c5c3302b32adae8ef693f0a068d544554007e56291d572ea87cad9a341a9638da4473ac9fd5819463a7692ec3987b8b5e7f1f7f6706eb335c4f
7
- data.tar.gz: b8d0510056974d9f8d35165e41ad9cd44a4760ba399a5ba614b780fa25955f43dc5cf9d5273fadc0e2c5774a2c23deda140189b39e2f077687b6949ebdacc644
6
+ metadata.gz: 810794625e6ca4ca08f16406b840eebec75f2fc7ecdb217809509fbc85d48a2d7d4ae265086fdb21f3631d87523026105fd48cff17ec21e2c0861bf181cb8eb2
7
+ data.tar.gz: 9bd784f01de609a744d04bdc7e6ecb0e514c112f00aebd599394924dd71318b1ef2abb9793d12fc916018cfce39c44f9bd46194c5e8b37f32759de560afe9a38
@@ -1,50 +1,48 @@
1
- PATH
2
- remote: .
3
- specs:
4
- hail_hydra (0.2.2)
5
- httparty
6
- nokogiri (>= 1.10.8)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- diff-lcs (1.3)
12
- httparty (0.17.1)
13
- mime-types (~> 3.0)
14
- multi_xml (>= 0.5.2)
15
- mime-types (3.2.2)
16
- mime-types-data (~> 3.2015)
17
- mime-types-data (3.2019.0331)
18
- mini_portile2 (2.4.0)
19
- multi_xml (0.6.0)
20
- nokogiri (1.10.8)
21
- mini_portile2 (~> 2.4.0)
22
- nokogiri (1.10.8-x64-mingw32)
23
- mini_portile2 (~> 2.4.0)
24
- rake (13.0.1)
25
- rspec (3.7.0)
26
- rspec-core (~> 3.7.0)
27
- rspec-expectations (~> 3.7.0)
28
- rspec-mocks (~> 3.7.0)
29
- rspec-core (3.7.1)
30
- rspec-support (~> 3.7.0)
31
- rspec-expectations (3.7.0)
32
- diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.7.0)
34
- rspec-mocks (3.7.0)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.7.0)
37
- rspec-support (3.7.1)
38
-
39
- PLATFORMS
40
- ruby
41
- x64-mingw32
42
-
43
- DEPENDENCIES
44
- bundler (~> 1.16)
45
- hail_hydra!
46
- rake (~> 13.0)
47
- rspec (~> 3.0)
48
-
49
- BUNDLED WITH
50
- 1.16.1
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hail_hydra (0.2.3)
5
+ addressable
6
+ httparty
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ diff-lcs (1.4.4)
14
+ httparty (0.18.0)
15
+ mime-types (~> 3.0)
16
+ multi_xml (>= 0.5.2)
17
+ mime-types (3.3.1)
18
+ mime-types-data (~> 3.2015)
19
+ mime-types-data (3.2020.0425)
20
+ multi_xml (0.6.0)
21
+ public_suffix (4.0.5)
22
+ rake (13.0.1)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.2)
28
+ rspec-support (~> 3.9.3)
29
+ rspec-expectations (3.9.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.3)
36
+
37
+ PLATFORMS
38
+ ruby
39
+ x64-mingw32
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 2.1)
43
+ hail_hydra!
44
+ rake (~> 13.0)
45
+ rspec (~> 3.9)
46
+
47
+ BUNDLED WITH
48
+ 2.1.4
data/README.md CHANGED
@@ -29,21 +29,15 @@ $ thepiratebay totallynotillegal
29
29
 
30
30
  From code
31
31
  ```ruby
32
- s = HailHydra::TPB.new("https://thepiratebay.org")
32
+ s = HailHydra::TPB.new("https://apibay.org")
33
33
 
34
34
  res = s.search('totallynotillegal')
35
35
  res.each do |torrent|
36
- puts torrent.name + " " + torrent.url
36
+ puts torrent.name + " " + torrent.size
37
37
  end
38
38
 
39
39
  ```
40
40
 
41
- ## Future releases
42
- 1. Scrape more info about the torrents
43
- 2. Add functionality to allow uploading torrents
44
- 3. Add user auth?
45
- 4. Add ability to comment
46
-
47
41
  ## Contributing
48
42
 
49
43
  Bug reports and pull requests are welcome on GitHub at https://github.com/Gr3atWh173/hail_hydra. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -57,4 +51,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
57
51
  Everyone interacting in the HailHydra project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Gr3atWh173/hail_hydra/blob/master/CODE_OF_CONDUCT.md).
58
52
 
59
53
  ## DISCLAIMER
60
- Neither this project or its author are related to ThePirateBay in any way.
54
+ Neither this project nor its author are related to ThePirateBay in any way.
@@ -2,14 +2,13 @@
2
2
 
3
3
  require 'hail_hydra'
4
4
 
5
- domain = "https://thepiratebay.org"
5
+ domain = "https://apibay.org"
6
6
  search = ARGV[0]
7
- pages = 1
8
7
 
9
- HailHydra::TPB.new(domain).search(search, pages).each do |result|
8
+ HailHydra::TPB.new(domain).search(search).each do |result|
10
9
  puts ""
11
10
  puts "NAME: " + result.name
12
- puts "URL: " + result.url
11
+ puts "SIZE: " + result.size
13
12
  puts "SEEDERS: " + result.seeders
14
13
  puts "LEECHERS: " + result.leechers
15
14
  puts "MAGNET: " + result.magnet_link
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "bundler", "~> 2.1"
24
24
  spec.add_development_dependency "rake", "~> 13.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "rspec", "~> 3.9"
26
26
 
27
- spec.add_dependency "nokogiri", ">= 1.10.8"
27
+ spec.add_dependency "addressable"
28
28
  spec.add_dependency "httparty"
29
29
  end
@@ -1,77 +1,74 @@
1
1
  require "httparty"
2
- require "nokogiri"
2
+ require "json"
3
+ require "addressable/uri"
4
+ require "cgi"
3
5
  require_relative "torrent.rb"
4
6
 
5
7
  module HailHydra
6
8
  # The TPB class provides the main client to connect to and scrape the
7
- # results. This may be broken into a 'client' and 'parser' in the future.
9
+ # results.
8
10
  class TPB
9
11
  # remember the domain name and get the cookie to use from the TPB server
10
- def initialize(domain_name)
11
- @domain = domain_name
12
- @headers = get_query_headers
12
+ def initialize domain="https://apibay.org"
13
+ @domain = domain
13
14
  end
14
15
 
15
16
  # search torrents
16
- def search(query, pages=1, orderby=99)
17
- get = make_search_request(query, pages, orderby)
17
+ def search query
18
+ get = make_search_request query
18
19
  raise "Invalid response: #{get.response.code}" unless get.response.code == "200"
19
- return parse_search_results(get.response.body)
20
+ return parse_search_results JSON.parse(get.response.body)
20
21
  end
21
22
 
22
23
  private
23
24
 
24
- def parse_search_results(html_text)
25
- nodes = Nokogiri::HTML(html_text)
26
- cells = []
27
- table = nodes.search('table')
28
-
29
- table.search('tr').each do |tr|
30
- cells.push(tr.search('th, td'))
31
- end
32
-
25
+ def parse_search_results json_results
33
26
  torrents = []
34
- descriptions = nodes.css('font.detDesc')
35
- 1.upto cells.length-1 do |i|
36
- torrent = HailHydra::Torrent.new()
37
-
38
- torrent.name = cells[i][1].children[1].children[1].children[0].content
39
- torrent.url = @domain + cells[i][1].children[1].children[1].attributes["href"].value
40
- torrent.magnet_link = cells[i][1].children[3].attributes["href"].value
41
- torrent.seeders = cells[i][2].children[0].content
42
- torrent.leechers = cells[i][3].children[0].content
43
-
44
- # extracting the uploaded by, at and size is a bit trickier
45
- info_line = descriptions[i-1].text.gsub("\u00A0", "---").split(",").map(&:strip)
46
-
47
- torrent.uploaded_at = info_line[0].split(" ")[1].gsub("---", " ")
48
- torrent.size = info_line[1].split(" ")[1].gsub("---", " ")
49
- torrent.uploaded_by = info_line[2].split(" ")[2]
50
-
27
+ json_results.each do |result|
28
+ torrent = HailHydra::Torrent.new
29
+ torrent.name = result["name"]
30
+ torrent.seeders = result["seeders"]
31
+ torrent.leechers = result["leechers"]
32
+ torrent.uploaded_by = result["username"]
33
+ torrent.uploaded_at = Time.at(result["added"].to_i).to_s
34
+ torrent.size = make_size(result["size"].to_i)
35
+ torrent.magnet_link = make_magnet_link(result["info_hash"], result["name"])
51
36
  torrents.push torrent
52
37
  end
53
38
  return torrents
54
39
  end
55
40
 
56
- def make_search_request(query, pages, orderby)
57
- query = {
58
- "q" => query,
59
- "page" => 0.to_s,
60
- "orderby" => orderby.to_s
61
- }
41
+ private
42
+
43
+ def make_magnet_link info_hash, name
44
+ # used CGI.escape because URI.encode now throws a warning and Addressable doesn't seem to
45
+ # support not-URL strings
46
+ return "magnet:?xt=urn:btih:#{info_hash}&dn=#{CGI.escape(name)}#{trackers}"
47
+ end
48
+
49
+ def trackers
50
+ tr = '&tr=' + Addressable::URI.encode('udp://tracker.coppersurfer.tk:6969/announce')
51
+ tr += '&tr=' + Addressable::URI.encode('udp://9.rarbg.to:2920/announce')
52
+ tr += '&tr=' + Addressable::URI.encode('udp://tracker.opentrackr.org:1337')
53
+ tr += '&tr=' + Addressable::URI.encode('udp://tracker.internetwarriors.net:1337/announce')
54
+ tr += '&tr=' + Addressable::URI.encode('udp://tracker.leechers-paradise.org:6969/announce')
55
+ tr += '&tr=' + Addressable::URI.encode('udp://tracker.coppersurfer.tk:6969/announce')
56
+ tr += '&tr=' + Addressable::URI.encode('udp://tracker.pirateparty.gr:6969/announce')
57
+ tr += '&tr=' + Addressable::URI.encode('udp://tracker.cyberia.is:6969/announce')
58
+ return tr
59
+ end
62
60
 
63
- # not sure why HTTParty doesn't do this already
64
- encoded_uri = URI.encode(@domain+"/search/" + query["q"] + "/0/" + query["orderby"] + "/0")
65
- HTTParty.get(encoded_uri, headers: @headers)
61
+ def make_size size
62
+ return ((size / 1125899906842624).round(3)).to_s + "PiB" if size >= 1125899906842624
63
+ return ((size / 1099511627776).round(3)).to_s + "TiB" if size >= 1099511627776
64
+ return ((size / 1073741824).round(3)).to_s + "GiB" if size >= 1073741824
65
+ return ((size / 1048576).round(3)).to_s + "MiB" if size >= 1048576
66
+ return ((size / 1024).round(3)).to_s + "KiB" if size >= 1024
66
67
  end
67
68
 
68
- def get_query_headers()
69
- cookie = HTTParty.get(@domain).response['set-cookie']
70
- return {
71
- 'User-Agent' => 'Mozilla/5.0 (Windows 10; WOW64; rv:10.0) Gecko/20100101 Firefox/10.0',
72
- 'Referer' => @domain,
73
- 'Cookie' => cookie
74
- }
69
+ def make_search_request query
70
+ encoded_uri = Addressable::URI.encode(@domain + "/q.php?q=" + query)
71
+ HTTParty.get encoded_uri
75
72
  end
76
73
  end
77
74
  end
@@ -1,3 +1,3 @@
1
1
  module HailHydra
2
- VERSION = "0.2.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hail_hydra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gr3atWh173
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-01 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.1'
20
20
  type: :development
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: '1.16'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.9'
55
55
  - !ruby/object:Gem::Dependency
56
- name: nokogiri
56
+ name: addressable
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.10.8
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.10.8
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -124,8 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.6.14.1
127
+ rubygems_version: 3.1.2
129
128
  signing_key:
130
129
  specification_version: 4
131
130
  summary: Unofficial pseudo-API for ThePirateBay