Sha256: 619ff21f842c4367e89a8b723bf8e178707ae839d00471765b8fb76f6d30f4df
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
require 'open3' require "uri" module MiniMediainfo # Class for parsing output from mediainfo class Media attr_reader :uri def initialize(uri, options={}) @uri = uri @introspection_data = {} end def introspect() cmd = "mediainfo \"#{@uri}\" -f" key = '' lines = [] keys = [] entries = [] Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr| while line = stdout_err.gets lines << line end exit_status = wait_thr.value unless exit_status.success? abort "FAILED !!! #{cmd}" end end key = '' lines.each do |l| if l.index(':').to_i > 0 media_attrs = [l.slice(0..l.index(':')-1), l.slice(l.index(':')+1..-1)].collect {|a| a.strip} else if l.strip.length > 0 key = l.strip keys.push(key) end end if (key && key.length > 0) && (media_attrs && media_attrs.length == 2) # Only add the attribute if it does not exist already. When we parse # full output from mediainfo we are only interested in the first # entry that is unformatted and easier to work with unless entries.find {|i| i[0] == key && i[1] == media_attrs[0]} entries.push([key, media_attrs[0], media_attrs[1]]) end end end keys.each do |k| per_key_entries = entries.select {|e| e[0] == k} per_key_hash = Hash[per_key_entries.each {|e| e.shift}] @introspection_data[k] = per_key_hash end end def meta() return @introspection_data end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mini_mediainfo-0.0.5 | lib/mini_mediainfo/media.rb |