From 61011ecea0eb86f50813d39a9172e86d417c1c0d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:53:51 +0200 Subject: [PATCH 1/3] use ayon api implementation of mime type --- client/ayon_core/lib/transcoding.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client/ayon_core/lib/transcoding.py b/client/ayon_core/lib/transcoding.py index b3958863fe..dd44d4a673 100644 --- a/client/ayon_core/lib/transcoding.py +++ b/client/ayon_core/lib/transcoding.py @@ -1519,12 +1519,24 @@ def get_media_mime_type(filepath: str) -> Optional[str]: Optional[str]: Mime type or None if is unknown mime type. """ + try: + from ayon_api.utils import ( + get_media_mime_type_for_content as _ayon_api_func + ) + except ImportError: + _ayon_api_func = None + if not filepath or not os.path.exists(filepath): return None with open(filepath, "rb") as stream: content = stream.read() + if _ayon_api_func is not None: + mime_type = _ayon_api_func(content) + if mime_type is not None: + return mime_type + content_len = len(content) # Pre-validation (largest definition check) # - hopefully there cannot be media defined in less than 12 bytes From ab058d15c524bd9ddaf9659f855be384408552b7 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:59:40 +0200 Subject: [PATCH 2/3] copy implementation from ayon api --- client/ayon_core/lib/transcoding.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/ayon_core/lib/transcoding.py b/client/ayon_core/lib/transcoding.py index dd44d4a673..36a0caef27 100644 --- a/client/ayon_core/lib/transcoding.py +++ b/client/ayon_core/lib/transcoding.py @@ -1563,11 +1563,13 @@ def get_media_mime_type(filepath: str) -> Optional[str]: if b'xmlns="http://www.w3.org/2000/svg"' in content: return "image/svg+xml" - # JPEG, JFIF or Exif - if ( - content[0:4] == b"\xff\xd8\xff\xdb" - or content[6:10] in (b"JFIF", b"Exif") - ): + # JPEG + # - [0:2] is constant b"\xff\xd8" + # (ref. https://www.file-recovery.com/jpg-signature-format.htm) + # - [2:4] Marker identifier b"\xff{?}" + # (ref. https://www.disktuna.com/list-of-jpeg-markers/) + # NOTE: File ends with b"\xff\xd9" + if content[0:3] == b"\xff\xd8\xff": return "image/jpeg" # Webp From 71da4a02ecc923c93474b1dfdf7df4dfbacd9dc1 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 2 Oct 2025 10:11:50 +0200 Subject: [PATCH 3/3] added comments to safe import --- client/ayon_core/lib/transcoding.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/ayon_core/lib/transcoding.py b/client/ayon_core/lib/transcoding.py index 36a0caef27..75f0c8bc4d 100644 --- a/client/ayon_core/lib/transcoding.py +++ b/client/ayon_core/lib/transcoding.py @@ -1519,6 +1519,9 @@ def get_media_mime_type(filepath: str) -> Optional[str]: Optional[str]: Mime type or None if is unknown mime type. """ + # The implementation is identical or better with ayon_api >=1.1.0, + # which is used in AYON launcher >=1.3.0. + # NOTE Remove safe import when AYON launcher >=1.2.0. try: from ayon_api.utils import ( get_media_mime_type_for_content as _ayon_api_func