Class: Subdb::Video
- Inherits:
-
Object
- Object
- Subdb::Video
- Defined in:
- lib/subdb/video.rb
Constant Summary collapse
- API =
"http://api.thesubdb.com/"
- SANDBOX =
"http://sandbox.thesubdb.com/"
Class Attribute Summary collapse
-
.test_mode ⇒ Object
Returns the value of attribute test_mode.
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #download(languages = ["en"]) ⇒ Object
-
#initialize(path) ⇒ Video
constructor
A new instance of Video.
- #pathbase ⇒ Object
- #search ⇒ Object
- #upload(path) ⇒ Object
Constructor Details
#initialize(path) ⇒ Video
Returns a new instance of Video.
49 50 51 52 53 54 |
# File 'lib/subdb/video.rb', line 49 def initialize(path) fail "#{path} is not a file" unless File.exists?(path) @path = path @hash = build_hash end |
Class Attribute Details
.test_mode ⇒ Object
Returns the value of attribute test_mode.
38 39 40 |
# File 'lib/subdb/video.rb', line 38 def test_mode @test_mode end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
47 48 49 |
# File 'lib/subdb/video.rb', line 47 def hash @hash end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
47 48 49 |
# File 'lib/subdb/video.rb', line 47 def path @path end |
Class Method Details
Instance Method Details
#download(languages = ["en"]) ⇒ Object
61 62 63 64 |
# File 'lib/subdb/video.rb', line 61 def download(languages = ["en"]) res = request("download", :language => languages.join(",")) check_get(res) end |
#pathbase ⇒ Object
96 97 98 |
# File 'lib/subdb/video.rb', line 96 def pathbase File.basename(path) end |
#search ⇒ Object
56 57 58 59 |
# File 'lib/subdb/video.rb', line 56 def search res = request("search") check_get(res) end |
#upload(path) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/subdb/video.rb', line 66 def upload(path) fail "Invalid subtitle file #{path}" unless File.exists?(path) params = {:action => "upload", :hash => @hash} url = URI.parse(self.class.api_url) begin file = File.open(path, "rb") io = UploadIO.new(file, "application/octet-stream", File.basename(path)) req = Net::HTTP::Post::Multipart.new(url.path + stringify_params(params), {"file" => io, "hash" => @hash}) req["User-Agent"] = user_agent res = Net::HTTP.start(url.host, url.port) do |http| http.request(req) end case res.code.to_s when "201" then true when "403" then false when "400" then fail "Malformed request" when "415" then fail "Invalid subtitle type" end ensure file.close end end |