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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7559d42447598fcce6945f6a1cd5bb4f7f448ca5
4
- data.tar.gz: de5e8bd3e157d42820dd7e97a222d39b37eb4988
3
+ metadata.gz: d5ad8ef2b99c52f9e3742897b0b266be010d52c7
4
+ data.tar.gz: b75e627f2306e3cfbd03e916d7940469af4592ab
5
5
  SHA512:
6
- metadata.gz: 3f4c7ac96f0cd0ca796d9fd1add056ca42c2ada8402996a0525950465300751a5b2a2c0721ad510c6cc40efb983319f3100f1758767af757b849fef8de3f0f0b
7
- data.tar.gz: 019013892ee90b4b2b3a88de9c14410a223939586322cad0f0f4ba734f283540affddb7ba5f896b76ddd8c4656093375513b3245beaa8e3adce7ea13923de176
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 <<-USAGE
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
- USAGE
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
@@ -8,32 +8,36 @@ module Subdb
8
8
  BASE_URL = 'http://api.thesubdb.com/'
9
9
  READSIZE = 64 * 1024
10
10
 
11
- FileNotFound = Class.new(StandardError)
12
- SubtitlesNotFound = Class.new(StandardError)
13
- SubtitleUploadError = Class.new(StandardError)
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(file_path)
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(file_path), "w") do |file|
25
- file.write(response.body)
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
- 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
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 Errno::ENOENT
57
- raise FileNotFound
60
+ rescue
61
+ raise ErrorCalculatingHash
58
62
  end
59
63
 
60
64
  def md5_for(buffer)
@@ -1,5 +1,5 @@
1
1
  module Subdb
2
2
  class Cli
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.14"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "webmock", "~> 3.0.1"
27
28
  end
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.0
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-22 00:00:00.000000000 Z
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