require 'forwardable' require 'net/http' require 'mediainfo/errors' require 'mediainfo/tracks' require 'mediainfo/string' module MediaInfo # Allow user to set custom mediainfo_path with ENV['MEDIAINFO_PATH'] def self.location ENV['MEDIAINFO_PATH'].nil? ? mediainfo_location = '/usr/local/bin/mediainfo' : mediainfo_location = ENV['MEDIAINFO_PATH'] raise EnvironmentError, "#{mediainfo_location} cannot be found. Are you sure mediainfo is installed?" unless ::File.exist? mediainfo_location return mediainfo_location end # Allow collection of MediaInfo version details def self.version version ||= `#{location} --Version`[/v([\d.]+)/, 1] # Ensure MediaInfo isn't buggy and returns something raise UnknownVersionError, 'Unable to determine mediainfo version. ' + "We tried: #{location} --Version." + 'Set MediaInfo.path = \'/full/path/of/mediainfo\' if it is not in your PATH.' unless version # Ensure you're not using an old version of MediaInfo if version < '0.7.25' raise IncompatibleVersionError, "Your version of mediainfo, #{version}, " + 'is not compatible with this gem. >= 0.7.25 required.' else @version = version end end def self.xml_parser ENV['MEDIAINFO_XML_PARSER'].nil? || ENV['MEDIAINFO_XML_PARSER'].to_s.strip.empty? ? xml_parser = 'rexml/document' : xml_parser = ENV['MEDIAINFO_XML_PARSER'] begin require xml_parser rescue Gem::LoadError => ex 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) input_guideline_message = 'Bad Input' + "\n" + "Input must be: \n" + "A video or xml file location. Example: '~/videos/test_video.mov' or '~/videos/test_video.xml' \n" + "A valid URL. Example: 'http://www.site.com/videofile.mov' \n" + "Or MediaInfo XML \n" if input # User must specify file if input.include?('