Class: Ffprober::Ffmpeg::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/ffprober/ffmpeg/finder.rb

Constant Summary collapse

SEARCH_PATHS =
ENV.fetch('PATH', nil)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFinder

Returns a new instance of Finder.



10
11
12
13
14
# File 'lib/ffprober/ffmpeg/finder.rb', line 10

def initialize
  @executable_path = nil
  @executable_name = executable_name_picker
  @path = nil
end

Instance Attribute Details

#executable_nameObject (readonly)

Returns the value of attribute executable_name.



8
9
10
# File 'lib/ffprober/ffmpeg/finder.rb', line 8

def executable_name
  @executable_name
end

Instance Method Details

#executable_name_pickerObject



26
27
28
29
30
31
32
# File 'lib/ffprober/ffmpeg/finder.rb', line 26

def executable_name_picker
  if windows?
    'ffprobe.exe'
  else
    'ffprobe'
  end
end

#executable_pathObject



34
35
36
37
38
# File 'lib/ffprober/ffmpeg/finder.rb', line 34

def executable_path
  @executable_path ||= SEARCH_PATHS.split(File::PATH_SEPARATOR).detect do |path_to_check|
    File.executable?(File.join(path_to_check, executable_name))
  end
end

#pathObject



16
17
18
19
20
# File 'lib/ffprober/ffmpeg/finder.rb', line 16

def path
  raise Ffprober::NoFfprobeFound, 'ffprobe executable not found' if executable_path.nil?

  @path ||= File.expand_path(executable_name, executable_path)
end

#windows?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ffprober/ffmpeg/finder.rb', line 22

def windows?
  !(RUBY_PLATFORM =~ /(mingw|mswin)/).nil?
end