Upload files to "/"

This commit is contained in:
2026-11-25 20:20:27 -06:00
parent 9c1e0134d9
commit ce7b8f704e
5 changed files with 2561 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
from dataclasses import dataclass
import re
@dataclass
class TranscodePlan:
input_path: str
video_codec: str
audio_codec: str
target_container: str = "mp4"
# Example rules:
# - If not H.264 or not AAC → transcode
# - If resolution > 1080p → downscale
def plan_transcodes(media_items):
plans = []
for item in media_items:
needs_transcode = False
if item.video_codec != "AVC": # pymediainfo may report H.264 as AVC
needs_transcode = True
if item.audio_codec != "AAC":
needs_transcode = True
if item.width and item.width > 1920:
needs_transcode = True
if needs_transcode:
print(f"Planning transcode for: {item.path}")
plans.append(
TranscodePlan(
input_path=str(item.path),
video_codec="h264",
audio_codec="aac"
)
)
return plans
def sanitize_filename(name: str) -> str:
"""
Make filename filesystem-safe and add _dup before extension.
"""
name = name.replace(":", "-").replace("@", "-").replace("–", "-")
name = re.sub(r"\s+", " ", name).strip()
if "." in name:
base, ext = name.rsplit(".", 1)
return f"{base}_dup.{ext}"
else:
return f"{name}_dup"