Class: Musictree::FFProber

Inherits:
Object
  • Object
show all
Defined in:
lib/musictree/ff_prober.rb

Overview

Let’s leave this in here for now if we need this for exotic cases.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FFProber

Returns a new instance of FFProber.



10
11
12
13
# File 'lib/musictree/ff_prober.rb', line 10

def initialize(path)
  @path = path
  probe
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
# File 'lib/musictree/ff_prober.rb', line 15

def [](key)
  [key]
end

#probeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/musictree/ff_prober.rb', line 19

def probe
   = {}
  stdout, stderr, status = Open3.capture3("ffprobe #{@path} -hide_banner -show_entries 'format_tags'")
  matches = stdout.match(/\[FORMAT\]\n(.*)\n\[\/FORMAT\]/m)
  unless status.success?
    raise FFProbeError.new("Error running ffprobe: #{stderr}")
  end
  if matches.nil?
    raise FFProbeError.new("No FORMAT block in result: #{[stdout, stderr].join}")
  end
  matches[1].lines.each do |line|
    line_matches = line.match(/^TAG:(?<tag>\w+)=(?<value>.*?)\n/)
    if line_matches
      [line_matches[:tag].downcase] = line_matches[:value]
    end
  end
end