tors 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbc41cecac6500bfa91947abab8ebfd9f0ab8658
4
- data.tar.gz: f49142eb95de177576f23ee3fbf9b14d5294cab3
3
+ metadata.gz: 3051833668a39d67c65e1aad241994436241c455
4
+ data.tar.gz: 8db8f95fe1308068e16d2a811b6daf2d25ba5283
5
5
  SHA512:
6
- metadata.gz: 1e03556f83b022ad8ee04bfd5efd0261ba4c3e0a6281fdec84e79e4e2ce4279fa5886392efca35a76983e3d9f0feeab232287d395d31bfd319fd2cf604ce72fd
7
- data.tar.gz: 62ceb765aff677e8d114ba5f5ffbf89c0d0821d43a15b6eb1e669cad81563707e2701ad05d94b37f10ec998cbe2995291d7484113eea1882945353b3d0d3c0fc
6
+ metadata.gz: ecb00262740d37ea438b14ae6dffac0a41ecbb4c4ba6d4fee4326e3674d77685205e104c0f223c2b0a3cbc8dfca02fb5d7a1c8fbdc137ab193e9dae212a1d9ac
7
+ data.tar.gz: bdf8b6e022adbdaf29069d860d943b6664b4169c7d8c0c5b2033ac74a65c04e5e71de84302c64d3c7af7bf06d2a0fa25febe48f7550c6d2ef1441fd1ef08f0e7
data/.gitignore CHANGED
@@ -12,4 +12,6 @@
12
12
  .rspec_status
13
13
 
14
14
  /.idea
