Sha256: c884bc14860fce986596d3a3e88309cbfb9f28c7aded1c8a1228de1460b3f4fd

Contents?: true

Size: 1.38 KB

Versions: 26

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Videos
    class Stream
      enable_simple_cache
      enable_listable

      lists.add_symbol :codec_type, :audio, :video, :subtitle, :data, :attachment

      common_constructor :ffprobe_data do
        self.ffprobe_data = ffprobe_data.symbolize_keys.freeze
        self.class.lists.codec_type.value_validate!(codec_type)
      end

      lists.codec_type.each_value do |v|
        define_method "#{v}?" do
          codec_type == v
        end
      end

      def to_s
        "#{index}|#{codec_type}|#{codec_name}|#{language}"
      end

      def to_h
        ffprobe_data
      end

      %i[index].each do |method_name|
        define_method method_name do
          ffprobe_data.fetch(method_name)
        end
      end

      %i[codec_name codec_long_name height width].each do |method_name|
        define_method method_name do
          ffprobe_data[method_name]
        end
      end

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

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

      def language
        tags[:language]
      end

      def language_with_title
        [language, title].reject(&:blank?).if_present { |v| v.join('_').variableize }
      end

      def title
        tags[:title]
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.33.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.32.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.28.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.27.1 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.27.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.26.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.25.1 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.25.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.24.1 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.24.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.23.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.22.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.21.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.20.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.19.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.18.0 lib/ehbrs_ruby_utils/videos/stream.rb
ehbrs_ruby_utils-0.17.3 lib/ehbrs_ruby_utils/videos/stream.rb