diff options
author | Eric Wong <e@80x24.org> | 2016-02-09 04:46:10 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-02-09 07:10:57 +0000 |
commit | a2e8e0b912ad44a6dc9c8387145f3a48494dd56e (patch) | |
tree | 2d8ddd43a8c6d5d3bf696b87d035e3a1e3ce1828 | |
parent | bc317247f98e7010aa589484317f2302dce9b42c (diff) | |
download | dtas-a2e8e0b912ad44a6dc9c8387145f3a48494dd56e.tar.gz |
Newer avprobe outputs a new format, fix our parser to workaround this while remaining compatible with the old one in Debian wheezy. Additionally, ffprobe is no longer available as a link to avprobe.
-rw-r--r-- | lib/dtas/source/av_ff_common.rb | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/lib/dtas/source/av_ff_common.rb b/lib/dtas/source/av_ff_common.rb index 58d9f54..27084f1 100644 --- a/lib/dtas/source/av_ff_common.rb +++ b/lib/dtas/source/av_ff_common.rb @@ -78,28 +78,50 @@ module DTAS::Source::AvFfCommon # :nodoc: break if cmd == prev_cmd err = "".b - s = qx(@env, cmd, err_str: err, no_raise: true) + begin + s = qx(@env, cmd, err_str: err, no_raise: true) + rescue Errno::ENOENT # avprobe/ffprobe not installed + return false + end return false unless probe_ok?(s, err) - s.scan(%r{^\[STREAM\]\n(.*?)\n\[/STREAM\]\n}mn) do |_| - __parse_astream(cmd, $1) do |index, as| - # incomplete streams may have zero channels - if as.channels > 0 && as.rate > 0 - @astreams[index] = as - incomplete[index] = nil - else - incomplete[index] = as + + # old avprobe + [ %r{^\[STREAM\]\n(.*?)\n\[/STREAM\]\n}mn, + %r{^\[streams\.stream\.\d+\]\n(.*?)\n\n}mn ].each do |re| + s.scan(re) do |_| + __parse_astream(cmd, $1) do |index, as| + # incomplete streams may have zero channels + if as.channels > 0 && as.rate > 0 + @astreams[index] = as + incomplete[index] = nil + else + incomplete[index] = as + end end end end + prev_cmd = cmd end while incomplete.compact[0] + # old avprobe s.scan(%r{^\[FORMAT\]\n(.*?)\n\[/FORMAT\]\n}m) do |_| f = $1.dup f =~ /^duration=([\d\.]+)\s*$/nm and @duration = $1.to_f # TODO: multi-line/multi-value/repeated tags f.gsub!(/^TAG:([^=]+)=(.*)$/ni) { |_| @comments[$1.upcase.freeze] = $2 } end + + # new avprobe + s.scan(%r{^\[format\.tags\]\n(.*?)\n\n}m) do |_| + f = $1.dup + f.gsub!(/^([^=]+)=(.*)$/ni) { |_| @comments[$1.upcase.freeze] = $2 } + end + s.scan(%r{^\[format\]\n(.*?)\n\n}m) do |_| + f = $1.dup + f =~ /^duration=([\d\.]+)\s*$/nm and @duration = $1.to_f + end + ! @astreams.compact.empty? end |