15
- /*.gem
15
+ /*.gem
16
+
17
+ *.swp
data/README.md CHANGED
@@ -43,17 +43,17 @@ Because katcr fastest provider for scrabing currently.
43
43
 
44
44
  Yep, there is a few provider option.
45
45
 
46
- | Provider | Status | Problems |
47
- |:------------------|:------:|:---------|
48
- | katcr | ✅ | - |
46
+ | Provider | Status | Problems |
47
+ |:------------------|:------:|:----------------------------------|
48
+ | katcr | ✅ | - |
49
49
  | rarbg | ✅ | Slow Connection, Threat defensing |
50
- | thepiratebay | ✅ | Only Magnet |
51
- | extratorrent | ✅ | Slow Connection |
52
- | 1337x | ✅ | Connection N+1 |
53
- | zooqle | ✅ | Skipping some torrents |
54
- | zamunda | ✅ | Require authentication |
55
- | torrentfunk | ☑️ | 🙈 |
56
- | limetorrents | ☑️ | 🙈 |
50
+ | thepiratebay | ✅ | Only Magnet |
51
+ | extratorrent | ✅ | Slow Connection |
52
+ | 1337x | ✅ | Connection N+1 |
53
+ | zooqle | ✅ | Skipping some torrents |
54
+ | zamunda | ✅ | Require authentication |
55
+ | torrentfunk | ☑️ | 🙈 |
56
+ | limetorrents | ☑️ | 🙈 |
57
57
 
58
58
  Use `-p PROVIDER` flag for scrape another providers.
59
59
 
@@ -67,7 +67,7 @@ You can use `-a` or `--auto-download` flag for automatically download the best t
67
67
 
68
68
  You can use `-d TARGET` flag for set destination storage path. Example:
69
69
 
70
- $ tors -s 'Assassins' -d $HOME/Downloads -a
70
+ $ tors -s 'ubuntu' -d $HOME/Downloads -a
71
71
 
72
72
  And you can list all active providers and usage instructions with `-h` or `--help` flag.
73
73
 
@@ -1,59 +1,69 @@
1
1
  require 'tors/version'
2
2
  require 'tors/search'
3
- require 'colorize'
4
- require 'optparse'
3
+ require 'slop'
5
4
 
5
+ # Main module for passing options and initializing TorS::Search class
6
6
  module TorS
7
- options = {}
8
- OptionParser.new do |opts|
9
- opts.on('-h', '--help', 'Show usage instructions') do |_h|
10
- puts opts
11
- abort
12
- end
13
- opts.on('-s=s', '--search=s', 'Search term [SEARCH]') do |s|
14
- options[:search] = s
15
- end
16
- opts.on('-d=d', '--directory=d', 'Destination path for downloaded torrent [DIRECTORY]') do |d|
17
- options[:directory] = d
18
- end
19
- opts.on('-p=p', '--provider=p', 'Provider name [PROVIDER]') do |p|
20
- options[:provider] = p
21
- end
22
- opts.on('-u=u', '--username=u', 'Username for authentication') do |u|
23
- options[:username] = u
24
- end
25
- opts.on('-w=p', '--password=p', 'Password for authentication') do |p|
26
- options[:password] = p
27
- end
28
- opts.on('-l', '--list-providers', 'List providers') do |_l|
7
+ REQUIRE_AUTH = %w[zamunda].freeze
8
+
9
+ opts = Slop.parse do |o|
10
+ o.banner = 'usage: tors [options] SEARCH_STRING'
11
+ o.string '-d', '--directory', 'Destination path for downloaded torrent', default: Dir.pwd
12
+ o.string '-p', '--provider', 'Provider name', default: 'katcr'
13
+ o.string '-u', '--username', 'Username for authentication'
14
+ o.string '-w', '--password', 'Password for authentication'
15
+ o.on '-l', '--list-providers', 'List available providers' do
29
16
  puts '- 1337x'
30
17
  puts '- extratorrent'
31
18
  puts '- katcr'
32
19
  puts '- rarbg'
33
20
  puts '- thepiratebay'
34
- puts '- zamunda'
21
+ puts '- zamunda (requires authentication)'
35
22
  puts '- zooqle'
36
- abort
37
- end
38
- opts.on('-a', '--auto-download', 'Auto download best choice') do
39
- options[:auto] = true
23
+ exit
40
24
  end
41
25
 
26
+ o.bool '-a', '--auto-download', 'Auto download best choice', default: false
27
+
42
28
  if RUBY_PLATFORM =~ /darwin/
43
- opts.on('-o', '--open', 'Open torrent after downloading') do
44
- options[:open] = true
45
- end
29
+ o.bool '-o', '--open', 'Open torrent after downloading', default: false
30
+ end
31
+
32
+ o.on '-h', '--help', 'Print help' do
33
+ puts o
34
+ exit
46
35
  end
47
- end.parse!
48
-
49
- tors = TorS::Search.new(options[:provider] || 'katcr') do |ts|
50
- ts.username = options[:username]
51
- ts.password = options[:password]
52
- ts.query = options[:search]
53
- ts.auto = options[:auto] || false
54
- ts.directory = options[:directory] || Dir.pwd
55
- ts.open_torrent = options[:open] || false
36
+
37
+ o.on '-v', '--version', 'Print version' do
38
+ puts VERSION
39
+ exit
40
+ end
41
+ end
42
+
43
+ if opts.arguments.empty?
44
+ puts opts
45
+ exit
46
+ end
47
+
48
+ if REQUIRE_AUTH.include?(opts['provider'])
49
+ if opts['username'].nil? || opts['password'].nil?
50
+ puts "ERROR! Provider #{opts['provider']} requires username and password for authentication".red
51
+ abort
52
+ end
53
+ end
54
+
55
+ tors = TorS::Search.new(opts.arguments[0]) do |ts|
56
+ ts.username = opts['username']
57
+ ts.password = opts['password']
58
+ ts.from = opts['provider']
59
+ ts.auto_download = opts.auto_download?
60
+ ts.directory = opts['directory']
61
+
62
+ # We only have this option in Darwin platform and slop throws an exception
63
+ # for non-defined parameters. That's the reason to check the platform here
64
+ ts.open_torrent = RUBY_PLATFORM =~ /darwin/ ? opts.open? : false
56
65
  end
57
66
 
58
67
  tors.run
68
+
59
69
  end
@@ -5,13 +5,21 @@ require 'mechanize'
5
5
  require 'open-uri'
6
6
  require 'tty-table'
7
7
  require 'tty-prompt'
8
+ require 'colorize'
8
9
 
9
10
  module TorS
10
11
  class Search
11
- attr_accessor :query, :from, :username, :password, :directory, :auto, :open_torrent
12
+ attr_accessor :from, :username, :password, :directory, :auto_download, :open_torrent
12
13
 
13
- def initialize(from = 'katcr')
14
- @from = from
14
+ # Initialize class. Only query string is required and the rest of the attributes
15
+ # are assigned default values.
16
+ def initialize(query)
17
+ raise "#{self.class} requires block to initialize" unless block_given?
18
+ yield self
19
+
20
+ @query = query
21
+ @from ||= 'katcr'
22
+ @directory ||= Dir.pwd
15
23
 
16
24
  yaml = File.expand_path("../../../providers/#{from}.yml", __FILE__)
17
25
  if File.exist? yaml
@@ -19,12 +27,6 @@ module TorS
19
27
  else
20
28
  list_providers_and_exit
21
29
  end
22
-
23
- if block_given?
24
- yield self
25
- else
26
- raise "#{self.class} requires block to initialize"
27
- end
28
30
  end
29
31
 
30
32
  def run
@@ -36,16 +38,14 @@ module TorS
36
38
  @url = URI.encode(@provider['url'].gsub(/%{(\w+)}/, @query ? @query : ''))
37
39
  @page = Nokogiri::HTML(open(@url))
38
40
 
39
- if @provider['authenticate']
40
- authenticate
41
- end
41
+ authenticate if @provider['authenticate']
42
42
 
43
43
  if @page.css(@provider['scrape']['selector']).empty?
44
44
  if threat_defence @page
45
- puts "😰 Sorry, I think you are banned from #{from}. There is a threat defense redirection.".red
45
+ puts "Sorry, I think you are banned from #{@from}. There is a threat defense redirection.".red
46
46
  end
47
47
 
48
- puts 'Please check this url is works : ' + @url
48
+ puts "Cannot parse the page (#{@url})".red
49
49
  return
50
50
  end
51
51
 
@@ -98,7 +98,7 @@ module TorS
98
98
  table = TTY::Table.new %i[# Category Title Size Seed Leech], @rows
99
99
  puts table.render(:unicode, padding: [0, 1, 0, 1])
100
100
 
101
- if @auto
101
+ if @auto_download
102
102
  download @downloads.find { |v| v[:key] == 1 }
103
103
  else
104
104
  prompt
@@ -119,7 +119,7 @@ module TorS
119
119
 
120
120
  def download(choice)
121
121
  if choice[:url] =~ /^magnet:\?/
122
- puts '😏 Sorry, I cannot download magnet links. Please copy/paste the following link into your torrent client'
122
+ puts 'Sorry! I cannot download magnet links. Please copy/paste the following link into your torrent client'.red
123
123
  puts choice[:url]
124
124
  else
125
125
  begin
@@ -139,9 +139,9 @@ module TorS
139
139
  # FIXME: what about HTTP errors? Net::HTTP throws a number of
140
140
  # exceptions. It would be wise to use another HTTP library for this
141
141
  # purpose
142
- puts '😵 There is an error! ' + e.message
142
+ puts 'There is an error! ' + e.message
143
143
  else
144
- puts '🥂 Downloaded!'
144
+ puts 'Downloaded!'.green
145
145
 
146
146
  # Open torrent option is only present in Darwin platform so there is
147
147
  # no need to check the platform here
@@ -169,8 +169,8 @@ module TorS
169
169
  puts 'Login failed with your credentials!'.red
170
170
  abort
171
171
  end
172
-
173
- puts '✔ Authentication successfull'.green
172
+
173
+ puts '✔ Authentication successful'.green
174
174
  end
175
175
 
176
176
  def threat_defence(page)
@@ -181,7 +181,7 @@ module TorS
181
181
  private
182
182
 
183
183
  def list_providers_and_exit
184
- puts "☠️ Provider '#{@from}' does not exist."
184
+ puts "Provider '#{@from}' does not exist.".red
185
185
  puts "Please choose a valid provider from the following list:\n\n"
186
186
 
187
187
  Dir[File.expand_path('providers/*.yml')].each do |f|
@@ -193,10 +193,11 @@ module TorS
193
193
 
194
194
  def check_download_directory
195
195
  ioerr = false
196
- ioerr = "😱 Directory #{@directory} not found." unless File.exist?(@directory) || File.directory?(@directory)
197
- ioerr = "😱 Directory #{@directory} not writable." unless File.writable? @directory
196
+ ioerr = "Directory #{@directory} not found." unless File.exist?(@directory) || File.directory?(@directory)
197
+ ioerr = "Directory #{@directory} not writable." unless File.writable? @directory
198
+
198
199
  if ioerr
199
- puts ioerr
200
+ puts ioerr.red
200
201
  abort 'Exiting'
201
202
  end
202
203
  end
@@ -1,3 +1,3 @@
1
1
  module TorS
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'colorize', '~> 0.8.1'
29
29
  spec.add_dependency 'tty-table', '~> 0.8.0'
30
30
  spec.add_dependency 'tty-prompt', '~> 0.13.1'
31
+ spec.add_dependency 'slop', '~> 4.5.0'
31
32
 
32
33
  spec.add_development_dependency 'bundler', '~> 1.15'
33
34
  spec.add_development_dependency 'rake', '~> 10.0'
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.4.0
4
+ version: 0.5.0
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-09-03 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.13.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: slop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 4.5.0
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 4.5.0
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: bundler
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
193
  version: '0'
180
194
  requirements: []
181
195
  rubyforge_project:
182
- rubygems_version: 2.6.13
196
+ rubygems_version: 2.6.8
183
197
  signing_key:
184
198
  specification_version: 4
185
199
  summary: Yet another torrent searching application for your command line.