uploads: allow uploading .m4v format videos.

Fix not being able to upload .m4v format videos as reported here:

* https://danbooru.donmai.us/forum_posts/205248
* https://github.com/danbooru/danbooru/issues/3615#issuecomment-1030950924

From https://en.wikipedia.org/wiki/M4V:

  The M4V file format is a video container format developed by Apple and
  is very similar to the MP4 format. The primary difference is that M4V
  files may optionally be protected by DRM copy protection.

This could be a problem if it allows uploading videos that are
unplayable because of DRM.
This commit is contained in:
evazion
2022-02-06 21:29:57 -06:00
parent 7bed81812d
commit 572878fb0d
4 changed files with 13 additions and 1 deletions

View File

@@ -56,7 +56,14 @@ class MediaFile
:swf
when /\x1a\x45\xdf\xa3/n
:webm
when /\A....ftyp(?:isom|3gp5|mp42|MSNV|avc1)/
# https://www.ftyps.com
# isom (common) - MP4 Base Media v1 [IS0 14496-12:2003]
# mp42 (common) - MP4 v2 [ISO 14496-14]
# 3gp5 (rare) - 3GPP Media (.3GP) Release 5
# avc1 (rare) - MP4 Base w/ AVC ext [ISO 14496-12:2005]
# M4V (rare) - Apple iTunes Video (https://en.wikipedia.org/wiki/M4V)
when /\A....ftyp(?:isom|3gp5|mp42|avc1|M4V)/
:mp4
when /\APK\x03\x04/
:zip

BIN
test/files/test-audio.m4v Normal file

Binary file not shown.

View File

@@ -261,6 +261,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
should_upload_successfully("test/files/test-animated-86x52.gif")
should_upload_successfully("test/files/test-300x300.mp4")
should_upload_successfully("test/files/test-512x512.webm")
should_upload_successfully("test/files/test-audio.m4v")
# should_upload_successfully("test/files/compressed.swf")
end

View File

@@ -93,6 +93,10 @@ class MediaFileTest < ActiveSupport::TestCase
assert_equal(:mp4, MediaFile.open("test/files/test-300x300.mp4").file_ext)
end
should "determine the correct extension for a m4v file" do
assert_equal(:mp4, MediaFile.open("test/files/test-audio.m4v").file_ext)
end
should "determine the correct extension for a ugoira file" do
assert_equal(:zip, MediaFile.open("test/files/ugoira.zip").file_ext)
end