Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,15 @@ import os
|
|
5 |
import logging
|
6 |
from typing import Optional
|
7 |
from fastapi.staticfiles import StaticFiles
|
|
|
8 |
|
9 |
# Set up logging
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
logger = logging.getLogger(__name__)
|
12 |
|
13 |
app = FastAPI(title="Deezer API")
|
|
|
|
|
14 |
|
15 |
# Mount a static files directory to serve downloaded files
|
16 |
os.makedirs("downloads", exist_ok=True)
|
@@ -20,12 +23,12 @@ app.mount("/downloads", StaticFiles(directory="downloads"), name="downloads")
|
|
20 |
DEEZER_API_URL = "https://api.deezer.com"
|
21 |
|
22 |
# Deezer ARL token (required for deezspot downloads)
|
23 |
-
ARL_TOKEN =
|
24 |
dl = DeeLogin(arl=ARL_TOKEN)
|
25 |
|
26 |
@app.get("/")
|
27 |
def read_root():
|
28 |
-
return {"message": "
|
29 |
|
30 |
# Fetch track metadata from Deezer API
|
31 |
@app.get("/track/{track_id}")
|
@@ -75,7 +78,7 @@ def download_track(track_id: str, quality: str = "MP3_320"):
|
|
75 |
|
76 |
# Try to find the file with a similar name
|
77 |
for file in downloaded_files:
|
78 |
-
if track_title.lower() in file.lower()
|
79 |
filepath = os.path.join("downloads", file)
|
80 |
logger.info(f"Found matching file: {filepath}")
|
81 |
break
|
|
|
5 |
import logging
|
6 |
from typing import Optional
|
7 |
from fastapi.staticfiles import StaticFiles
|
8 |
+
from dotenv import load_dotenv
|
9 |
|
10 |
# Set up logging
|
11 |
logging.basicConfig(level=logging.INFO)
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
app = FastAPI(title="Deezer API")
|
15 |
+
# Load environment variables
|
16 |
+
load_dotenv()
|
17 |
|
18 |
# Mount a static files directory to serve downloaded files
|
19 |
os.makedirs("downloads", exist_ok=True)
|
|
|
23 |
DEEZER_API_URL = "https://api.deezer.com"
|
24 |
|
25 |
# Deezer ARL token (required for deezspot downloads)
|
26 |
+
ARL_TOKEN = os.get_env('ARL')
|
27 |
dl = DeeLogin(arl=ARL_TOKEN)
|
28 |
|
29 |
@app.get("/")
|
30 |
def read_root():
|
31 |
+
return {"message": "running}"}
|
32 |
|
33 |
# Fetch track metadata from Deezer API
|
34 |
@app.get("/track/{track_id}")
|
|
|
78 |
|
79 |
# Try to find the file with a similar name
|
80 |
for file in downloaded_files:
|
81 |
+
if track_title.lower() in file.lower() or artist_name.lower() in file.lower():
|
82 |
filepath = os.path.join("downloads", file)
|
83 |
logger.info(f"Found matching file: {filepath}")
|
84 |
break
|