lib/mediainfo.rb in mediainfo-1.2.2 vs lib/mediainfo.rb in mediainfo-1.3.0
- old
+ new
@@ -53,20 +53,10 @@
raise Gem::LoadError, "Your specified XML parser, #{xml_parser.inspect}, could not be loaded: #{ex.message}"
end
return xml_parser
end
- def self.run(input = nil)
- raise ArgumentError, 'Your input cannot be blank.' if input.nil?
- command = "#{location} #{input} --Output=XML 2>&1"
- raw_response = `#{command}`
- unless $? == 0
- raise ExecutionError, "Execution of '#{command}' failed. #{raw_response.inspect}"
- end
- return raw_response
- end
-
def self.from(input)
return from_uri(input) if input.is_a?(URI)
return from_string(input) if input.is_a?(String)
raise BadInputError
end
@@ -94,16 +84,30 @@
def self.from_link(input)
from_uri(URI(input))
end
+ def self.run(input = nil)
+ raise ArgumentError, 'Your input cannot be blank.' if input.nil?
+ command = "#{location} '#{input}' --Output=XML"
+ raw_response, errors, status = Open3.capture3(command)
+ unless errors.empty? && status.exitstatus == 0
+ raise ExecutionError, "Execution of '#{command}' failed: \n #{errors.red}"
+ end
+ return raw_response
+ end
+
def self.from_uri(input)
- http = Net::HTTP.new(input.host, input.port) # Check if input is valid
- request = Net::HTTP::Head.new(input.request_uri) # Only grab the Headers to be sure we don't try and download the whole file
- http.use_ssl = true if input.is_a? URI::HTTPS # For https support
- http_request = http.request(request)
- raise RemoteUrlError, "HTTP call to #{input} is not working : #{http_request.value}" unless http_request.is_a?(Net::HTTPOK)
- MediaInfo::Tracks.new(MediaInfo.run(URI.escape(input.to_s)))
+ if input.host.include?('amazonaws.com')
+ MediaInfo::Tracks.new(MediaInfo.run(input.to_s)) # Removed URI.escape due to Error parsing the X-Amz-Credential parameter; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request"
+ else
+ http = Net::HTTP.new(input.host, input.port) # Check if input is valid
+ request = Net::HTTP::Head.new(input.request_uri) # Only grab the Headers to be sure we don't try and download the whole file; Doesn't work with presigned_urls in aws/s3
+ http.use_ssl = true if input.is_a? URI::HTTPS # For https support
+ http_request = http.request(request)
+ raise RemoteUrlError, "HTTP call to #{input} is not working : #{http_request.value}" unless http_request.is_a?(Net::HTTPOK)
+ MediaInfo::Tracks.new(MediaInfo.run(URI.escape(input.to_s)))
+ end
end
def self.set_singleton_method(object,name,parameters)
# Handle parameters with invalid characters (instance_variable_set throws error)
name.gsub!('.','_') if name.include?('.') ## period in name