From 3a964a6ac3a78e8f4091effc88bd531de24badc2 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Thu, 27 Feb 2025 19:19:32 +0300 Subject: [PATCH] add mimetype to source list --- .vscode/settings.json | 3 +++ app/library/HttpAPI.py | 12 ++++++--- app/library/Utils.py | 50 +++++++++++++++++++++++++++++++++++ ui/components/VideoPlayer.vue | 4 ++- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f21e8522..ac6857c9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,13 +23,16 @@ "httpx", "libcurl", "libx", + "matroska", "mpegts", + "msvideo", "muxdelay", "nodesc", "noprogress", "postprocessor", "preferredcodec", "preferredquality", + "quicktime", "tmpfilename", "vcodec", "vconvert", diff --git a/app/library/HttpAPI.py b/app/library/HttpAPI.py index 4ffef7b1..c8ac7162 100644 --- a/app/library/HttpAPI.py +++ b/app/library/HttpAPI.py @@ -38,6 +38,7 @@ from .Utils import ( StreamingError, arg_converter, calc_download_path, + get_mime_type, get_sidecar_subtitles, get_video_info, validate_url, @@ -1204,15 +1205,18 @@ class HttpAPI(Common): realFile = Path(realFile) + ff_info = await ffprobe(realFile) + response = { - "ffprobe": await ffprobe(realFile), + "ffprobe": ff_info, + "mimetype": get_mime_type(ff_info.get("metadata", {}), realFile), "sidecar": get_sidecar_subtitles(realFile), } for i, f in enumerate(response["sidecar"]): - response["sidecar"][i]["file"] = str(Path(realFile).with_name(f["file"].name)).replace( - self.config.download_path, "" - ).strip("/") + response["sidecar"][i]["file"] = ( + str(Path(realFile).with_name(f["file"].name)).replace(self.config.download_path, "").strip("/") + ) return web.json_response(data=response, status=web.HTTPOk.status_code, dumps=self.encoder.encode) except Exception as e: diff --git a/app/library/Utils.py b/app/library/Utils.py index 45c26df1..7a986130 100644 --- a/app/library/Utils.py +++ b/app/library/Utils.py @@ -554,3 +554,53 @@ def get_sidecar_subtitles(file: pathlib.Path) -> list[dict]: files.append({"file": f, "lang": lang, "name": f"{f.suffix[1:].upper()} ({i}) - {lang}"}) return files + + +def get_mime_type(metadata: dict, file_path: pathlib.Path) -> str: + """ + Determine the correct MIME type for a video file based on ffprobe metadata. + + Args: + metadata (dict): Parsed JSON output from ffprobe. + file_path (str): The path to the video file for fallback detection. + + Returns: + str: MIME type compatible with HTML5