Class: Dato::Local::FieldType::File::VideoAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/dato/local/field_type/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(upload) ⇒ VideoAttributes

Returns a new instance of VideoAttributes.



141
142
143
# File 'lib/dato/local/field_type/file.rb', line 141

def initialize(upload)
  @upload = upload
end

Instance Method Details

#durationObject



153
154
155
# File 'lib/dato/local/field_type/file.rb', line 153

def duration
  @upload.duration
end

#frame_rateObject



149
150
151
# File 'lib/dato/local/field_type/file.rb', line 149

def frame_rate
  @upload.frame_rate
end

#mp4_url(options = nil) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# 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_idObject



145
146
147
# File 'lib/dato/local/field_type/file.rb', line 145

def mux_playback_id
  @upload.mux_playback_id
end

#streaming_urlObject



157
158
159
# 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) ⇒ Object



161
162
163
164
165
166
167
# 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_hashObject



194
195
196
197
198
199
200
201
202
203
# 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