From 2c22ad59b75e23eecfa660b5ac3242c9d233d9fb Mon Sep 17 00:00:00 2001 From: dvirlabs <114520947+dvirlabs@users.noreply.github.com> Date: Thu, 10 Jul 2025 10:11:40 +0300 Subject: [PATCH] Fix libs --- backend/downloader.py | 33 +++++++++++++++++++++++++++++++++ backend/main.py | 35 ----------------------------------- backend/requirements.txt | 3 --- 3 files changed, 33 insertions(+), 38 deletions(-) create mode 100644 backend/downloader.py diff --git a/backend/downloader.py b/backend/downloader.py new file mode 100644 index 0000000..7989718 --- /dev/null +++ b/backend/downloader.py @@ -0,0 +1,33 @@ +import subprocess +import os +from config import settings +import uuid +import requests + +def download_song(query: str): + output_template = os.path.join(settings.MUSIC_DIR, "%(title)s.%(ext)s") + + command = [ + "yt-dlp", + f"ytsearch1:{query}", + "--extract-audio", + "--audio-format", "mp3", + "--output", output_template + ] + + result = subprocess.run(command, capture_output=True, text=True) + + if result.returncode != 0: + raise Exception(f"Download failed: {result.stderr}") + + # Optional: trigger navidrome scan + if settings.NAVIDROME_SCAN_URL: + try: + requests.post(settings.NAVIDROME_SCAN_URL, timeout=5) + except Exception as e: + pass # non-critical + + return { + "query": query, + "log": result.stdout + } \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 69266a7..92755b8 100644 --- a/backend/main.py +++ b/backend/main.py @@ -12,38 +12,3 @@ def download(query: str = Query(..., description="Song name or YouTube search te return JSONResponse(content={"status": "success", **result}) except Exception as e: raise HTTPException(status_code=500, detail=str(e)) - -# downloader.py -import subprocess -import os -from config import settings -import uuid -import requests - -def download_song(query: str): - output_template = os.path.join(settings.MUSIC_DIR, "%(title)s.%(ext)s") - - command = [ - "yt-dlp", - f"ytsearch1:{query}", - "--extract-audio", - "--audio-format", "mp3", - "--output", output_template - ] - - result = subprocess.run(command, capture_output=True, text=True) - - if result.returncode != 0: - raise Exception(f"Download failed: {result.stderr}") - - # Optional: trigger navidrome scan - if settings.NAVIDROME_SCAN_URL: - try: - requests.post(settings.NAVIDROME_SCAN_URL, timeout=5) - except Exception as e: - pass # non-critical - - return { - "query": query, - "log": result.stdout - } \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt index cb359d4..0ea73f9 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,6 +2,3 @@ fastapi uvicorn pydantic requests -downloader -config -urllib2 \ No newline at end of file