tors 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/.gitignore +2 -1
- data/.travis.yml +4 -2
- data/README.md +16 -1
- data/lib/tors/search.rb +21 -4
- data/lib/tors/version.rb +1 -1
- data/lib/tors.rb +5 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95eea10bc57ad0710b1f7fcd62eb7c4e81376256
|
4
|
+
data.tar.gz: b92ad9855bac1ba0072a8d1f5738f6252cc06d83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 703eeacae5a37dc895a43e97193eae58dea34bda9f4c1ccc2325ecc122d566d28b195d518318e2befa7dec131b486661b2daf194ca328520495d61f00f51d539
|
7
|
+
data.tar.gz: 144829b12bb8a24f7f955d55d94699e828c490844b3cbb2fdb951d4c530b672ea3206b094eda83a88b48ce6367894cc84ee0baa6da48366c2b16b17177b7001c
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# TorS
|
2
2
|
|
3
|
-
|
3
|
+
[](https://github.com/muratbsts/tors/blob/master/LICENCE)
|
4
|
+
[](https://github.com/muratbsts/tors/releases)
|
5
|
+
[](https://travis-ci.org/muratbsts/tors)
|
6
|
+
[](https://github.com/muratbsts/tors/issues)
|
7
|
+
[](https://github.com/muratbsts/tors/pulls)
|
8
|
+
|
9
|
+
[](https://rubygems.org/gems/tors)
|
10
|
+
|
11
|
+
Yet another torrent searching application for your command line.
|
4
12
|
But this has an option for automatically download the best torrent.
|
5
13
|
|
6
14
|
## Installation
|
@@ -56,6 +64,10 @@ You can use `-a 1` flag for automatically download the best torrent. Example:
|
|
56
64
|
|
57
65
|
$ tors -s 'game of thrones' -p 1337x -a 1
|
58
66
|
|
67
|
+
You can use `-d TARGET` flag for set destination storage path. Example:
|
68
|
+
|
69
|
+
$ tors -s 'Assassins' -d $HOME/Downloads -a 1
|
70
|
+
|
59
71
|
And you can list all active providers and usage instructions with `-h` or `--help` flag.
|
60
72
|
|
61
73
|
$ tors -h
|
@@ -63,6 +75,9 @@ And you can list all active providers and usage instructions with `-h` or `--hel
|
|
63
75
|
-s, --search=s Search term [SEARCH]
|
64
76
|
-p, --provider=p From provider name [PROVIDER]
|
65
77
|
-a, --auto-download=a Auto download best choice
|
78
|
+
-d, --directory=d Destination torrent download directory
|
79
|
+
|
80
|
+
[](https://asciinema.org/a/No1Zdfk3gYoCYdGb2XUdFaUyS)
|
66
81
|
|
67
82
|
## Development
|
68
83
|
|
data/lib/tors/search.rb
CHANGED
@@ -7,17 +7,19 @@ require 'tty-prompt'
|
|
7
7
|
|
8
8
|
module TorS
|
9
9
|
class Search
|
10
|
-
def initialize(query, from = 'katcr', auto = false)
|
10
|
+
def initialize(query = '', from = 'katcr', auto = false, directory = Dir.pwd)
|
11
11
|
@provider = YAML.load_file(File.expand_path("../../../providers/#{from}.yml", __FILE__))
|
12
12
|
@query = query
|
13
13
|
@from = from
|
14
14
|
@auto = auto
|
15
|
+
@directory = directory
|
15
16
|
|
17
|
+
check_download_directory
|
16
18
|
scrape
|
17
19
|
end
|
18
20
|
|
19
21
|
def scrape
|
20
|
-
@url = @provider['url'].gsub(/%{(\w+)}/, @query.tr(' ', '+'))
|
22
|
+
@url = @provider['url'].gsub(/%{(\w+)}/, @query ? @query.tr(' ', '+') : '')
|
21
23
|
@page = Nokogiri::HTML(open(@url))
|
22
24
|
|
23
25
|
if @page.css(@provider['scrape']['selector']).empty?
|
@@ -97,8 +99,11 @@ module TorS
|
|
97
99
|
puts choice[:url]
|
98
100
|
else
|
99
101
|
begin
|
100
|
-
|
101
|
-
|
102
|
+
source = Net::HTTP.get(URI.parse(choice[:url]))
|
103
|
+
target_file_name = choice[:name].tr("\n", ' ').squeeze(' ').strip + '.torrent'
|
104
|
+
target_file = File.join(@directory, target_file_name)
|
105
|
+
puts 'Downloading ' + target_file_name
|
106
|
+
File.write(target_file, source)
|
102
107
|
rescue IOError => e
|
103
108
|
puts '😵 There is an error! ' + e.message + ' Here: L108'
|
104
109
|
ensure
|
@@ -111,5 +116,17 @@ module TorS
|
|
111
116
|
return false unless page.text =~ /threat_defence.php/
|
112
117
|
true
|
113
118
|
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def check_download_directory
|
123
|
+
ioerr = false
|
124
|
+
ioerr = "😱 Your download directory #{@directory} not found." unless File.exist? @directory or File.directory? @directory
|
125
|
+
ioerr = "😱 Your download directory #{@directory} not writable." unless File.writable? @directory
|
126
|
+
if ioerr
|
127
|
+
puts ioerr
|
128
|
+
Process.kill 9, Process.pid
|
129
|
+
end
|
130
|
+
end
|
114
131
|
end
|
115
132
|
end
|
data/lib/tors/version.rb
CHANGED
data/lib/tors.rb
CHANGED
@@ -15,7 +15,10 @@ module TorS
|
|
15
15
|
opts.on('-a=a', '--auto-download=a', 'Auto download best choice') do |a|
|
16
16
|
options[:auto] = a || true
|
17
17
|
end
|
18
|
+
opts.on('-d=d', '--directory=d', 'Auto download directory') do |d|
|
19
|
+
options[:directory] = d
|
20
|
+
end
|
18
21
|
end.parse!
|
19
22
|
|
20
|
-
TorS::Search.new(options[:search], options[:provider] || 'katcr', options[:auto] || false)
|
21
|
-
end
|
23
|
+
TorS::Search.new(options[:search], options[:provider] || 'katcr', options[:auto] || false, options[:directory] || Dir.pwd)
|
24
|
+
end
|