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)


29
30
31
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 29

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

#codec_typeObject



59
60
61
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 59

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

#durationActiveSupport::Duration?

Returns:

  • (ActiveSupport::Duration, nil)


34
35
36
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 34

def duration
  duration_from_root || duration_from_tags
end

#languageObject



67
68
69
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 67

def language
  tags[:language]
end

#language_with_titleObject



71
72
73
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 71

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

#tagsObject



63
64
65
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 63

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

#titleObject



75
76
77
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 75

def title
  tags[:title]
end

#to_hObject



43
44
45
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 43

def to_h
  ffprobe_data
end

#to_sString

Returns:

  • (String)


39
40
41
# File 'lib/ehbrs_ruby_utils/videos/stream.rb', line 39

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