diff --git a/backend/config.py b/backend/config.py index ced148b..15700b7 100644 --- a/backend/config.py +++ b/backend/config.py @@ -1,10 +1,12 @@ from pydantic_settings import BaseSettings +from pydantic import Field class Settings(BaseSettings): - MUSIC_DIR: str = "/music" - NAVIDROME_SCAN_URL: str = "" + MUSIC_DIR: str = Field(default="/music", description="Path where songs are saved") + NAVIDROME_SCAN_URL: str = Field(default="", description="URL to trigger Navidrome rescan") class Config: env_file = ".env" + env_file_encoding = "utf-8" settings = Settings() diff --git a/backend/downloader.py b/backend/downloader.py index 7989718..83d567c 100644 --- a/backend/downloader.py +++ b/backend/downloader.py @@ -1,33 +1,36 @@ 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 + "--output", output_template, + "--no-playlist", + "--quiet" ] result = subprocess.run(command, capture_output=True, text=True) if result.returncode != 0: - raise Exception(f"Download failed: {result.stderr}") + raise Exception(f"❌ Download failed:\n{result.stderr}") - # Optional: trigger navidrome scan + # Optional: trigger Navidrome rescan if settings.NAVIDROME_SCAN_URL: try: - requests.post(settings.NAVIDROME_SCAN_URL, timeout=5) + res = requests.get(settings.NAVIDROME_SCAN_URL, timeout=5) + res.raise_for_status() except Exception as e: - pass # non-critical + print(f"⚠️ Failed to trigger Navidrome rescan: {e}") return { + "status": "success", "query": query, - "log": result.stdout - } \ No newline at end of file + "log": result.stdout + "\n" + result.stderr + }