subdb-cli 0.2.0 → 0.2.1
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/exe/subdb +6 -2
- data/lib/subdb/cli.rb +20 -16
- data/lib/subdb/cli/version.rb +1 -1
- data/subdb-cli.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5ad8ef2b99c52f9e3742897b0b266be010d52c7
|
4
|
+
data.tar.gz: b75e627f2306e3cfbd03e916d7940469af4592ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24f697bbc1ce268933af2554c17375966c254d5ae7fabe32758f5adb91b9ee2c1f81e05993d3bab013297e4d0c87de29ae7aefd737e7987258618474e507c60f
|
7
|
+
data.tar.gz: 82187aa1d0fc4a8a0cfe220f1bcd9562814b5fc1af3a5f644fa302c0b13f8d289a11487a81b694c96bf2e3d6f675ccda17a3fea4bcb000fbe900da88f5f4d569
|
data/exe/subdb
CHANGED
@@ -4,13 +4,15 @@ require "bundler/setup"
|
|
4
4
|
require "subdb/cli"
|
5
5
|
|
6
6
|
def display_help
|
7
|
-
puts <<-
|
7
|
+
puts <<-HELP
|
8
|
+
subdb-cli v#{Subdb::Cli::VERSION}
|
9
|
+
|
8
10
|
Usage:
|
9
11
|
subdb download [video_file_path] [languages]
|
10
12
|
subdb upload [video_file_path] [subtitles_file_path]
|
11
13
|
|
12
14
|
[languages] is a comma separated list of desired languages in priority order to download (default: en)
|
13
|
-
|
15
|
+
HELP
|
14
16
|
end
|
15
17
|
|
16
18
|
action = ARGV[0]
|
@@ -38,6 +40,8 @@ begin
|
|
38
40
|
end
|
39
41
|
rescue Subdb::Cli::FileNotFound
|
40
42
|
puts "File not found"
|
43
|
+
rescue Subdb::Cli::ErrorCalculatingHash
|
44
|
+
puts "Error calculating hash for video file"
|
41
45
|
rescue Subdb::Cli::SubtitlesNotFound
|
42
46
|
puts "Subtitles file not found at Subdb database for the given language."
|
43
47
|
rescue SubtitleUploadError
|
data/lib/subdb/cli.rb
CHANGED
@@ -8,32 +8,36 @@ module Subdb
|
|
8
8
|
BASE_URL = 'http://api.thesubdb.com/'
|
9
9
|
READSIZE = 64 * 1024
|
10
10
|
|
11
|
-
FileNotFound
|
12
|
-
|
13
|
-
|
11
|
+
FileNotFound = Class.new(StandardError)
|
12
|
+
ErrorCalculatingHash = Class.new(StandardError)
|
13
|
+
SubtitlesNotFound = Class.new(StandardError)
|
14
|
+
SubtitleUploadError = Class.new(StandardError)
|
15
|
+
|
16
|
+
def download(video_file_path, language)
|
17
|
+
raise FileNotFound unless File.exists?(video_file_path)
|
14
18
|
|
15
|
-
def download(file_path, language)
|
16
19
|
response = client.get('/', {
|
17
20
|
action: 'download',
|
18
21
|
language: language,
|
19
|
-
hash: hash_for(
|
22
|
+
hash: hash_for(video_file_path)
|
20
23
|
})
|
21
24
|
|
22
25
|
raise SubtitleNotFound unless response.status == 200
|
23
26
|
|
24
|
-
File.open(srt_file_for(
|
25
|
-
|
27
|
+
File.open(srt_file_for(video_file_path), "w") do |srt_file|
|
28
|
+
srt_file.write(response.body)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
32
|
|
30
33
|
def upload(video_file_path, subtitles_file_path)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
raise FileNotFound unless File.exists?(video_file_path)
|
35
|
+
raise FileNotFound unless File.exists?(subtitles_file_path)
|
36
|
+
|
37
|
+
response = client.post('/?action=upload', {
|
38
|
+
hash: hash_for(video_file_path),
|
39
|
+
file: Faraday::UploadIO.new(subtitles_file_path, 'application/octet-stream')
|
40
|
+
})
|
37
41
|
|
38
42
|
raise SubtitleUploadError unless response.status == 200
|
39
43
|
end
|
@@ -47,14 +51,14 @@ module Subdb
|
|
47
51
|
end
|
48
52
|
|
49
53
|
def hash_for(file_path)
|
50
|
-
file = File.open(file_path)
|
54
|
+
file = File.open(file_path, "r")
|
51
55
|
buffer = file.read(READSIZE)
|
52
56
|
file.seek(-READSIZE, IO::SEEK_END)
|
53
57
|
buffer += file.read(READSIZE)
|
54
58
|
file.close
|
55
59
|
md5_for(buffer)
|
56
|
-
rescue
|
57
|
-
raise
|
60
|
+
rescue
|
61
|
+
raise ErrorCalculatingHash
|
58
62
|
end
|
59
63
|
|
60
64
|
def md5_for(buffer)
|
data/lib/subdb/cli/version.rb
CHANGED
data/subdb-cli.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subdb-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Paramio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.1
|
69
83
|
description: SubDB client in Ruby
|
70
84
|
email:
|
71
85
|
- hola@carlosparamio.com
|