Hash video profile paths

This commit is contained in:
Abel Luck 2026-03-31 15:01:49 +02:00
parent 954608c5f9
commit 2ad0536bb0
5 changed files with 180 additions and 28 deletions

View file

@ -170,6 +170,10 @@ def _frame_rate(stream: Dict[str, Any]) -> Optional[str]:
return None
def _scale_to_max_height(max_height: int) -> str:
return f"scale=-2:{max_height}"
def audio_meta(probe: Dict[str, Any]) -> Optional[AudioMeta]:
stream = primary_audio_stream(probe)
if not stream:
@ -303,7 +307,7 @@ def video_transcode_params(
params = {"extension": settings["extension"]}
if len(passes) == 0 or is_vcodec:
if not is_good_height:
params["vf"] = f"scale={width}:{height}"
params["vf"] = _scale_to_max_height(max_height)
if not is_vcodec:
params.update(settings["ffmpeg_video_params"])
if not is_acodec or not is_audio_bitrate:
@ -313,7 +317,7 @@ def video_transcode_params(
for p in passes:
p = copy.deepcopy(p)
if not is_good_height:
p["vf"] = f"scale={width}:{height}"
p["vf"] = _scale_to_max_height(max_height)
params["passes"].append(p)
return params

View file

@ -1,4 +1,5 @@
import hashlib
import json
import mimetypes
from enum import Enum
from pathlib import Path
@ -42,8 +43,23 @@ def local_audio_path(s: str) -> str:
return local_file_path(s)
def variant_media_path(base_path: str, profile: Mapping[str, Any]) -> str:
return f"{base_path}-{profile['name']}.{profile['extension']}"
def profile_settings_hash(profile: Mapping[str, Any]) -> str:
settings = {
key: value
for key, value in profile.items()
if key not in {"name", "mimetype", "extension"}
}
payload = json.dumps(settings, sort_keys=True, separators=(",", ":"))
return hashlib.sha1(to_bytes(payload)).hexdigest()[:8] # nosec
def variant_media_path(
base_path: str, profile: Mapping[str, Any], *, hashed: bool = False
) -> str:
profile_name = str(profile["name"])
if hashed:
profile_name = f"{profile_name}-{profile_settings_hash(profile)}"
return f"{base_path}-{profile_name}.{profile['extension']}"
def published_media_path(
@ -52,7 +68,7 @@ def published_media_path(
if file_type == FileType.AUDIO:
return variant_media_path(local_audio_path(source_url), profile)
if file_type == FileType.VIDEO:
return variant_media_path(local_video_path(source_url), profile)
return variant_media_path(local_video_path(source_url), profile, hashed=True)
raise ValueError(f"Unsupported file type for published media path: {file_type}")