tsearch-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +99 -0
- data/LICENSE.txt +20 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/tsearch +18 -0
- data/lib/tsearch.rb +6 -0
- data/lib/tsearch/cli.rb +59 -0
- data/lib/tsearch/command.rb +121 -0
- data/lib/tsearch/commands/search.rb +109 -0
- data/lib/tsearch/templates/search/.gitkeep +1 -0
- data/lib/tsearch/version.rb +3 -0
- data/tsearch.gemspec +29 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dd4845f0d936a66054bee75d69d22cdb9c2052091233e9ef1bcb6562032a538f
|
4
|
+
data.tar.gz: 2de8d051d5d4c0fff0d964fa1c7e66acfd8c9f3f819e8e744f56fbb31f69b8f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69ffaaf3788f525aa7926ac73a9a860d02cfafbb38410f0aa0988074309873af8afd2749c3c74f564e131d9d246639feb81aade28d0b45be539126cd3762ba40
|
7
|
+
data.tar.gz: 0604155505e066efbb2784a90a6a98fd341fd19f3086f276cf0844bb6419cbdcb27efd5b4b8adf4e01439b470f9fff828293c41a68420dbf5c3816b5594b99c5
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at caioramos97@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in tsearch.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "rake", "~> 12.0"
|
7
|
+
|
8
|
+
gem "rarbg", "~> 2.0"
|
9
|
+
|
10
|
+
gem "solargraph", "~> 0.40.2", :group => :development
|
11
|
+
|
12
|
+
gem "activesupport", "~> 6.1"
|
13
|
+
|
14
|
+
gem "rubocop", "~> 1.9", :group => :development
|
15
|
+
|
16
|
+
gem "byebug", "~> 11.1", :group => :development
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tsearch (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (6.1.1)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 1.6, < 2)
|
12
|
+
minitest (>= 5.1)
|
13
|
+
tzinfo (~> 2.0)
|
14
|
+
zeitwerk (~> 2.3)
|
15
|
+
ast (2.4.2)
|
16
|
+
backport (1.1.2)
|
17
|
+
benchmark (0.1.1)
|
18
|
+
byebug (11.1.3)
|
19
|
+
concurrent-ruby (1.1.8)
|
20
|
+
e2mmap (0.1.0)
|
21
|
+
faraday (1.3.0)
|
22
|
+
faraday-net_http (~> 1.0)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
ruby2_keywords
|
25
|
+
faraday-net_http (1.0.1)
|
26
|
+
i18n (1.8.7)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
jaro_winkler (1.5.4)
|
29
|
+
kramdown (2.3.0)
|
30
|
+
rexml
|
31
|
+
kramdown-parser-gfm (1.1.0)
|
32
|
+
kramdown (~> 2.0)
|
33
|
+
mini_portile2 (2.5.0)
|
34
|
+
minitest (5.14.3)
|
35
|
+
multipart-post (2.1.1)
|
36
|
+
nokogiri (1.11.1)
|
37
|
+
mini_portile2 (~> 2.5.0)
|
38
|
+
racc (~> 1.4)
|
39
|
+
parallel (1.20.1)
|
40
|
+
parser (3.0.0.0)
|
41
|
+
ast (~> 2.4.1)
|
42
|
+
racc (1.5.2)
|
43
|
+
rainbow (3.0.0)
|
44
|
+
rake (12.3.3)
|
45
|
+
rarbg (2.0.0)
|
46
|
+
faraday (~> 1.0)
|
47
|
+
regexp_parser (2.0.3)
|
48
|
+
reverse_markdown (2.0.0)
|
49
|
+
nokogiri
|
50
|
+
rexml (3.2.4)
|
51
|
+
rubocop (1.9.0)
|
52
|
+
parallel (~> 1.10)
|
53
|
+
parser (>= 3.0.0.0)
|
54
|
+
rainbow (>= 2.2.2, < 4.0)
|
55
|
+
regexp_parser (>= 1.8, < 3.0)
|
56
|
+
rexml
|
57
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
58
|
+
ruby-progressbar (~> 1.7)
|
59
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
60
|
+
rubocop-ast (1.4.1)
|
61
|
+
parser (>= 2.7.1.5)
|
62
|
+
ruby-progressbar (1.11.0)
|
63
|
+
ruby2_keywords (0.0.4)
|
64
|
+
solargraph (0.40.2)
|
65
|
+
backport (~> 1.1)
|
66
|
+
benchmark
|
67
|
+
bundler (>= 1.17.2)
|
68
|
+
e2mmap
|
69
|
+
jaro_winkler (~> 1.5)
|
70
|
+
kramdown (~> 2.3)
|
71
|
+
kramdown-parser-gfm (~> 1.1)
|
72
|
+
parser (~> 3.0)
|
73
|
+
reverse_markdown (>= 1.0.5, < 3)
|
74
|
+
rubocop (>= 0.52)
|
75
|
+
thor (~> 1.0)
|
76
|
+
tilt (~> 2.0)
|
77
|
+
yard (~> 0.9, >= 0.9.24)
|
78
|
+
thor (1.1.0)
|
79
|
+
tilt (2.0.10)
|
80
|
+
tzinfo (2.0.4)
|
81
|
+
concurrent-ruby (~> 1.0)
|
82
|
+
unicode-display_width (2.0.0)
|
83
|
+
yard (0.9.26)
|
84
|
+
zeitwerk (2.4.2)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
ruby
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
activesupport (~> 6.1)
|
91
|
+
byebug (~> 11.1)
|
92
|
+
rake (~> 12.0)
|
93
|
+
rarbg (~> 2.0)
|
94
|
+
rubocop (~> 1.9)
|
95
|
+
solargraph (~> 0.40.2)
|
96
|
+
tsearch!
|
97
|
+
|
98
|
+
BUNDLED WITH
|
99
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Caio Ramos
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Tsearch
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Install it yourself as:
|
6
|
+
|
7
|
+
$ gem install tsearch-cli
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```
|
12
|
+
Usage:
|
13
|
+
tsearch search
|
14
|
+
|
15
|
+
Options:
|
16
|
+
-h, [--help], [--no-help] # Display usage information
|
17
|
+
-s, [--string=STRING] # Search by string
|
18
|
+
-i, [--imdb=IMDB] # Search by IMDb id
|
19
|
+
-t, [--tvdb=TVDB] # Search by TVDB id
|
20
|
+
-m, [--themoviedb=THEMOVIEDB] # Search by The Movie DB id
|
21
|
+
-c, [--category=CATEGORY] # Filter results by category
|
22
|
+
# Possible values: movies, tv, music, games, software, xxx
|
23
|
+
-l, [--limit=N] # Limit results number
|
24
|
+
# Default: 25
|
25
|
+
# Possible values: 25, 50, 100
|
26
|
+
[--min-seeders=N] # Filter results by minimum seeders
|
27
|
+
[--min-leechers=N] # Filter results by minimum leechers
|
28
|
+
[--ranked], [--no-ranked] # Include/exclude unranked torrents
|
29
|
+
# Default: true
|
30
|
+
[--sort=SORT] # Sort results
|
31
|
+
# Default: seeders
|
32
|
+
# Possible values: last, seeders, leechers
|
33
|
+
-v, [--verbose], [--no-verbose] # Verbose output
|
34
|
+
|
35
|
+
Description:
|
36
|
+
You will need to provide at least one of the search options: string, imdb, tvdb, themoviedb
|
37
|
+
```
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/caiohsramos/tsearch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/caiohsramos/tsearch/blob/master/CODE_OF_CONDUCT.md).
|
48
|
+
|
49
|
+
|
50
|
+
## Code of Conduct
|
51
|
+
|
52
|
+
Everyone interacting in the Tsearch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tsearch/blob/master/CODE_OF_CONDUCT.md).
|
53
|
+
|
54
|
+
## Copyright
|
55
|
+
|
56
|
+
Copyright (c) 2021 Caio Ramos. See [MIT License](LICENSE.txt) for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tsearch"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/tsearch
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib_path = File.expand_path('../lib', __dir__)
|
5
|
+
$:.unshift(lib_path) if !$:.include?(lib_path)
|
6
|
+
require 'tsearch/cli'
|
7
|
+
|
8
|
+
Signal.trap('INT') do
|
9
|
+
warn("\n#{caller.join("\n")}: interrupted")
|
10
|
+
exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Tsearch::CLI.start
|
15
|
+
rescue Tsearch::CLI::Error => err
|
16
|
+
puts "ERROR: #{err.message}"
|
17
|
+
exit 1
|
18
|
+
end
|
data/lib/tsearch.rb
ADDED
data/lib/tsearch/cli.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Tsearch
|
6
|
+
# Handle the application command line parsing
|
7
|
+
# and the dispatch to various command objects
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class CLI < Thor
|
11
|
+
# Error raised by this runner
|
12
|
+
Error = Class.new(StandardError)
|
13
|
+
|
14
|
+
def self.exit_on_failure?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'version', 'tsearch version'
|
19
|
+
def version
|
20
|
+
require_relative 'version'
|
21
|
+
puts "v#{Tsearch::VERSION}"
|
22
|
+
end
|
23
|
+
map %w[--version -V] => :version
|
24
|
+
|
25
|
+
desc 'search', 'searches a torrent with the given options'
|
26
|
+
long_desc <<-DESC
|
27
|
+
You will need to provide at least one of the search options: string, imdb, tvdb, themoviedb
|
28
|
+
DESC
|
29
|
+
method_option :help, aliases: '-h', type: :boolean,
|
30
|
+
desc: 'Display usage information'
|
31
|
+
method_option :string, type: :string, desc: 'Search by string', aliases: '-s'
|
32
|
+
method_option :imdb, type: :string, desc: 'Search by IMDb id', aliases: '-i'
|
33
|
+
method_option :tvdb, type: :string, desc: 'Search by TVDB id', aliases: '-t'
|
34
|
+
method_option :themoviedb, type: :string, desc: 'Search by The Movie DB id', aliases: '-m'
|
35
|
+
method_option :category, type: :string, desc: 'Filter results by category',
|
36
|
+
enum: %w[movies tv music games software xxx], aliases: '-c'
|
37
|
+
method_option :limit, type: :numeric, desc: 'Limit results number', enum: [25, 50, 100], default: 25,
|
38
|
+
aliases: '-l'
|
39
|
+
method_option :min_seeders, type: :numeric, desc: 'Filter results by minimum seeders'
|
40
|
+
method_option :min_leechers, type: :numeric, desc: 'Filter results by minimum leechers'
|
41
|
+
method_option :ranked, type: :boolean, desc: 'Include/exclude unranked torrents', default: true
|
42
|
+
method_option :sort, type: :string, desc: 'Sort results', enum: %w[last seeders leechers],
|
43
|
+
default: 'seeders'
|
44
|
+
method_option :verbose, type: :boolean, desc: 'Verbose output', aliases: '-v'
|
45
|
+
def search
|
46
|
+
if options[:help]
|
47
|
+
invoke :help, ['search']
|
48
|
+
else
|
49
|
+
if options[:string].nil? && options[:imdb].nil? && options[:tvdb].nil? && options[:themoviedb].nil?
|
50
|
+
raise RequiredArgumentMissingError,
|
51
|
+
'At least one of the search options must be provided: string, imdb, tvdb, themoviedb'
|
52
|
+
end
|
53
|
+
|
54
|
+
require_relative 'commands/search'
|
55
|
+
Tsearch::Commands::Search.new(options).execute
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Tsearch
|
6
|
+
class Command
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :command, :run
|
10
|
+
|
11
|
+
# Execute this command
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
def execute(*)
|
15
|
+
raise(
|
16
|
+
NotImplementedError,
|
17
|
+
"#{self.class}##{__method__} must be implemented"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
# The external commands runner
|
22
|
+
#
|
23
|
+
# @see http://www.rubydoc.info/gems/tty-command
|
24
|
+
#
|
25
|
+
# @api public
|
26
|
+
def command(**options)
|
27
|
+
require 'tty-command'
|
28
|
+
TTY::Command.new(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# The cursor movement
|
32
|
+
#
|
33
|
+
# @see http://www.rubydoc.info/gems/tty-cursor
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
def cursor
|
37
|
+
require 'tty-cursor'
|
38
|
+
TTY::Cursor
|
39
|
+
end
|
40
|
+
|
41
|
+
# Open a file or text in the user's preferred editor
|
42
|
+
#
|
43
|
+
# @see http://www.rubydoc.info/gems/tty-editor
|
44
|
+
#
|
45
|
+
# @api public
|
46
|
+
def editor
|
47
|
+
require 'tty-editor'
|
48
|
+
TTY::Editor
|
49
|
+
end
|
50
|
+
|
51
|
+
# File manipulation utility methods
|
52
|
+
#
|
53
|
+
# @see http://www.rubydoc.info/gems/tty-file
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def generator
|
57
|
+
require 'tty-file'
|
58
|
+
TTY::File
|
59
|
+
end
|
60
|
+
|
61
|
+
# Terminal output paging
|
62
|
+
#
|
63
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
def pager(**options)
|
67
|
+
require 'tty-pager'
|
68
|
+
TTY::Pager.new(options)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Terminal platform and OS properties
|
72
|
+
#
|
73
|
+
# @see http://www.rubydoc.info/gems/tty-pager
|
74
|
+
#
|
75
|
+
# @api public
|
76
|
+
def platform
|
77
|
+
require 'tty-platform'
|
78
|
+
TTY::Platform.new
|
79
|
+
end
|
80
|
+
|
81
|
+
# The interactive prompt
|
82
|
+
#
|
83
|
+
# @see http://www.rubydoc.info/gems/tty-prompt
|
84
|
+
#
|
85
|
+
# @api public
|
86
|
+
def prompt(**options)
|
87
|
+
require 'tty-prompt'
|
88
|
+
TTY::Prompt.new(options)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get terminal screen properties
|
92
|
+
#
|
93
|
+
# @see http://www.rubydoc.info/gems/tty-screen
|
94
|
+
#
|
95
|
+
# @api public
|
96
|
+
def screen
|
97
|
+
require 'tty-screen'
|
98
|
+
TTY::Screen
|
99
|
+
end
|
100
|
+
|
101
|
+
# The unix which utility
|
102
|
+
#
|
103
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
104
|
+
#
|
105
|
+
# @api public
|
106
|
+
def which(*args)
|
107
|
+
require 'tty-which'
|
108
|
+
TTY::Which.which(*args)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Check if executable exists
|
112
|
+
#
|
113
|
+
# @see http://www.rubydoc.info/gems/tty-which
|
114
|
+
#
|
115
|
+
# @api public
|
116
|
+
def exec_exist?(*args)
|
117
|
+
require 'tty-which'
|
118
|
+
TTY::Which.exist?(*args)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require 'rarbg'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/core_ext/hash'
|
7
|
+
require 'byebug'
|
8
|
+
|
9
|
+
module Tsearch
|
10
|
+
module Commands
|
11
|
+
class Search < Tsearch::Command
|
12
|
+
CATEGORY_MAP = {
|
13
|
+
'movies': [14, 48, 17, 44, 45, 47, 50, 51, 52, 42, 46],
|
14
|
+
'tv': [18, 41, 49],
|
15
|
+
'music': [23, 25],
|
16
|
+
'games': [27, 28, 40, 53, 32],
|
17
|
+
'software': [33],
|
18
|
+
'xxx': [4]
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
def initialize(options)
|
22
|
+
@options = options
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(_input: $stdin, output: $stdout)
|
26
|
+
results = search_torrent.map(&:deep_symbolize_keys)
|
27
|
+
if results.empty?
|
28
|
+
output.puts 'No results were found, please try again'
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
display_results(results.reverse, output)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def rarbg
|
38
|
+
@rarbg ||= RARBG::API.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def search_torrent
|
42
|
+
query = {
|
43
|
+
string: string,
|
44
|
+
imdb: imdb,
|
45
|
+
tvdb: tvdb,
|
46
|
+
category: CATEGORY_MAP[category],
|
47
|
+
limit: limit,
|
48
|
+
format: :json_extended,
|
49
|
+
min_seeders: min_seeders,
|
50
|
+
min_leechers: min_leechers,
|
51
|
+
ranked: ranked,
|
52
|
+
sort: sort
|
53
|
+
}.compact
|
54
|
+
rarbg.search(query)
|
55
|
+
end
|
56
|
+
|
57
|
+
def format_link(url, name = 'Link')
|
58
|
+
"\e]8;;#{url}\a#{name}\e]8;;\a (CTRL+Click)"
|
59
|
+
end
|
60
|
+
|
61
|
+
def filesize(size)
|
62
|
+
units = ['B', 'KB', 'MB', 'GB', 'TB', 'Pb', 'EB']
|
63
|
+
|
64
|
+
return '0.0 B' if size == 0
|
65
|
+
|
66
|
+
exp = (Math.log(size) / Math.log(1024)).to_i
|
67
|
+
exp += 1 if size.to_f / 1024**exp >= 1024 - 0.05
|
68
|
+
exp = 6 if exp > 6
|
69
|
+
|
70
|
+
'%.1f %s' % [size.to_f / 1024**exp, units[exp]]
|
71
|
+
end
|
72
|
+
|
73
|
+
def display_results(results, output)
|
74
|
+
results.each do |result|
|
75
|
+
output.puts "Name: #{result[:title]}"
|
76
|
+
output.puts "Category: #{result[:category]}"
|
77
|
+
output.puts "Magnet: #{format_link(result[:download])}"
|
78
|
+
unless verbose
|
79
|
+
output.puts
|
80
|
+
next
|
81
|
+
end
|
82
|
+
|
83
|
+
output.puts "Seeders: #{result[:seeders]}"
|
84
|
+
output.puts "Leechers: #{result[:leechers]}"
|
85
|
+
output.puts "Filesize: #{filesize(result[:size])}"
|
86
|
+
output.puts "Ranked: #{result[:ranked] == 1 ? 'Yes' : 'No'}"
|
87
|
+
output.puts "Info page: #{format_link(result[:info_page])}"
|
88
|
+
output.puts
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def method_missing(key, *args, &block)
|
93
|
+
super unless %i[string
|
94
|
+
imdb
|
95
|
+
tvdb
|
96
|
+
themoviedb
|
97
|
+
category
|
98
|
+
limit
|
99
|
+
min_seeders
|
100
|
+
min_leechers
|
101
|
+
ranked
|
102
|
+
sort
|
103
|
+
verbose].include?(key)
|
104
|
+
|
105
|
+
@options[key]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
data/tsearch.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/tsearch/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "tsearch-cli"
|
5
|
+
spec.license = "MIT"
|
6
|
+
spec.version = Tsearch::VERSION
|
7
|
+
spec.authors = ["Caio Ramos"]
|
8
|
+
spec.email = ["caioramos97@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = 'Ruby CLI for RARBG torrent search'
|
11
|
+
|
12
|
+
spec.homepage = "https://github.com/caiohsramos/tsearch"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/caiohsramos/tsearch"
|
19
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tsearch-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caio Ramos
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- caioramos97@gmail.com
|
16
|
+
executables:
|
17
|
+
- tsearch
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- exe/tsearch
|
32
|
+
- lib/tsearch.rb
|
33
|
+
- lib/tsearch/cli.rb
|
34
|
+
- lib/tsearch/command.rb
|
35
|
+
- lib/tsearch/commands/search.rb
|
36
|
+
- lib/tsearch/templates/search/.gitkeep
|
37
|
+
- lib/tsearch/version.rb
|
38
|
+
- tsearch.gemspec
|
39
|
+
homepage: https://github.com/caiohsramos/tsearch
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
homepage_uri: https://github.com/caiohsramos/tsearch
|
44
|
+
source_code_uri: https://github.com/caiohsramos/tsearch
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.7.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.1.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Ruby CLI for RARBG torrent search
|
64
|
+
test_files: []
|