Class: Ffprober::Parser

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_file(file_to_parse) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ffprober/parser.rb', line 5

def self.from_file(file_to_parse)
  unless FfprobeVersion.valid?
    fail ArgumentError.new("no or unsupported ffprobe version found.\
                            (version: #{FfprobeVersion.new.version})")
  end

  unless File.exist?(file_to_parse)
    fail ArgumentError.new("File not found #{file_to_parse}")
  end

  json_output = `#{Ffprober.path} #{options} #{Shellwords.escape(file_to_parse)}`
  from_json(json_output)
end

.from_json(json_to_parse) ⇒ Object



19
20
21
22
23
# File 'lib/ffprober/parser.rb', line 19

def self.from_json(json_to_parse)
  parser = new
  parser.parse(json_to_parse)
  parser
end

Instance Method Details

#audio_streamsObject



38
39
40
# File 'lib/ffprober/parser.rb', line 38

def audio_streams
  @audio_streams ||= stream_by_codec('audio').map { |stream| Ffprober::AudioStream.new(stream) }
end

#chaptersObject



46
47
48
# File 'lib/ffprober/parser.rb', line 46

def chapters
  @chapters ||= @json[:chapters].map { |chapter| Ffprober::Chapter.new(chapter) }
end

#formatObject



30
31
32
# File 'lib/ffprober/parser.rb', line 30

def format
  @format ||= Ffprober::Format.new(@json[:format])
end

#parse(json_to_parse) ⇒ Object



25
26
27
28
# File 'lib/ffprober/parser.rb', line 25

def parse(json_to_parse)
  fail ArgumentError.new('No JSON input data') if json_to_parse.nil?
  @json = JSON.parse(json_to_parse, symbolize_names: true)
end

#subtitle_streamsObject



42
43
44
# File 'lib/ffprober/parser.rb', line 42

def subtitle_streams
  @subtitle_streams ||= stream_by_codec('subtitle').map { |stream| Ffprober::SubtitleStream.new(stream) }
end

#video_streamsObject



34
35
36
# File 'lib/ffprober/parser.rb', line 34

def video_streams
  @video_streams ||= stream_by_codec('video').map { |stream| Ffprober::VideoStream.new(stream) }
end