class Dato::Local::FieldType::File::VideoAttributes

Public Class Methods

new(upload) click to toggle source
# File lib/dato/local/field_type/file.rb, line 141
def initialize(upload)
  @upload = upload
end

Public Instance Methods

duration() click to toggle source
# File lib/dato/local/field_type/file.rb, line 153
def duration
  @upload.duration
end
frame_rate() click to toggle source
# File lib/dato/local/field_type/file.rb, line 149
def frame_rate
  @upload.frame_rate
end
mp4_url(options = nil) click to toggle source
# File lib/dato/local/field_type/file.rb, line 169
def mp4_url(options = nil)
  @upload.mux_mp4_highest_res or
    return nil

  if options && options[:exact_res]
    if options[:exact_res] == :low
      raw_mp4_url("low")
    elsif options[:exact_res] == :medium
      raw_mp4_url("medium") if %w[medium high].include?(@upload.mux_mp4_highest_res)
    elsif @upload.mux_mp4_highest_res == :high
      raw_mp4_url("high")
    end
  elsif options && options[:res] == :low
    raw_mp4_url("low")
  elsif options && options[:res] == :medium
    if %w[low medium].include?(@upload.mux_mp4_highest_res)
      raw_mp4_url(@upload.mux_mp4_highest_res)
    else
      raw_mp4_url("medium")
    end
  else
    raw_mp4_url(@upload.mux_mp4_highest_res)
  end
end
mux_playback_id() click to toggle source
# File lib/dato/local/field_type/file.rb, line 145
def mux_playback_id
  @upload.mux_playback_id
end
streaming_url() click to toggle source
# File lib/dato/local/field_type/file.rb, line 157
def streaming_url
  "https://stream.mux.com/#{@upload.mux_playback_id}.m3u8"
end
thumbnail_url(format = :jpg) click to toggle source
# File lib/dato/local/field_type/file.rb, line 161
def thumbnail_url(format = :jpg)
  if format == :gif
    "https://image.mux.com/#{@upload.mux_playback_id}/animated.gif"
  else
    "https://image.mux.com/#{@upload.mux_playback_id}/thumbnail.#{format}"
  end
end
to_hash() click to toggle source
# File lib/dato/local/field_type/file.rb, line 194
def to_hash
  {
    mux_playback_id: mux_playback_id,
    frame_rate: frame_rate,
    duration: duration,
    streaming_url: streaming_url,
    thumbnail_url: thumbnail_url,
    mp4_url: mp4_url,
  }
end

Private Instance Methods

raw_mp4_url(res) click to toggle source
# File lib/dato/local/field_type/file.rb, line 207
def raw_mp4_url(res)
  "https://stream.mux.com/#{@upload.mux_playback_id}/#{res}.mp4"
end