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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5aa017f5cd550b00dd0cc02737f087cc148eea39
4
- data.tar.gz: 1b43602f04b36b7e08c749f0ac01179989f70be8
3
+ metadata.gz: 7559d42447598fcce6945f6a1cd5bb4f7f448ca5
4
+ data.tar.gz: de5e8bd3e157d42820dd7e97a222d39b37eb4988
5
5
  SHA512:
6
- metadata.gz: 3eef16f7f59e32c0dfb6fab1a2b9449d428297dc1032ddece8cca6d8509e82a9e9fa3c9a71b700120e3c0fc373978bc824f1e4acc460b67778f52360110f007b
7
- data.tar.gz: e4b599017364ccfbe59095d2baf9c2a781bf6e15af60b94bd5b8dd979c4a741e7c3f4c0e88ad7f78c6a72ef910ce44c37df2f61aaed465dfbf53daf909fe1c20
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
- ARGV << '-h' if ARGV[0].nil?
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
- options = {
10
- language: "en"
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
- OptionParser.new do |opts|
14
- opts.banner = "Usage: subdb [options] file_path"
16
+ action = ARGV[0]
15
17
 
16
- opts.on("-l", "--language LANG", "Select language to download (default: en)") do |language|
17
- options[:language] = language
18
- end
18
+ begin
19
+ case action
20
+ when "download"
21
+ video_file_path = ARGV[1]
22
+ languages = ARGV[2] || "en"
19
23
 
20
- opts.on_tail("-h", "--help", "Show this message") do
21
- puts opts
22
- exit
23
- end
24
- end.parse!
24
+ display_help && exit if video_file_path.nil?
25
25
 
26
- begin
27
- Subdb::Cli.new.download(ARGV[0], options[:language])
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
- exit
34
- end
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
@@ -8,8 +8,9 @@ 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)
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/0.1; https://github.com/carlosparamio/subdb-cli)"
73
+ "SubDB/1.0 (subdb-cli/#{VERSION}; https://github.com/carlosparamio/subdb-cli)"
61
74
  end
62
75
 
63
76
  end
@@ -1,5 +1,5 @@
1
1
  module Subdb
2
2
  class Cli
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subdb-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Paramio