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)
- ErrorCalculatingHash =
Class.new(StandardError)
- SubtitlesNotFound =
Class.new(StandardError)
- SubtitleUploadError =
Class.new(StandardError)
- VERSION =
"0.2.2"
Instance Method Summary collapse
- #download(video_file_path, language) ⇒ Object
- #upload(video_file_path, subtitles_file_path) ⇒ Object
Instance Method Details
#download(video_file_path, language) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/subdb/cli.rb', line 16 def download(video_file_path, language) raise FileNotFound unless File.exists?(video_file_path) response = client.get('/', { action: 'download', language: language, hash: hash_for(video_file_path) }) raise SubtitleNotFound unless response.status == 200 File.open(srt_file_for(video_file_path), "w") do |srt_file| srt_file.write(response.body) end end |
#upload(video_file_path, subtitles_file_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/subdb/cli.rb', line 33 def upload(video_file_path, subtitles_file_path) raise FileNotFound unless File.exists?(video_file_path) raise FileNotFound unless File.exists?(subtitles_file_path) response = client.post('/?action=upload', { hash: hash_for(video_file_path), file: Faraday::UploadIO.new(subtitles_file_path, 'application/octet-stream') }) raise SubtitleUploadError unless response.status == 200 end |