Upload files to "/"
This commit is contained in:
@@ -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"
|
||||
Reference in New Issue
Block a user