- FastAPI backend (auth, jobs, SSE, download) - Frontend: drag&drop + YouTube URL + jobs panel - Pipeline: yt_download → find_chorus → reframe → subtitle - Modes: track (face follow), center, blur - Whisper for SI/DE/EN subtitles - Auto-chorus detection via Whisper + RMS energy - Docker + Coolify ready
81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
yt_download.py — Download YouTube video v 1080p (16:9) za reels pipeline.
|
|
|
|
Primer:
|
|
python3 yt_download.py "https://youtu.be/dQw4w9WgXcQ" /data/uploads/video.mp4
|
|
"""
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
import json
|
|
|
|
|
|
def download(url, output, max_height=1080, format_str=None):
|
|
"""
|
|
Download YT video. Privzeto: best mp4 ≤1080p z audiotrackom.
|
|
"""
|
|
if format_str is None:
|
|
format_str = (
|
|
f"bestvideo[height<={max_height}][ext=mp4]+bestaudio[ext=m4a]/"
|
|
f"best[height<={max_height}][ext=mp4]/best"
|
|
)
|
|
|
|
cmd = [
|
|
"yt-dlp",
|
|
"-f", format_str,
|
|
"--merge-output-format", "mp4",
|
|
"--no-playlist",
|
|
"--write-info-json",
|
|
"--restrict-filenames",
|
|
"-o", str(output),
|
|
url,
|
|
]
|
|
print(f"⬇ Downloading {url}...", file=sys.stderr)
|
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
if result.returncode != 0:
|
|
print(f"❌ yt-dlp napaka:\n{result.stderr[-1500:]}", file=sys.stderr)
|
|
sys.exit(1)
|
|
print(f"✅ {output}", file=sys.stderr)
|
|
return output
|
|
|
|
|
|
def get_info(url):
|
|
"""Vrni metadata brez prenosa."""
|
|
cmd = ["yt-dlp", "--dump-json", "--no-playlist", url]
|
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
if result.returncode != 0:
|
|
return None
|
|
return json.loads(result.stdout.strip().split("\n")[0])
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("url")
|
|
ap.add_argument("output")
|
|
ap.add_argument("--max-height", type=int, default=1080)
|
|
ap.add_argument("--info-only", action="store_true",
|
|
help="Samo metadata, brez prenosa")
|
|
args = ap.parse_args()
|
|
|
|
if args.info_only:
|
|
info = get_info(args.url)
|
|
if info:
|
|
print(json.dumps({
|
|
"title": info.get("title"),
|
|
"duration": info.get("duration"),
|
|
"uploader": info.get("uploader"),
|
|
"thumbnail": info.get("thumbnail"),
|
|
}, indent=2))
|
|
else:
|
|
print("❌ Ne morem dobiti info", file=sys.stderr)
|
|
sys.exit(1)
|
|
return
|
|
|
|
download(args.url, args.output, max_height=args.max_height)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|