tors 0.3.2 → 0.4.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: 3b01df74d9ebdef51e46ede758d4b144e8a81beb
4
- data.tar.gz: 333697b0e6ce94ce7d71ff36ee34d3531cb0f2f7
3
+ metadata.gz: dbc41cecac6500bfa91947abab8ebfd9f0ab8658
4
+ data.tar.gz: f49142eb95de177576f23ee3fbf9b14d5294cab3
5
5
  SHA512:
6
- metadata.gz: a310371c00409519df7190cb6cd4df7087d073d9f72dee140a95b1288b8e94d4a22e69e6b0120563b6a6cdba9cdf73a4da488f82bbb93c62d19f48604f651b38
7
- data.tar.gz: 21632d35679252bc8c90c21b97f5d8af1c2f6cc5c689cc2f02d92e45b293336977c280bc2c3b5fc82df3fa0be4151a4c7b54bc2d85ba84121a7194f3c4731d84
6
+ metadata.gz: 1e03556f83b022ad8ee04bfd5efd0261ba4c3e0a6281fdec84e79e4e2ce4279fa5886392efca35a76983e3d9f0feeab232287d395d31bfd319fd2cf604ce72fd
7
+ data.tar.gz: 62ceb765aff677e8d114ba5f5ffbf89c0d0821d43a15b6eb1e669cad81563707e2701ad05d94b37f10ec998cbe2995291d7484113eea1882945353b3d0d3c0fc
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
 
32
32
  Open your terminal and run this command:
33
33
 
34
- $ tors -s 'game of thrones'
34
+ $ tors -s 'ubuntu'
35
35
 
36
36
  It will list torrents ordered descending by seeder from **katcr**.
37
37
 
@@ -45,24 +45,25 @@ Yep, there is a few provider option.
45
45
 
46
46
  | Provider | Status | Problems |
47
47
  |:------------------|:------:|:---------|
48
- | katcr | ✅ | - |
48
+ | katcr | ✅ | - |
49
49
  | rarbg | ✅ | Slow Connection, Threat defensing |
50
- | thepiratebay | ✅ | Only Magnet |
51
- | extratorrent | ✅ | Slow Connection |
50
+ | thepiratebay | ✅ | Only Magnet |
51
+ | extratorrent | ✅ | Slow Connection |
52
52
  | 1337x | ✅ | Connection N+1 |
53
- | zooqle | ✅ | Skipping some torrents |
54
- | torrentfunk | ☑️ | 🙈 |
55
- | limetorrents | ☑️ | 🙈 |
53
+ | zooqle | ✅ | Skipping some torrents |
54
+ | zamunda | | Require authentication |
55
+ | torrentfunk | ☑️ | 🙈 |
56
+ | limetorrents | ☑️ | 🙈 |
56
57
 
57
58
  Use `-p PROVIDER` flag for scrape another providers.
58
59
 
59
- $ tors -s 'game of thrones' -p thepiratebay
60
+ $ tors -s 'ubuntu' -p thepiratebay
60
61
 
61
62
  And then It will ask for **which torrent you want to download?** You can answer with a torrent number seen on list.
62
63
 
63
64
  You can use `-a` or `--auto-download` flag for automatically download the best torrent. Example:
64
65
 
65
- $ tors -s 'game of thrones' -p 1337x -a
66
+ $ tors -s 'ubuntu' -p 1337x -a
66
67
 
67
68
  You can use `-d TARGET` flag for set destination storage path. Example:
68
69
 
