Class: Subdb::Cli
- Inherits:
-
Object
- Object
- Subdb::Cli
- Defined in:
- lib/subdb/cli.rb,
lib/subdb/cli/version.rb
Constant Summary collapse
- BASE_URL =
'http://api.thesubdb.com/'- READSIZE =
64 * 1024
- FileNotFound =
Class.new(StandardError)
- SubtitlesNotFound =
Class.new(StandardError)
- SubtitleUploadError =
Class.new(StandardError)
- VERSION =
"0.2.0"
Instance Method Summary collapse
Instance Method Details
#download(file_path, language) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/subdb/cli.rb', line 15 def download(file_path, language) response = client.get('/', { action: 'download', language: language, hash: hash_for(file_path) }) raise SubtitleNotFound unless response.status == 200 File.open(srt_file_for(file_path), "w") do |file| file.write(response.body) end end |
#upload(video_file_path, subtitles_file_path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/subdb/cli.rb', line 30 def upload(video_file_path, subtitles_file_path) response = client.post('/', { action: 'upload', hash: hash_for(video_file_path) }) do |request| request.body = File.read(subtitles_file_path) end raise SubtitleUploadError unless response.status == 200 end |