Hash video profile paths
This commit is contained in:
parent
954608c5f9
commit
2ad0536bb0
5 changed files with 180 additions and 28 deletions
|
|
@ -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}")
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue