add mimetype to source list
This commit is contained in:
parent
63a9a15e67
commit
3a964a6ac3
4 changed files with 64 additions and 5 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -23,13 +23,16 @@
|
||||||
"httpx",
|
"httpx",
|
||||||
"libcurl",
|
"libcurl",
|
||||||
"libx",
|
"libx",
|
||||||
|
"matroska",
|
||||||
"mpegts",
|
"mpegts",
|
||||||
|
"msvideo",
|
||||||
"muxdelay",
|
"muxdelay",
|
||||||
"nodesc",
|
"nodesc",
|
||||||
"noprogress",
|
"noprogress",
|
||||||
"postprocessor",
|
"postprocessor",
|
||||||
"preferredcodec",
|
"preferredcodec",
|
||||||
"preferredquality",
|
"preferredquality",
|
||||||
|
"quicktime",
|
||||||
"tmpfilename",
|
"tmpfilename",
|
||||||
"vcodec",
|
"vcodec",
|
||||||
"vconvert",
|
"vconvert",
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ from .Utils import (
|
||||||
StreamingError,
|
StreamingError,
|
||||||
arg_converter,
|
arg_converter,
|
||||||
calc_download_path,
|
calc_download_path,
|
||||||
|
get_mime_type,
|
||||||
get_sidecar_subtitles,
|
get_sidecar_subtitles,
|
||||||
get_video_info,
|
get_video_info,
|
||||||
validate_url,
|
validate_url,
|
||||||
|
|
@ -1204,15 +1205,18 @@ class HttpAPI(Common):
|
||||||
|
|
||||||
realFile = Path(realFile)
|
realFile = Path(realFile)
|
||||||
|
|
||||||
|
ff_info = await ffprobe(realFile)
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"ffprobe": await ffprobe(realFile),
|
"ffprobe": ff_info,
|
||||||
|
"mimetype": get_mime_type(ff_info.get("metadata", {}), realFile),
|
||||||
"sidecar": get_sidecar_subtitles(realFile),
|
"sidecar": get_sidecar_subtitles(realFile),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, f in enumerate(response["sidecar"]):
|
for i, f in enumerate(response["sidecar"]):
|
||||||
response["sidecar"][i]["file"] = str(Path(realFile).with_name(f["file"].name)).replace(
|
response["sidecar"][i]["file"] = (
|
||||||
self.config.download_path, ""
|
str(Path(realFile).with_name(f["file"].name)).replace(self.config.download_path, "").strip("/")
|
||||||
).strip("/")
|
)
|
||||||
|
|
||||||
return web.json_response(data=response, status=web.HTTPOk.status_code, dumps=self.encoder.encode)
|
return web.json_response(data=response, status=web.HTTPOk.status_code, dumps=self.encoder.encode)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -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}"})
|
files.append({"file": f, "lang": lang, "name": f"{f.suffix[1:].upper()} ({i}) - {lang}"})
|
||||||
|
|
||||||
return files
|
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 <video> tag.
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Extract format name from ffprobe
|
||||||
|
format_name = metadata.get("format_name", "")
|
||||||
|
|
||||||
|
# Define mappings for HTML5-compatible video types
|
||||||
|
format_to_mime = {
|
||||||
|
"matroska": "video/x-matroska", # Default for MKV
|
||||||
|
"webm": "video/webm", # MKV can also be WebM
|
||||||
|
"mp4": "video/mp4",
|
||||||
|
"mov": "video/quicktime",
|
||||||
|
"avi": "video/x-msvideo",
|
||||||
|
"flv": "video/x-flv",
|
||||||
|
"ogg": "video/ogg",
|
||||||
|
"mpegts": "video/mp2t",
|
||||||
|
"3gp": "video/3gpp",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check format_name against known formats
|
||||||
|
if format_name:
|
||||||
|
selected = None
|
||||||
|
for fmt in format_name.split(","):
|
||||||
|
fmt = fmt.strip().lower()
|
||||||
|
if fmt in format_to_mime:
|
||||||
|
selected = format_to_mime[fmt]
|
||||||
|
|
||||||
|
if selected:
|
||||||
|
return selected
|
||||||
|
|
||||||
|
# Fallback: Use Python's mimetypes module
|
||||||
|
import mimetypes
|
||||||
|
|
||||||
|
mime_type, _ = mimetypes.guess_type(str(file_path))
|
||||||
|
if mime_type:
|
||||||
|
return mime_type
|
||||||
|
|
||||||
|
# Final fallback: Return generic binary type
|
||||||
|
return "application/octet-stream"
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<video id="player" ref="video" :poster="thumbnail" :title="title" playsinline>
|
<video id="player" ref="video" :poster="thumbnail" :title="title" playsinline>
|
||||||
<source v-for="source in sources" :key="source.src" :src="source.src" @error="source.onerror" />
|
<source v-for="source in sources" :key="source.src" :src="source.src" @error="source.onerror"
|
||||||
|
:type="source.type" />
|
||||||
<track v-for="track in tracks" :key="track.file" :kind="track.kind" :label="track.label" :srclang="track.lang"
|
<track v-for="track in tracks" :key="track.file" :kind="track.kind" :label="track.label" :srclang="track.lang"
|
||||||
:src="track.file" default />
|
:src="track.file" default />
|
||||||
</video>
|
</video>
|
||||||
|
|
@ -70,6 +71,7 @@ onMounted(async () => {
|
||||||
|
|
||||||
sources.value.push({
|
sources.value.push({
|
||||||
src: makeDownload(config, props.item, 'api/download'),
|
src: makeDownload(config, props.item, 'api/download'),
|
||||||
|
type: response.mimetype,
|
||||||
onerror: e => src_error(e),
|
onerror: e => src_error(e),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue