Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@
DOWNLOAD_DIR = os.path.join(os.path.dirname(__file__), "downloads")
os.makedirs(DOWNLOAD_DIR, exist_ok=True)

# Path to yt-dlp (use Homebrew version which has YouTube fixes)
YT_DLP_PATH = os.environ.get("YT_DLP_PATH", "/opt/homebrew/bin/yt-dlp")

# Browser for yt-dlp cookie extraction (set to empty string to disable)
COOKIES_BROWSER = os.environ.get("COOKIES_BROWSER", "brave")

# Build --cookies-from-browser args if configured
COOKIE_ARGS = ["--cookies-from-browser", COOKIES_BROWSER] if COOKIES_BROWSER else []

jobs = {}


def run_download(job_id, url, format_choice, format_id):
job = jobs[job_id]
out_template = os.path.join(DOWNLOAD_DIR, f"{job_id}.%(ext)s")

cmd = ["yt-dlp", "--no-playlist", "-o", out_template]
cmd = [YT_DLP_PATH, "--no-playlist", "-o", out_template]
cmd += COOKIE_ARGS
cmd += ["--extractor-retries", "3", "--retries", "5"]

if format_choice == "audio":
cmd += ["-x", "--audio-format", "mp3"]
Expand Down Expand Up @@ -85,7 +96,7 @@ def get_info():
if not url:
return jsonify({"error": "No URL provided"}), 400

cmd = ["yt-dlp", "--no-playlist", "-j", url]
cmd = [YT_DLP_PATH, "--no-playlist"] + COOKIE_ARGS + ["-j", url]
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
if result.returncode != 0:
Expand Down