mushin_ext_tpb 0.1.0 → 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 +4 -4
- data/lib/TPB/IUAM.js +18 -0
- data/lib/TPB/version.rb +1 -1
- data/lib/mushin_ext_tpb.rb +108 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e46f7aa9fce3169d1f35562881b32e05fbf46e3a
|
4
|
+
data.tar.gz: 4ccb6f2406c1a424ff4f03450ffd4d3ba88a71c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206f89dfdcff593959855363ece6a7223ed0945c306f326d47db47ee7064ce027c863e834c1cc8dfd1e19a1ef4f24db79eb1ef51b6a6132b74a5951feb5fc636
|
7
|
+
data.tar.gz: a24e42684af5297c80d1cce9f36ed0e1e0fc23b2a1e09f5beae382e9b38790b4e84e04b2fd4da49249c36625da202dd8b126c0b8096c967cfc4176038a4cb77e
|
data/lib/TPB/IUAM.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
// https://github.com/codemanki/cloudscraper forked at https://github.com/zotherstupidguy/cloudscraper
|
2
|
+
|
3
|
+
console.log("IUAM is active")
|
4
|
+
|
5
|
+
var url = process.argv[2]
|
6
|
+
console.log(url)
|
7
|
+
|
8
|
+
var cloudscraper = require('cloudscraper');
|
9
|
+
|
10
|
+
//cloudscraper.get('https://thepiratebay.org/s/?q=Algorithms&page=0&orderby=99', function(error, response, body) {
|
11
|
+
cloudscraper.get(url, function(error, response, body) {
|
12
|
+
if (error) {
|
13
|
+
console.log('Error occurred');
|
14
|
+
} else {
|
15
|
+
console.log(body);
|
16
|
+
//console.log(body, response);
|
17
|
+
}
|
18
|
+
});
|
data/lib/TPB/version.rb
CHANGED
data/lib/mushin_ext_tpb.rb
CHANGED
@@ -1,10 +1,108 @@
|
|
1
1
|
require 'mushin'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
require 'httparty'
|
6
|
+
require 'open3'
|
7
|
+
|
2
8
|
require_relative 'TPB/version'
|
3
9
|
|
4
10
|
|
5
11
|
module TPB
|
12
|
+
module Internal
|
13
|
+
class EmptyQuery < RuntimeError
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_service(url, params)
|
17
|
+
begin
|
18
|
+
response = HTTParty.get(url, query: params, :verify => false)
|
19
|
+
begin
|
20
|
+
if response.code == 200
|
21
|
+
p "everything fine"
|
22
|
+
return true
|
23
|
+
else
|
24
|
+
p response.code
|
25
|
+
p "unexpected status code"
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
rescue Timeout::Error
|
29
|
+
p "timeout reading from server"
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
rescue Timeout::Error
|
33
|
+
p "timeout connecting to server"
|
34
|
+
return false
|
35
|
+
rescue SocketError
|
36
|
+
p "unknown server"
|
37
|
+
return false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def search(query)
|
42
|
+
p query
|
43
|
+
uri = "https://thepiratebay.org/search/#{URI.escape(query)}"
|
44
|
+
case check_service(uri, "")
|
45
|
+
when true
|
46
|
+
stdin, scraped, stderr = Open3.popen3("node #{File.dirname(__FILE__)}/TPB/IUAM.js #{uri}")
|
47
|
+
doc = Nokogiri::HTML(scraped)
|
48
|
+
when false
|
49
|
+
stdin, scraped, stderr = Open3.popen3("node #{File.dirname(__FILE__)}/TPB/IUAM.js #{uri}")
|
50
|
+
doc = Nokogiri::HTML(scraped)
|
51
|
+
else
|
52
|
+
p "tpb is not online, skip it Gracefully"
|
53
|
+
end
|
54
|
+
@results = Hash.new
|
55
|
+
@results[:torrents] = []
|
56
|
+
|
57
|
+
start_time = Time.now
|
58
|
+
|
59
|
+
doc.xpath('//*[@id="searchResult"]').search('tr').each do |row|
|
60
|
+
name = row.search('a.detLink')
|
61
|
+
next if name.empty? # Skip empty names
|
62
|
+
|
63
|
+
temp = row.search('font.detDesc').text
|
64
|
+
match = temp.match /Uploaded (.*), ULed by .*/
|
65
|
+
|
66
|
+
if !match.nil? then
|
67
|
+
description = match[1] unless match[1].nil?
|
68
|
+
upload_date, total_size = description.split(',')
|
69
|
+
|
70
|
+
total_size.slice! "Size" #removes the word 'Size'
|
71
|
+
total_size.strip! #removes empty spaces
|
72
|
+
|
73
|
+
temp = row.search('td')
|
74
|
+
seeders = temp[2].text unless temp[2].nil?
|
75
|
+
leechers = temp[3].text unless temp[3].nil?
|
76
|
+
|
77
|
+
|
78
|
+
magnet_link = ""
|
79
|
+
row.search('a').each do |a|
|
80
|
+
if a["href"].match /^magnet.*/
|
81
|
+
magnet_link = a["href"]
|
82
|
+
break
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
#TODO make the service make sure its .to_json
|
88
|
+
@results[:torrents] << { :seeders => seeders, :leechers => leechers, :upload_date => upload_date, :total_size => total_size, :name => name.text, :magnet_link => magnet_link }
|
89
|
+
end
|
90
|
+
finish_time = Time.now
|
91
|
+
|
92
|
+
@results[:results_count] = @results[:torrents].count
|
93
|
+
@results[:search_time] = finish_time - start_time
|
94
|
+
|
95
|
+
#TODO use logger instead
|
96
|
+
puts JSON.pretty_generate @results
|
97
|
+
@results
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
6
101
|
class Ext
|
7
102
|
using Mushin::Ext
|
103
|
+
include Internal
|
104
|
+
|
105
|
+
attr_accessor :results
|
8
106
|
|
9
107
|
def initialize app=nil, opts={}, params={}
|
10
108
|
@app = app
|
@@ -13,14 +111,19 @@ module TPB
|
|
13
111
|
end
|
14
112
|
def call env
|
15
113
|
env ||= Hash.new
|
16
|
-
#
|
17
|
-
|
18
|
-
|
114
|
+
$log.debug "#{self} ------ Inbound maniuplation"
|
115
|
+
env[:query] = @params[:query]
|
116
|
+
env[:id] = @params[:query]
|
117
|
+
|
118
|
+
case
|
119
|
+
when env[:query].nil?, env[:query].empty?
|
120
|
+
p "empty is no good"
|
19
121
|
else
|
20
|
-
|
122
|
+
results = search(env[:query])
|
123
|
+
env[:tpbbot] = results
|
21
124
|
end
|
22
125
|
@app.call(env)
|
23
|
-
#
|
126
|
+
$log.debug "#{self} ------ Outbound maniuplation"
|
24
127
|
end
|
25
128
|
end
|
26
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mushin_ext_tpb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zotherstupidguy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- TPB.gemspec
|
84
84
|
- bin/console
|
85
85
|
- bin/setup
|
86
|
+
- lib/TPB/IUAM.js
|
86
87
|
- lib/TPB/version.rb
|
87
88
|
- lib/mushin_ext_tpb.rb
|
88
89
|
homepage: http://hackspree.com
|