@@ -72,17 +73,17 @@ And you can list all active providers and usage instructions with `-h` or `--hel
72
73
 
73
74
  $ tors -h
74
75
  Usage: tors [options]
75
- -h, --help Show usage instructions
76
- -s, --search=s Search term [SEARCH]
77
- -d, --directory=d Destination path for download torrent [DIRECTORY]
78
- -p, --provider=p Provider name [PROVIDER]
79
- -l, --list-providers List providers
80
- -a, --auto-download Auto download best choice
81
- -o, --open Open torrent after downloading
82
-
83
-
84
-
85
- [![See it in action](https://asciinema.org/a/No1Zdfk3gYoCYdGb2XUdFaUyS.png)](https://asciinema.org/a/No1Zdfk3gYoCYdGb2XUdFaUyS)
76
+ -h, --help Show usage instructions
77
+ -s, --search=s Search term [SEARCH]
78
+ -d, --directory=d Destination path for downloaded torrent [DIRECTORY]
79
+ -p, --provider=p Provider name [PROVIDER]
80
+ -u, --username=u Username for authentication
81
+ -w, --password=p Password for authentication
82
+ -l, --list-providers List providers
83
+ -a, --auto-download Auto download best choice
84
+ -o, --open Open torrent after downloading
85
+
86
+ [![See it in action](https://asciinema.org/a/lxRQTTiTSUXVhD3dpzIwCcIs2.png)](https://asciinema.org/a/lxRQTTiTSUXVhD3dpzIwCcIs2)
86
87
 
87
88
  ## Development
88
89
 
@@ -19,10 +19,20 @@ module TorS
19
19
  opts.on('-p=p', '--provider=p', 'Provider name [PROVIDER]') do |p|
20
20
  options[:provider] = p
21
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
22
28
  opts.on('-l', '--list-providers', 'List providers') do |_l|
23
- Dir[File.expand_path('providers/*.yml')].each do |f|
24
- puts '- ' + File.basename(f).split('.').first
25
- end
29
+ puts '- 1337x'
30
+ puts '- extratorrent'
31
+ puts '- katcr'
32
+ puts '- rarbg'
33
+ puts '- thepiratebay'
34
+ puts '- zamunda'
35
+ puts '- zooqle'
26
36
  abort
27
37
  end
28
38
  opts.on('-a', '--auto-download', 'Auto download best choice') do
@@ -37,6 +47,8 @@ module TorS
37
47
  end.parse!
38
48
 
39
49
  tors = TorS::Search.new(options[:provider] || 'katcr') do |ts|
50
+ ts.username = options[:username]
51
+ ts.password = options[:password]
40
52
  ts.query = options[:search]
41
53
  ts.auto = options[:auto] || false
42
54
  ts.directory = options[:directory] || Dir.pwd
@@ -1,13 +1,14 @@
1
1
  require 'yaml'
2
2
  require 'net/http'
3
3
  require 'nokogiri'
4
+ require 'mechanize'
4
5
  require 'open-uri'
5
6
  require 'tty-table'
6
7
  require 'tty-prompt'
7
8
 
8
9
  module TorS
9
10
  class Search
10
- attr_accessor :query, :from, :auto, :directory, :open_torrent
11
+ attr_accessor :query, :from, :username, :password, :directory, :auto, :open_torrent
11
12
 
12
13
  def initialize(from = 'katcr')
13
14
  @from = from
@@ -32,12 +33,16 @@ module TorS
32
33
  end
33
34
 
34
35
  def scrape
35
- @url = @provider['url'].gsub(/%{(\w+)}/, @query ? @query.tr(' ', '+') : '')
36
+ @url = URI.encode(@provider['url'].gsub(/%{(\w+)}/, @query ? @query : ''))
36
37
  @page = Nokogiri::HTML(open(@url))
37
38
 
39
+ if @provider['authenticate']
40
+ authenticate
41
+ end
42
+
38
43
  if @page.css(@provider['scrape']['selector']).empty?
39
44
  if threat_defence @page
40
- puts "😰 Sorry, I think you are banned from #{from}. There is a threat defense redirection."
45
+ puts "😰 Sorry, I think you are banned from #{from}. There is a threat defense redirection.".red
41
46
  end
42
47
 
43
48
  puts 'Please check this url is works : ' + @url
@@ -47,7 +52,7 @@ module TorS
47
52
  @rows = []
48
53
  @downloads = []
49
54
 
50
- puts 'Scraping...'
55
+ puts 'Scraping...'.blue
51
56
 
52
57
  key = 0
53
58
  @page.css(@provider['scrape']['selector']).each do |row|
@@ -121,10 +126,15 @@ module TorS
121
126
  target_file_name = choice[:name].tr("\n", ' ').squeeze(' ').strip + '.torrent'
122
127
  puts 'Downloading ' + target_file_name
123
128
 
124
- source = Net::HTTP.get(URI.parse(choice[:url]))
125
- target_file = File.join(@directory, target_file_name)
129
+ target_file = File.join(@directory, target_file_name)
126
130
 
127
- File.write(target_file, source)
131
+ if @provider['authenticate']
132
+ source = @mechanize.get URI.parse(choice[:url])
133
+ source.save_as(target_file)
134
+ else
135
+ source = Net::HTTP.get(URI.parse(choice[:url]))
136
+ File.write(target_file, source)
137
+ end
128
138
  rescue IOError => e
129
139
  # FIXME: what about HTTP errors? Net::HTTP throws a number of
130
140
  # exceptions. It would be wise to use another HTTP library for this
@@ -140,6 +150,29 @@ module TorS
140
150
  end
141
151
  end
142
152
 
153
+ # FIXME: This must be refactored
154
+ # Nokogiri dependency is not necessary with mechanize
155
+ # (Mechanize already dependent to nokogiri)
156
+ # And mechanize has all features of nokogiri.
157
+ def authenticate
158
+ @mechanize = Mechanize.new
159
+ puts '⚠ Trying authentication'.cyan
160
+
161
+ @page = @mechanize.get @url
162
+ login_form = @page.form_with(name: @provider['authenticate']['form_name']) do |login|
163
+ login[@provider['authenticate']['username_input']] = @username
164
+ login[@provider['authenticate']['password_input']] = @password
165
+ end
166
+ @page = login_form.submit
167
+
168
+ if @page.css(@provider['scrape']['selector']).empty?
169
+ puts 'Login failed with your credentials!'.red
170
+ abort
171
+ end
172
+
173
+ puts '✔ Authentication successfull'.green
174
+ end
175
+
143
176
  def threat_defence(page)
144
177
  return false unless page.text =~ /threat_defence.php/
145
178
  true
@@ -1,3 +1,3 @@
1
1
  module TorS
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -0,0 +1,16 @@
1
+ name: 'zamunda'
2
+ url: "http://zamunda.net/bananas?c42=1&c25=1&c35=1&c46=1&c20=1&c19=1&c5=1&c24=1&c31=1&c28=1&c7=1&c33=1&c39=1&c4=1&c21=1&c17=1&c40=1&c12=1&c54=1&c6=1&c30=1&c29=1&c51=1&c34=1&c38=1&c1=1&c22=1&c43=1&c41=1&c36=1&c52=1&c53=1&c26=1&c23=1&c32=1&c37=1&search=%{query}&incldead=&field=name&sort=9&type=desc"
3
+ download_prefix: "http://zamunda.net"
4
+ authenticate:
5
+ form_name: 'login'
6
+ username_input: 'username'
7
+ password_input: 'password'
8
+ scrape:
9
+ selector: '.video-list > .item'
10
+ data:
11
+ name: '.title_genre h2 a'
12
+ category: '.video-meta > div:nth-child(5) a'
13
+ download: '.video-meta > div:nth-child(1) > a'
14
+ size: '.video-meta div:nth-child(1) a font:last-child'
15
+ seed: '.video-meta > div:nth-child(8) a:nth-child(9)'
16
+ leech: '.video-meta > div:nth-child(8) a:nth-child(10)'
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ['lib']
25
25
 
26
26
  spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.0'
27
+ spec.add_dependency 'mechanize', '~> 2.7.5'
27
28
  spec.add_dependency 'colorize', '~> 0.8.1'
28
29
  spec.add_dependency 'tty-table', '~> 0.8.0'
29
30
  spec.add_dependency 'tty-prompt', '~> 0.13.1'
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.2
4
+ version: 0.4.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-01 00:00:00.000000000 Z
11
+ date: 2017-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.8.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: mechanize
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.7.5
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.7.5
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: colorize
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +156,7 @@ files:
142
156
  - providers/katcr.yml
143
157
  - providers/rarbg.yml
144
158
  - providers/thepiratebay.yml
159
+ - providers/zamunda.yml
145
160
  - providers/zooqle.yml
146
161
  - tors.gemspec
147
162
  homepage: https://github.com/muratbsts/tors
@@ -164,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
179
  version: '0'
165
180
  requirements: []
166
181
  rubyforge_project:
167
- rubygems_version: 2.6.12
182
+ rubygems_version: 2.6.13
168
183
  signing_key:
169
184
  specification_version: 4
170
185
  summary: Yet another torrent searching application for your command line.