Class: EhbrsRubyUtils::Videos::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/videos/stream.rb

Constant Summary collapse

DURATION_TAG_TO_SECONDS_PARSER =
/\A(\d{2}):(\d{2}):(\d{2}.\d+)\z/.to_parser do |m|
  (m[1].to_i * 3600) + (m[2].to_i * 60) + m[3].to_f
end

Instance Method Summary collapse

Instance Method Details

#codec_tagInteger

Returns:

  • (Integer)


27
28
29
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 27

def codec_tag
  ffprobe_data.fetch(:codec_tag).to_i(16)
end

#codec_typeObject



57
58
59
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 57

def codec_type
  ffprobe_data.fetch(:codec_type).to_sym
end

#durationActiveSupport::Duration?

Returns:

  • (ActiveSupport::Duration, nil)


32
33
34
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 32

def duration
  duration_from_root || duration_from_tags
end

#languageObject



65
66
67
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 65

def language
  tags[:language]
end

#language_with_titleObject



69
70
71
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 69

def language_with_title
  [language, title].compact_blank.if_present { |v| v.join('_').variableize }
end

#tagsObject



61
62
63
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 61

def tags
  ffprobe_data[:tags].if_present({}, &:symbolize_keys)
end

#titleObject



73
74
75
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 73

def title
  tags[:title]
end

#to_hObject



41
42
43
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 41

def to_h
  ffprobe_data
end

#to_sString

Returns:

  • (String)


37
38
39
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 37

def to_s
  [index, codec_type, codec_name, language, codec_tag_string].join('|')
end