lib/mini_mediainfo/media.rb in mini_mediainfo-0.0.1 vs lib/mini_mediainfo/media.rb in mini_mediainfo-0.0.2
- old
+ new
@@ -2,10 +2,11 @@
require "net/http"
require "uri"
module MiniMediainfo
+ # Class for parsing output from mediainfo
class Media
attr_reader :uri
def initialize(uri, options={})
@@ -24,11 +25,11 @@
@uri = uri
@introspection_data = {}
end
def introspect()
- cmd = "mediainfo \"#{@uri}\""
+ cmd = "mediainfo \"#{@uri}\" -f"
key = ''
lines = []
keys = []
entries = []
@@ -53,10 +54,15 @@
keys.push(key)
end
end
if (key && key.length > 0) && (media_attrs && media_attrs.length == 2)
- entries.push([key, media_attrs[0], media_attrs[1]])
+ # 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}