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.



132
133
134
# File 'lib/dato/local/field_type/file.rb', line 132

def initialize(upload)
  @upload = upload
end

Instance Method Details

#durationObject



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

def duration
  @upload.duration
end

#frame_rateObject



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

def frame_rate
  @upload.frame_rate
end

#mp4_url(options = nil) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/dato/local/field_type/file.rb', line 160

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
      if %w[medium high].include?(@upload.mux_mp4_highest_res)
        raw_mp4_url("medium")
      end
    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



136
137
138
# File 'lib/dato/local/field_type/file.rb', line 136

def mux_playback_id
  @upload.mux_playback_id
end

#streaming_urlObject



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

def streaming_url
  "https://stream.mux.com/#{@upload.mux_playback_id}.m3u8"
end

#thumbnail_url(format = :jpg) ⇒ Object



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

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



187
188
189
190
191
192
193
194
195
196
# File 'lib/dato/local/field_type/file.rb', line 187

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