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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7a96d354ee69c0ca206a4bad63b4307711f01a1
4
- data.tar.gz: dbe9b45a170220c8b3700787472120d1d02d2581
3
+ metadata.gz: 95eea10bc57ad0710b1f7fcd62eb7c4e81376256
4
+ data.tar.gz: b92ad9855bac1ba0072a8d1f5738f6252cc06d83
5
5
  SHA512:
6
- metadata.gz: b60d64063afb943c9fc88513f108e2bd4728c598a14edf38bc02c219c8716297560e9160f1ae20962e83ecc4ff6958ac7286a2b2922dbfff313aa98f72a36bae
7
- data.tar.gz: 4f58d6f8d829145e4658fc80a0a72dc8bb75b59a240530baf1e358be81b23f5996d26d4e3ae6afa57a5df3fdc2beefc318ca6a6489dd7f8d517b9d795fc65e0a
6
+ metadata.gz: 703eeacae5a37dc895a43e97193eae58dea34bda9f4c1ccc2325ecc122d566d28b195d518318e2befa7dec131b486661b2daf194ca328520495d61f00f51d539
7
+ data.tar.gz: 144829b12bb8a24f7f955d55d94699e828c490844b3cbb2fdb951d4c530b672ea3206b094eda83a88b48ce6367894cc84ee0baa6da48366c2b16b17177b7001c
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
13
 
14
- /.idea
14
+ /.idea
15
+ /*.gem
data/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
- sudo: false
2
1
  language: ruby
2
+ script: bundle exec rspec
3
3
  rvm:
4
4
  - 2.4.0
5
- before_install: gem install bundler -v 1.15.3
5
+ - ruby-head
6
+ matrix:
7
+ fast_finish: true
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # TorS
2
2
 
3
- Yet another torrent searching application for your command line.
3
+ [![Licence](https://img.shields.io/github/license/muratbsts/tors.svg)](https://github.com/muratbsts/tors/blob/master/LICENCE)
4
+ [![Release](https://img.shields.io/github/release/muratbsts/tors.svg)](https://github.com/muratbsts/tors/releases)
5
+ [![Build](https://travis-ci.org/muratbsts/tors.svg?branch=master)](https://travis-ci.org/muratbsts/tors)
6
+ [![Issues](https://img.shields.io/github/issues/muratbsts/tors.svg)](https://github.com/muratbsts/tors/issues)
7
+ [![Pull Requests](https://img.shields.io/github/issues-pr/muratbsts/tors.svg)](https://github.com/muratbsts/tors/pulls)
8
+
9
+ [![Downloads](https://img.shields.io/gem/dt/tors.svg)](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
+ [![See it in action](https://asciinema.org/a/No1Zdfk3gYoCYdGb2XUdFaUyS.png)](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
- puts 'Downloading ' + choice[:name] + '.torrent'
101
- File.write(choice[:name] + '.torrent', Net::HTTP.get(URI.parse(choice[:url])))
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
@@ -1,3 +1,3 @@
1
1
  module TorS
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murat Bastas