Fix libs
This commit is contained in:
parent
735b15e80a
commit
2c22ad59b7
33
backend/downloader.py
Normal file
33
backend/downloader.py
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -12,38 +12,3 @@ def download(query: str = Query(..., description="Song name or YouTube search te
|
|||||||
return JSONResponse(content={"status": "success", **result})
|
return JSONResponse(content={"status": "success", **result})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(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
|
|
||||||
}
|
|
||||||
@ -2,6 +2,3 @@ fastapi
|
|||||||
uvicorn
|
uvicorn
|
||||||
pydantic
|
pydantic
|
||||||
requests
|
requests
|
||||||
downloader
|
|
||||||
config
|
|
||||||
urllib2
|
|
||||||
Loading…
x
Reference in New Issue
Block a user