From cd042a4ee30c46b117d74a182e14846a1d62540b Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Fri, 12 Apr 2019 02:22:56 -0500 Subject: Handle more audio formats, only converting formats not supported by HTML5 audio --- app/models/media_attachment.rb | 40 +++++++++++++++++++++++----------------- app/models/status.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 17 deletions(-) (limited to 'app') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 50b885bcf..8d3a656ae 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -28,12 +28,13 @@ class MediaAttachment < ApplicationRecord IMAGE_FILE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.webp'].freeze VIDEO_FILE_EXTENSIONS = ['.webm', '.mp4', '.m4v', '.mov'].freeze - AUDIO_FILE_EXTENSIONS = ['.mp3', '.m4a', '.wav', '.ogg'].freeze + AUDIO_FILE_EXTENSIONS = ['.mp3', '.m4a', '.wav', '.ogg', '.aac'].freeze IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze VIDEO_MIME_TYPES = ['video/webm', 'video/mp4', 'video/quicktime'].freeze VIDEO_CONVERTIBLE_MIME_TYPES = ['video/webm', 'video/quicktime'].freeze - AUDIO_MIME_TYPES = ['audio/mpeg', 'audio/mp4', 'audio/vnd.wav', 'audio/wav', 'audio/x-wav', 'audio/x-wave', 'audio/ogg', 'audio/aac',].freeze + AUDIO_MIME_TYPES = ['audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg', 'audio/mp4', 'audio/vnd.wav', 'audio/wav', 'audio/x-wav', 'audio/x-wave', 'audio/ogg', 'audio/aac', 'audio/flac'].freeze + AUDIO_CONVERTIBLE_MIME_TYPES = ['audio/vnd.wav', 'audio/wav', 'audio/x-wav', 'audio/x-wave', 'audio/ogg', 'audio/flac'].freeze BLURHASH_OPTIONS = { x_comp: 4, @@ -54,17 +55,6 @@ class MediaAttachment < ApplicationRecord }.freeze AUDIO_STYLES = { - original: { - format: 'm4a', - convert_options: { - output: { - vn: '', - acodec: 'aac', - movflags: '+faststart', - }, - }, - }, - small: { format: 'png', time: 0, @@ -86,6 +76,17 @@ class MediaAttachment < ApplicationRecord }, }.freeze + AUDIO_FORMAT = { + format: 'm4a', + convert_options: { + output: { + vn: '', + acodec: 'aac', + movflags: '+faststart', + }, + }, + }.freeze + VIDEO_STYLES = { small: { convert_options: { @@ -131,8 +132,8 @@ class MediaAttachment < ApplicationRecord convert_options: { all: '-quality 90 -strip' } validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES - validates_attachment_size :file, less_than: IMAGE_LIMIT, unless: :video_or_gifv? - validates_attachment_size :file, less_than: VIDEO_LIMIT, if: :video_or_gifv? + validates_attachment_size :file, less_than: IMAGE_LIMIT, unless: :video_or_audio? + validates_attachment_size :file, less_than: VIDEO_LIMIT, if: :video_or_audio? remotable_attachment :file, VIDEO_LIMIT include Attachmentable @@ -155,8 +156,8 @@ class MediaAttachment < ApplicationRecord file.blank? && remote_url.present? end - def video_or_gifv? - video? || gifv? + def video_or_audio? + video? || gifv? || audio? end def to_param @@ -198,6 +199,11 @@ class MediaAttachment < ApplicationRecord } elsif IMAGE_MIME_TYPES.include? f.instance.file_content_type IMAGE_STYLES + elsif AUDIO_CONVERTIBLE_MIME_TYPES.include?(f.instance.file_content_type) + { + small: AUDIO_STYLES[:small], + original: AUDIO_FORMAT, + } elsif AUDIO_MIME_TYPES.include? f.instance.file_content_type AUDIO_STYLES elsif VIDEO_CONVERTIBLE_MIME_TYPES.include?(f.instance.file_content_type) diff --git a/app/models/status.rb b/app/models/status.rb index 97b6b1b39..45db988e3 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -682,6 +682,33 @@ class Status < ApplicationRecord tf_cmds = [] vore_stack = [] component_stack = [] + when 'emojify' + chunk = nil + next if cmd[1].nil? + src_img = nil + shortcode = cmd[2] + case cmd[1] + when 'avatar' + src_img = account.avatar + when 'parent' + next unless cmd[3].present? && reply? + shortcode = cmd[3] + parent_status = Status.where(id: in_reply_to_id).first + next if parent_status.nil? + case cmd[2] + when 'avatar' + src_img = parent_status.account.avatar + end + end + + next if src_img.nil? || shortcode.nil? || !shortcode.match?(/\A\w+\Z/) + + chunk = ":#{shortcode}:" + emoji = CustomEmoji.find_or_initialize_by(shortcode: shortcode, domain: nil) + if emoji.id.nil? + emoji.image = src_img + emoji.save + end when 'emoji' next if cmd[1].nil? shortcode = cmd[1] -- cgit