tors 0.3.0 → 0.3.2
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/README.md +8 -1
- data/lib/tors.rb +18 -5
- data/lib/tors/search.rb +35 -20
- data/lib/tors/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b01df74d9ebdef51e46ede758d4b144e8a81beb
|
4
|
+
data.tar.gz: 333697b0e6ce94ce7d71ff36ee34d3531cb0f2f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a310371c00409519df7190cb6cd4df7087d073d9f72dee140a95b1288b8e94d4a22e69e6b0120563b6a6cdba9cdf73a4da488f82bbb93c62d19f48604f651b38
|
7
|
+
data.tar.gz: 21632d35679252bc8c90c21b97f5d8af1c2f6cc5c689cc2f02d92e45b293336977c280bc2c3b5fc82df3fa0be4151a4c7b54bc2d85ba84121a7194f3c4731d84
|
data/README.md
CHANGED
@@ -78,6 +78,7 @@ And you can list all active providers and usage instructions with `-h` or `--hel
|
|
78
78
|
-p, --provider=p Provider name [PROVIDER]
|
79
79
|
-l, --list-providers List providers
|
80
80
|
-a, --auto-download Auto download best choice
|
81
|
+
-o, --open Open torrent after downloading
|
81
82
|
|
82
83
|
|
83
84
|
|
@@ -91,7 +92,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
91
92
|
|
92
93
|
## Contributing
|
93
94
|
|
94
|
-
Bug reports and pull requests are welcome on GitHub at [https://github.com/muratbsts/
|
95
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/muratbsts/tors](https://github.com/muratbsts/tors). 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.
|
96
|
+
|
97
|
+
## Contributors
|
98
|
+
|
99
|
+
- [Murat Bastas](https://github.com/muratbsts)
|
100
|
+
- [Eren Türkay](https://github.com/eren)
|
101
|
+
- [Muhammet Dilmaç](https://github.com/muhammetdilmac)
|
95
102
|
|
96
103
|
## License
|
97
104
|
|
data/lib/tors.rb
CHANGED
@@ -6,20 +6,20 @@ require 'optparse'
|
|
6
6
|
module TorS
|
7
7
|
options = {}
|
8
8
|
OptionParser.new do |opts|
|
9
|
-
opts.on('-h', '--help', 'Show usage instructions') do |
|
9
|
+
opts.on('-h', '--help', 'Show usage instructions') do |_h|
|
10
10
|
puts opts
|
11
11
|
abort
|
12
12
|
end
|
13
13
|
opts.on('-s=s', '--search=s', 'Search term [SEARCH]') do |s|
|
14
14
|
options[:search] = s
|
15
15
|
end
|
16
|
-
opts.on('-d=d', '--directory=d', 'Destination path for
|
16
|
+
opts.on('-d=d', '--directory=d', 'Destination path for downloaded torrent [DIRECTORY]') do |d|
|
17
17
|
options[:directory] = d
|
18
18
|
end
|
19
19
|
opts.on('-p=p', '--provider=p', 'Provider name [PROVIDER]') do |p|
|
20
20
|
options[:provider] = p
|
21
21
|
end
|
22
|
-
opts.on('-l', '--list-providers', 'List providers') do |
|
22
|
+
opts.on('-l', '--list-providers', 'List providers') do |_l|
|
23
23
|
Dir[File.expand_path('providers/*.yml')].each do |f|
|
24
24
|
puts '- ' + File.basename(f).split('.').first
|
25
25
|
end
|
@@ -28,7 +28,20 @@ module TorS
|
|
28
28
|
opts.on('-a', '--auto-download', 'Auto download best choice') do
|
29
29
|
options[:auto] = true
|
30
30
|
end
|
31
|
+
|
32
|
+
if RUBY_PLATFORM =~ /darwin/
|
33
|
+
opts.on('-o', '--open', 'Open torrent after downloading') do
|
34
|
+
options[:open] = true
|
35
|
+
end
|
36
|
+
end
|
31
37
|
end.parse!
|
32
38
|
|
33
|
-
TorS::Search.new(options[:
|
34
|
-
|
39
|
+
tors = TorS::Search.new(options[:provider] || 'katcr') do |ts|
|
40
|
+
ts.query = options[:search]
|
41
|
+
ts.auto = options[:auto] || false
|
42
|
+
ts.directory = options[:directory] || Dir.pwd
|
43
|
+
ts.open_torrent = options[:open] || false
|
44
|
+
end
|
45
|
+
|
46
|
+
tors.run
|
47
|
+
end
|
data/lib/tors/search.rb
CHANGED
@@ -7,19 +7,26 @@ require 'tty-prompt'
|
|
7
7
|
|
8
8
|
module TorS
|
9
9
|
class Search
|
10
|
-
|
10
|
+
attr_accessor :query, :from, :auto, :directory, :open_torrent
|
11
|
+
|
12
|
+
def initialize(from = 'katcr')
|
13
|
+
@from = from
|
14
|
+
|
11
15
|
yaml = File.expand_path("../../../providers/#{from}.yml", __FILE__)
|
12
|
-
if File.
|
16
|
+
if File.exist? yaml
|
13
17
|
@provider = YAML.load_file(yaml)
|
14
18
|
else
|
15
|
-
|
19
|
+
list_providers_and_exit
|
16
20
|
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
if block_given?
|
23
|
+
yield self
|
24
|
+
else
|
25
|
+
raise "#{self.class} requires block to initialize"
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
29
|
+
def run
|
23
30
|
check_download_directory
|
24
31
|
scrape
|
25
32
|
end
|
@@ -30,7 +37,7 @@ module TorS
|
|
30
37
|
|
31
38
|
if @page.css(@provider['scrape']['selector']).empty?
|
32
39
|
if threat_defence @page
|
33
|
-
puts
|
40
|
+
puts "😰 Sorry, I think you are banned from #{from}. There is a threat defense redirection."
|
34
41
|
end
|
35
42
|
|
36
43
|
puts 'Please check this url is works : ' + @url
|
@@ -40,7 +47,7 @@ module TorS
|
|
40
47
|
@rows = []
|
41
48
|
@downloads = []
|
42
49
|
|
43
|
-
puts '
|
50
|
+
puts 'Scraping...'
|
44
51
|
|
45
52
|
key = 0
|
46
53
|
@page.css(@provider['scrape']['selector']).each do |row|
|
@@ -95,7 +102,7 @@ module TorS
|
|
95
102
|
|
96
103
|
def prompt
|
97
104
|
prompt = TTY::Prompt.new(interrupt: :exit)
|
98
|
-
choice = prompt.ask("Which torrent you want to download? (1..#{@downloads.size} or ctrl+c/cmd+c
|
105
|
+
choice = prompt.ask("Which torrent do you want to download? (1..#{@downloads.size} or ctrl+c/cmd+c to interrupt)",
|
99
106
|
convert: :int,
|
100
107
|
default: 1) do |c|
|
101
108
|
c.in "1-#{@downloads.size}"
|
@@ -107,20 +114,28 @@ module TorS
|
|
107
114
|
|
108
115
|
def download(choice)
|
109
116
|
if choice[:url] =~ /^magnet:\?/
|
110
|
-
puts '😏 Sorry, I
|
117
|
+
puts '😏 Sorry, I cannot download magnet links. Please copy/paste the following link into your torrent client'
|
111
118
|
puts choice[:url]
|
112
119
|
else
|
113
120
|
begin
|
121
|
+
target_file_name = choice[:name].tr("\n", ' ').squeeze(' ').strip + '.torrent'
|
122
|
+
puts 'Downloading ' + target_file_name
|
123
|
+
|
114
124
|
source = Net::HTTP.get(URI.parse(choice[:url]))
|
115
|
-
target_file_name = choice[:name].tr("\n", ' ').squeeze(' ').strip + '.torrent'
|
116
125
|
target_file = File.join(@directory, target_file_name)
|
117
|
-
|
126
|
+
|
118
127
|
File.write(target_file, source)
|
119
128
|
rescue IOError => e
|
129
|
+
# FIXME: what about HTTP errors? Net::HTTP throws a number of
|
130
|
+
# exceptions. It would be wise to use another HTTP library for this
|
131
|
+
# purpose
|
120
132
|
puts '😵 There is an error! ' + e.message
|
121
|
-
|
133
|
+
else
|
122
134
|
puts '🥂 Downloaded!'
|
123
|
-
|
135
|
+
|
136
|
+
# Open torrent option is only present in Darwin platform so there is
|
137
|
+
# no need to check the platform here
|
138
|
+
system("open '#{target_file}'") if @open_torrent
|
124
139
|
end
|
125
140
|
end
|
126
141
|
end
|
@@ -132,20 +147,20 @@ module TorS
|
|
132
147
|
|
133
148
|
private
|
134
149
|
|
135
|
-
def
|
136
|
-
puts "☠️
|
150
|
+
def list_providers_and_exit
|
151
|
+
puts "☠️ Provider '#{@from}' does not exist."
|
152
|
+
puts "Please choose a valid provider from the following list:\n\n"
|
137
153
|
|
138
|
-
puts 'You must choose from this list.'
|
139
154
|
Dir[File.expand_path('providers/*.yml')].each do |f|
|
140
155
|
puts '- ' + File.basename(f).split('.').first
|
141
156
|
end
|
142
157
|
|
143
|
-
abort
|
158
|
+
abort
|
144
159
|
end
|
145
160
|
|
146
161
|
def check_download_directory
|
147
162
|
ioerr = false
|
148
|
-
ioerr = "😱 Directory #{@directory} not found." unless File.exist?
|
163
|
+
ioerr = "😱 Directory #{@directory} not found." unless File.exist?(@directory) || File.directory?(@directory)
|
149
164
|
ioerr = "😱 Directory #{@directory} not writable." unless File.writable? @directory
|
150
165
|
if ioerr
|
151
166
|
puts ioerr
|
data/lib/tors/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Murat Bastas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|