module XMorph require 'active_support' class Util def self.mediainfo_xml_to_hash(response) meta = { "Audio" => [] } begin response_json = Hash.from_xml(response) response_json["Mediainfo"]["File"]["track"].each do |track| type = track['type'] track = track.except("type") (type == "Audio") ? meta["Audio"] << track : meta[type] = track if type == "Video" aspect_ratio = nil if track["Display_aspect_ratio"].present? aspect_ratio = track["Display_aspect_ratio"] if track["Display_aspect_ratio"].include? (":") end if aspect_ratio.nil? and track["Original_display_aspect_ratio"].present? aspect_ratio = track["Original_display_aspect_ratio"] if track["Original_display_aspect_ratio"].include? (":") end track["Display_aspect_ratio"] = aspect_ratio if aspect_ratio.present? end end meta['audio_tracks'] = meta['Audio'].count.to_s rescue => ex puts ex return false, {"error" => "Failed to load mediainfo"} end return true, meta end def self.run_cmd_with_response(cmd) XMorph::Base.logger.info("Util#run_cmd_with_response: command: #{cmd}") raw_response = `#{cmd}` successful = true exit_status = $?.exitstatus if exit_status != 0 successful = false end return successful, raw_response end end end