From 8a03015349c3d9642c4d83472dbe76b072dd05a1 Mon Sep 17 00:00:00 2001 From: skybldev Date: Fri, 5 Aug 2022 21:31:27 -0400 Subject: [PATCH 1/2] client+server: added quicktime upload support --- client/html/post_merge_side.tpl | 1 + client/html/post_readonly_sidebar.tpl | 1 + client/js/views/post_upload_view.js | 2 ++ server/szurubooru/func/mime.py | 6 +++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/client/html/post_merge_side.tpl b/client/html/post_merge_side.tpl index fe705027..a08070f0 100644 --- a/client/html/post_merge_side.tpl +++ b/client/html/post_merge_side.tpl @@ -42,6 +42,7 @@ 'image/heic': 'HEIC', 'video/webm': 'WEBM', 'video/mp4': 'MPEG-4', + 'video/quicktime': 'MOV', 'application/x-shockwave-flash': 'SWF', }[ctx.post.mimeType] + ' (' + diff --git a/client/html/post_readonly_sidebar.tpl b/client/html/post_readonly_sidebar.tpl index 4f18624f..0f93ae3b 100644 --- a/client/html/post_readonly_sidebar.tpl +++ b/client/html/post_readonly_sidebar.tpl @@ -15,6 +15,7 @@ 'image/heic': 'HEIC', 'video/webm': 'WEBM', 'video/mp4': 'MPEG-4', + 'video/quicktime': 'MOV', 'application/x-shockwave-flash': 'SWF', }[ctx.post.mimeType] %> diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js index fc98a19e..4ef4c1ad 100644 --- a/client/js/views/post_upload_view.js +++ b/client/js/views/post_upload_view.js @@ -22,6 +22,7 @@ function _mimeTypeToPostType(mimeType) { "image/heic": "image", "video/mp4": "video", "video/webm": "video", + "video/quicktime": "video", }[mimeType] || "unknown" ); } @@ -120,6 +121,7 @@ class Url extends Uploadable { heif: "image/heif", heic: "image/heic", mp4: "video/mp4", + mov: "video/quicktime", webm: "video/webm", }; for (let extension of Object.keys(mime)) { diff --git a/server/szurubooru/func/mime.py b/server/szurubooru/func/mime.py index 3be43f77..4aa9c3dc 100644 --- a/server/szurubooru/func/mime.py +++ b/server/szurubooru/func/mime.py @@ -39,6 +39,9 @@ def get_mime_type(content: bytes) -> str: if content[4:12] in (b"ftypisom", b"ftypiso5", b"ftypmp42", b"ftypM4V "): return "video/mp4" + if content[4:12] in (b"ftypqt "): + return "video/quicktime" + return "application/octet-stream" @@ -54,6 +57,7 @@ def get_extension(mime_type: str) -> Optional[str]: "image/heif": "heif", "image/heic": "heic", "video/mp4": "mp4", + "video/quicktime": "mov", "video/webm": "webm", "application/octet-stream": "dat", } @@ -65,7 +69,7 @@ def is_flash(mime_type: str) -> bool: def is_video(mime_type: str) -> bool: - return mime_type.lower() in ("application/ogg", "video/mp4", "video/webm") + return mime_type.lower() in ("application/ogg", "video/mp4", "video/quicktime", "video/webm") def is_image(mime_type: str) -> bool: From 42524503b9fb5a73c69402c435e8d7aee3e036fa Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Mon, 17 Apr 2023 11:58:13 -0400 Subject: [PATCH 2/2] client/tests: add unit tests for quicktime videos --- server/szurubooru/func/mime.py | 9 +++++++-- server/szurubooru/tests/assets/mov.mov | Bin 0 -> 844 bytes server/szurubooru/tests/func/test_mime.py | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 server/szurubooru/tests/assets/mov.mov diff --git a/server/szurubooru/func/mime.py b/server/szurubooru/func/mime.py index 4aa9c3dc..f01af0da 100644 --- a/server/szurubooru/func/mime.py +++ b/server/szurubooru/func/mime.py @@ -39,7 +39,7 @@ def get_mime_type(content: bytes) -> str: if content[4:12] in (b"ftypisom", b"ftypiso5", b"ftypmp42", b"ftypM4V "): return "video/mp4" - if content[4:12] in (b"ftypqt "): + if content[4:12] == b"ftypqt ": return "video/quicktime" return "application/octet-stream" @@ -69,7 +69,12 @@ def is_flash(mime_type: str) -> bool: def is_video(mime_type: str) -> bool: - return mime_type.lower() in ("application/ogg", "video/mp4", "video/quicktime", "video/webm") + return mime_type.lower() in ( + "application/ogg", + "video/mp4", + "video/quicktime", + "video/webm", + ) def is_image(mime_type: str) -> bool: diff --git a/server/szurubooru/tests/assets/mov.mov b/server/szurubooru/tests/assets/mov.mov new file mode 100644 index 0000000000000000000000000000000000000000..911ee8525be3b88429a94b9dc25585c089d4a5ce GIT binary patch literal 844 zcmZ`$u}&L75S_y$Si(q7Vj(~-E|M!Nwj97pC=ixnAqp%d1yoU#jrS~DzQxY%atJCz z1qFXWLl=P{Kj8cUA3>Ko6?t=eXB|WtYdo{>&Agl0C89#d91g!5*Cm=F8!3CxlO7Q* zDJcw*b4~dfgxmbrPbcd?e-mZq)nE{!!dGEeBBm^Jk3*RpG^EhS2M~`)qDH#*-+T(w z9h*S(L47v;=$n~TS)x`>VKz;egm`jpFrJN_sN_kbaVmPg#^#Z6ht-XGoj*$U1Ta_0 zr@PkxV^nLEuJi*=Ro4$fd!sQ$l-mU`*b;lv_fX_qsNP-&Y#~&UXnM>yiI9ZQe&D+k z6(qAwVZ=m-O48~SW#F+M8*Am_KIG1OZNB-y?zGX#<8jSc4OjV5*`n`nZni$!g|Ji> zzb!EAY*B?x|MS1_@BrqErzKx0Wk#b>3vJVg8}18+Xl}&*3`hlvKX|&EvsYH!acO*h zO24S-6g~jD+7@BEzEWMOS8LDF;qXo8he8h#c^dWwZK4N6nqbj`6tQcYL0D3o!~(b@ oOVP`i2i6|M7}u5HulJ=9h>Mr{AfUOOF$U_?*Q(3!s&8wxzmBzPhX4Qo literal 0 HcmV?d00001 diff --git a/server/szurubooru/tests/func/test_mime.py b/server/szurubooru/tests/func/test_mime.py index b33746b4..551ba7c3 100644 --- a/server/szurubooru/tests/func/test_mime.py +++ b/server/szurubooru/tests/func/test_mime.py @@ -7,6 +7,7 @@ from szurubooru.func import mime "input_path,expected_mime_type", [ ("mp4.mp4", "video/mp4"), + ("mov.mov", "video/quicktime"), ("webm.webm", "video/webm"), ("flash.swf", "application/x-shockwave-flash"), ("png.png", "image/png"), @@ -35,6 +36,7 @@ def test_get_mime_type_for_empty_file(): [ ("video/mp4", "mp4"), ("video/webm", "webm"), + ("video/quicktime", "mov"), ("application/x-shockwave-flash", "swf"), ("image/png", "png"), ("image/jpeg", "jpg"), @@ -70,6 +72,8 @@ def test_is_flash(input_mime_type, expected_state): ("VIDEO/WEBM", True), ("video/mp4", True), ("VIDEO/MP4", True), + ("video/quicktime", True), + ("VIDEO/QUICKTIME", True), ("video/anything_else", False), ("application/ogg", True), ("not a video", False),