Fix config.py and downloader.py
This commit is contained in:
parent
d15223f2cb
commit
e5a151ce99
@ -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()
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import subprocess
|
||||
import os
|
||||
from config import settings
|
||||
import uuid
|
||||
import requests
|
||||
|
||||
def download_song(query: str):
|
||||
@ -12,22 +11,26 @@ def download_song(query: str):
|
||||
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
|
||||
"log": result.stdout + "\n" + result.stderr
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user