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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ee398e99916449521153f862a0c18bb7534e7cc
4
- data.tar.gz: 34f775df3c49296be598fe4d541c5b20ce27fef1
3
+ metadata.gz: 3b01df74d9ebdef51e46ede758d4b144e8a81beb
4
+ data.tar.gz: 333697b0e6ce94ce7d71ff36ee34d3531cb0f2f7
5
5
  SHA512:
6
- metadata.gz: 9ffa6277f1db5d387ce401abb32a4f66466f0a32cac5e62d3269558d878385fa3933dfba00f15a08fd2d301c9dc5ef14912c9a2a9a82b37ab661333298f8f4d5
7
- data.tar.gz: 52caa081807d7a89ec6ea03a16b775db271fcb57cddc3d93cb1f44611ab3545ac6e5a8b1adbf5486c00b0a3a66c2f6a154e29fa6bd0327ceb5cdcbf21e22a7f7
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/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.
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 |h|
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 download torrent [DIRECTORY]') do |d|
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 |l|
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[:search], options[:provider] || 'katcr', options[:auto] || false, options[:directory] || Dir.pwd)
34
- end
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
- def initialize(query = '', from = 'katcr', auto = false, directory = Dir.pwd)
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.exists? yaml
16
+ if File.exist? yaml
13
17
  @provider = YAML.load_file(yaml)
14
18
  else
15
- not_exists_provider
19
+ list_providers_and_exit
16
20
  end
17
21
 
18
- @query = query
19
- @from = from
20
- @auto = auto
21
- @directory = directory
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 '😰 Sorry, I think you banned from ' + @from + '. There is a threat defense redirection.'
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 'Scrabing...'
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 for interrupt)",
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 can\'t start automatically magnet links. Please use this in your torrent client.'
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
- puts 'Downloading ' + target_file_name
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
- ensure
133
+ else
122
134
  puts '🥂 Downloaded!'
123
- system 'open', target_file if RUBY_PLATFORM =~ /darwin/
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 not_exists_provider
136
- puts "☠️ There is not found #{@from} provider."
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 'Exiting'
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? @directory or File.directory? @directory
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
@@ -1,3 +1,3 @@
1
1
  module TorS
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.2'.freeze
3
3
  end
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.0
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-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri