Skip to content

Commit

Permalink
remove display mime type and migrate existing data to new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
manno committed Jan 14, 2016
1 parent dee1bf9 commit 32e27e6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 30 deletions.
4 changes: 2 additions & 2 deletions app/helpers/frontend/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def googleplus_url(title, url)
def appnet_url(title, url)
'https://alpha.app.net/intent/post?text='.freeze + URI.encode_www_form_component(title + ': ' + url)
end

def diaspora_url(title, url)
'https://share.diasporafoundation.org/?title='.freeze + URI.encode_www_form_component(title) + '&url=' + URI.encode_www_form_component(url)
end
Expand Down Expand Up @@ -66,7 +66,7 @@ def duration_in_minutes(duration)
end

def video_for_flash(recordings)
url = recordings.find { |recording| recording.display_mime_type == 'video/mp4' }.try(:url)
url = recordings.find { |recording| recording.mime_type == 'video/mp4' }.try(:url)
if url.present?
h(url)
elsif recordings.present?
Expand Down
4 changes: 0 additions & 4 deletions app/models/frontend/recording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def torrent_url
(url + '.torrent').freeze
end

def display_mime_type
MimeType.display_mime_type(mime_type)
end

def filetype
MimeType.humanized_mime_type(mime_type)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/frontend/events/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#audio.tab-pane
%audio.audio{controls: 'controls', preload: 'none'}
- @audio_recordings.each do |recording|
%source{type: recording.display_mime_type, src: h(recording.url)}
%source{type: recording.mime_type, src: h(recording.url)}

#download.tab-pane
= render partial: 'frontend/shared/download', locals: { video_recordings: @video_recordings, audio_recordings: @audio_recordings, subtitle_recording: @subtitle_recording, conference: @conference }
Expand Down
2 changes: 1 addition & 1 deletion app/views/frontend/shared/_videoplayer.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%video.video{controls: 'controls', 'data-id' => event_id, poster: poster_url, width: width, height: height}
- video_recordings.each do |recording|
%source{type: recording.display_mime_type, src: h(recording.url)}
%source{type: recording.mime_type, src: h(recording.url)}
%object{ width: width, height: height, type: 'application/x-shockwave-flash', data: asset_url('flashmediaelement.swf') }
%param{ name: 'allowFullScreen', value: 'true' }
%param{ name: 'flashvars', value: "controls=true&file=#{video_for_flash(video_recordings)}" }
Expand Down
1 change: 0 additions & 1 deletion app/views/public/shared/_recording.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
json.extract! recording, :size, :length, :mime_type, :language, :filename, :original_url, :state, :folder, :width, :height, :updated_at
json.recording_url recording.get_recording_url
json.hd recording.hd_quality
json.display_mime_type MimeType.display_mime_type(recording.mime_type)
json.url public_recording_url(recording, format: :json)
json.event_url public_event_url(recording.event, format: :json)
json.conference_url public_conference_url(recording.conference, format: :json)
46 changes: 46 additions & 0 deletions db/migrate/20160104122727_mime_types_to_flags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class MimeTypesToFlags < ActiveRecord::Migration
def change
html5 = %w(vnd.voc/mp4-web vnd.voc/webm-web)
Recording.find_each do |recording|
next unless recording.valid?
recording.hd_quality = hd?(recording.mime_type)
recording.html5 = html5.include?(recording.mime_type)
recording.mime_type = display_mime_type(recording.mime_type)
recording.save!
end
end

def display_mime_type(mime_type)
case mime_type
when 'vnd.voc/h264-lq'
'video/mp4'
when 'vnd.voc/h264-sd'
'video/mp4'
when 'vnd.voc/h264-hd'
'video/mp4'
when 'vnd.voc/mp4-web'
'video/mp4'
when 'vnd.voc/webm-hd'
'video/webm'
when 'vnd.voc/webm-web'
'video/webm'
else
mime_type
end
end

def hd?(mime_type)
case mime_type
when 'vnd.voc/h264-lq'
false
when 'vnd.voc/h264-sd'
false
when 'vnd.voc/h264-hd'
true
when 'vnd.voc/webm-hd'
true
else
true
end
end
end
2 changes: 1 addition & 1 deletion lib/feeds/podcast_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def fill_item(item, event, recording)

item.enclosure.url = recording.url
item.enclosure.length = size_to_bytes(recording.size || 0)
item.enclosure.type = recording.display_mime_type
item.enclosure.type = recording.mime_type
end

def size_to_bytes(size)
Expand Down
20 changes: 0 additions & 20 deletions lib/mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@ def mime_type_slug(mime_type)
humanized_mime_type(mime_type).to_param.downcase.freeze
end

# TODO this will be just mime_type one day?
def display_mime_type(mime_type)
case mime_type
when 'vnd.voc/h264-lq'
'video/mp4'
when 'vnd.voc/h264-sd'
'video/mp4'
when 'vnd.voc/h264-hd'
'video/mp4'
when 'vnd.voc/mp4-web'
'video/mp4'
when 'vnd.voc/webm-hd'
'video/webm'
when 'vnd.voc/webm-web'
'video/webm'
else
mime_type
end
end

def humanized_mime_type(mime_type)
case mime_type
when 'vnd.voc/h264-lq'
Expand Down

0 comments on commit 32e27e6

Please sign in to comment.