tecuts commited on
Commit
b642c37
·
verified ·
1 Parent(s): 7d46648

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -20,8 +20,7 @@ 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 = "9850d663715d56830e6cdb4d28d19491d8c9d9a8ee31c160a0f5e06116b6d8035fb01c5323ec9690e49a32c0580c0a84e484366df2d6a8ac5786d30a95dc660771fbb372735cb2b39d4081bf30284f08319c0f73f6ad34d3d6bcb4449226877c"
24
- #f10b97c01d087e29c71e1b1950f22
25
  dl = DeeLogin(arl=ARL_TOKEN)
26
 
27
  @app.get("/")
@@ -68,11 +67,23 @@ def download_track(track_id: str, quality: str = "MP3_320"):
68
 
69
  # Check if the file exists
70
  if not os.path.exists(filepath):
71
- logger.error(f"File not found: {filepath}")
72
- raise HTTPException(status_code=500, detail="File download failed")
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  # Return the download URL
75
- download_url = f"/downloads/{filename}"
76
  logger.info(f"Download successful: {download_url}")
77
  return {"download_url": download_url}
78
  except Exception as e:
 
20
  DEEZER_API_URL = "https://api.deezer.com"
21
 
22
  # Deezer ARL token (required for deezspot downloads)
23
+ ARL_TOKEN = "9850d663715d56830e6cdb4d28d19491d8c9d9a8ee31c160a0f5e06116b6d8035fb01c5323ec9690e49a32c0580c0a84e484366df2d6a8ac5786d30a95dc660771fbb372735cb2b39d4081bf30284f08319c0f73f6ad34d3d6bcb4449226877c" # Replace with your ARL token
 
24
  dl = DeeLogin(arl=ARL_TOKEN)
25
 
26
  @app.get("/")
 
67
 
68
  # Check if the file exists
69
  if not os.path.exists(filepath):
70
+ # If the file is not found, search for files in the downloads directory
71
+ logger.warning(f"File not found at expected path: {filepath}")
72
+ logger.warning("Searching for downloaded files in the downloads directory...")
73
+ downloaded_files = os.listdir("downloads")
74
+ logger.warning(f"Files in downloads directory: {downloaded_files}")
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() and artist_name.lower() in file.lower():
79
+ filepath = os.path.join("downloads", file)
80
+ logger.info(f"Found matching file: {filepath}")
81
+ break
82
+ else:
83
+ raise HTTPException(status_code=500, detail="File download failed")
84
 
85
  # Return the download URL
86
+ download_url = f"/downloads/{os.path.basename(filepath)}"
87
  logger.info(f"Download successful: {download_url}")
88
  return {"download_url": download_url}
89
  except Exception as e: