subdb-cli 0.1.1 → 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/README.md +2 -1
- data/exe/subdb +32 -23
- data/lib/subdb/cli.rb +16 -3
- data/lib/subdb/cli/version.rb +1 -1
- 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: 7559d42447598fcce6945f6a1cd5bb4f7f448ca5
|
4
|
+
data.tar.gz: de5e8bd3e157d42820dd7e97a222d39b37eb4988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f4c7ac96f0cd0ca796d9fd1add056ca42c2ada8402996a0525950465300751a5b2a2c0721ad510c6cc40efb983319f3100f1758767af757b849fef8de3f0f0b
|
7
|
+
data.tar.gz: 019013892ee90b4b2b3a88de9c14410a223939586322cad0f0f4ba734f283540affddb7ba5f896b76ddd8c4656093375513b3245beaa8e3adce7ea13923de176
|
data/README.md
CHANGED
@@ -5,8 +5,9 @@ Library and client to download subtitles from http://thesubdb.com.
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
subdb [file]
|
8
|
+
|
8
9
|
subdb [file] -l [lang]
|
9
10
|
|
10
11
|
## Contributing
|
11
12
|
|
12
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/carlosparamio/subdb-cli. 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.
|
13
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/carlosparamio/subdb-cli. 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.
|
data/exe/subdb
CHANGED
@@ -2,35 +2,44 @@
|
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "subdb/cli"
|
5
|
-
require "optparse"
|
6
5
|
|
7
|
-
|
6
|
+
def display_help
|
7
|
+
puts <<-USAGE
|
8
|
+
Usage:
|
9
|
+
subdb download [video_file_path] [languages]
|
10
|
+
subdb upload [video_file_path] [subtitles_file_path]
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
[languages] is a comma separated list of desired languages in priority order to download (default: en)
|
13
|
+
USAGE
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
opts.banner = "Usage: subdb [options] file_path"
|
16
|
+
action = ARGV[0]
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
begin
|
19
|
+
case action
|
20
|
+
when "download"
|
21
|
+
video_file_path = ARGV[1]
|
22
|
+
languages = ARGV[2] || "en"
|
19
23
|
|
20
|
-
|
21
|
-
puts opts
|
22
|
-
exit
|
23
|
-
end
|
24
|
-
end.parse!
|
24
|
+
display_help && exit if video_file_path.nil?
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
Subdb::Cli.new.download(video_file_path, languages)
|
27
|
+
puts "Subtitles file downloaded."
|
28
|
+
when "upload"
|
29
|
+
video_file_path = ARGV[1]
|
30
|
+
subtitles_file_path = ARGV[2]
|
31
|
+
|
32
|
+
display_help && exit if video_file_path.nil? || subtitles_file_path.nil?
|
33
|
+
|
34
|
+
Subdb::Cli.new.upload(video_file_path, subtitles_file_path)
|
35
|
+
puts "Subtitles file uploaded."
|
36
|
+
else
|
37
|
+
display_help
|
38
|
+
end
|
28
39
|
rescue Subdb::Cli::FileNotFound
|
29
40
|
puts "File not found"
|
30
|
-
exit
|
31
41
|
rescue Subdb::Cli::SubtitlesNotFound
|
32
|
-
puts "Subtitles file not found at Subdb database for the given language"
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
puts "Subtitles file downloaded"
|
42
|
+
puts "Subtitles file not found at Subdb database for the given language."
|
43
|
+
rescue SubtitleUploadError
|
44
|
+
puts "There was a problem uploading the subtitles file."
|
45
|
+
end
|
data/lib/subdb/cli.rb
CHANGED
@@ -8,8 +8,9 @@ module Subdb
|
|
8
8
|
BASE_URL = 'http://api.thesubdb.com/'
|
9
9
|
READSIZE = 64 * 1024
|
10
10
|
|
11
|
-
FileNotFound
|
12
|
-
SubtitlesNotFound
|
11
|
+
FileNotFound = Class.new(StandardError)
|
12
|
+
SubtitlesNotFound = Class.new(StandardError)
|
13
|
+
SubtitleUploadError = Class.new(StandardError)
|
13
14
|
|
14
15
|
def download(file_path, language)
|
15
16
|
response = client.get('/', {
|
@@ -25,6 +26,18 @@ module Subdb
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
|
30
|
+
def upload(video_file_path, subtitles_file_path)
|
31
|
+
response = client.post('/', {
|
32
|
+
action: 'upload',
|
33
|
+
hash: hash_for(video_file_path)
|
34
|
+
}) do |request|
|
35
|
+
request.body = File.read(subtitles_file_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
raise SubtitleUploadError unless response.status == 200
|
39
|
+
end
|
40
|
+
|
28
41
|
private
|
29
42
|
|
30
43
|
def srt_file_for(file_path)
|
@@ -57,7 +70,7 @@ module Subdb
|
|
57
70
|
end
|
58
71
|
|
59
72
|
def user_agent
|
60
|
-
"SubDB/1.0 (subdb-cli
|
73
|
+
"SubDB/1.0 (subdb-cli/#{VERSION}; https://github.com/carlosparamio/subdb-cli)"
|
61
74
|
end
|
62
75
|
|
63
76
|
end
|
data/lib/subdb/cli/version.rb
CHANGED