Skip to content

Commit

Permalink
Move monkeypatching to fork; Handle durations with spaces between num…
Browse files Browse the repository at this point in the history
…ber and designator
  • Loading branch information
cjcolvar committed Sep 16, 2016
1 parent 3c0c3e1 commit af770d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/mediainfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def self.supported_attributes; @supported_attributes ||= []; end
# Size of source file as reported by File.size.
# Returns nil if you haven't yet fired off the system command.
def size; File.size(@full_filename) if @full_filename; end
def other; @other_proxy ||= StreamProxy.new(self, :other); end
def other?; streams.any? { |x| x.other? }; end

class StreamProxy
def initialize(mediainfo, stream_type)
Expand Down Expand Up @@ -198,6 +200,7 @@ def initialize(stream_type)

def [](k); @parsed_response[@stream_type][k]; end
def []=(k,v); @parsed_response[@stream_type][k] = v; end
def other?; :other == @stream_type; end

Mediainfo::SECTIONS.each { |t| define_method("#{t}?") { t == @stream_type } }
end
Expand Down Expand Up @@ -295,7 +298,16 @@ class AudioStream < Stream
mediainfo_attr_reader :stream_id, "ID"

mediainfo_duration_reader :duration

def accurate_duration
duration = 0
parsed_response[:audio]["duration"].split(':').reverse.each_with_index do |t, pow|
t, milli = t.split('.') if pow == 0
duration += milli.to_i if milli
duration += t.to_i * (60 ** pow) * 1000
end
duration
end

mediainfo_attr_reader :sampling_rate
def sample_rate
return unless rate = sampling_rate_before_type_cast
Expand Down
4 changes: 2 additions & 2 deletions lib/mediainfo/attr_readers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def mediainfo_attr_reader(method_name, mediainfo_key = nil)
def mediainfo_duration_reader(*a)
mediainfo_attr_reader *a do |v|
t = 0
v.split(/\s+/).each do |tf|
case tf
v.scan(/\d+\s*\w+/).each do |tf|
case tf.gsub(/\s*/,'')
# XXX haven't actually seen hot they represent hours yet
# but hopefully this is ok.. :\
when /\d+h/ then t += tf.to_i * 60 * 60 * 1000
Expand Down

0 comments on commit af770d3

Please sign in to comment.