Chrunos commited on
Commit
332ce83
·
verified ·
1 Parent(s): d14d034

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -161,34 +161,46 @@ def download_track(request: DownloadRequest):
161
  raise HTTPException(status_code=500, detail=str(e))
162
 
163
 
 
 
 
 
 
164
  # Fetch album data
165
  @app.post("/album")
166
- def fetch_album(album_id: int = Query(..., description="ID of the album to fetch")):
 
167
  try:
168
  response = requests.get(f"{DEEZER_API_URL}/album/{album_id}")
169
  response.raise_for_status()
170
  return response.json()
171
  except requests.exceptions.RequestException as e:
172
  logger.error(f"Network error fetching album: {e}")
173
- raise HTTPException(status_code=500, detail=str(e))
174
  except Exception as e:
175
  logger.error(f"Error fetching album: {e}")
176
- raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
177
 
178
 
179
  # Fetch playlist data
180
  @app.post("/playlist")
181
- def fetch_playlist(playlist_id: int = Query(..., description="ID of the playlist to fetch")):
 
182
  try:
183
  response = requests.get(f"{DEEZER_API_URL}/playlist/{playlist_id}")
184
  response.raise_for_status()
185
  return response.json()
186
  except requests.exceptions.RequestException as e:
187
  logger.error(f"Network error fetching playlist: {e}")
188
- raise HTTPException(status_code=500, detail=str(e))
189
  except Exception as e:
190
  logger.error(f"Error fetching playlist: {e}")
191
- raise HTTPException(status_code=500, detail=str(e))
192
 
193
 
194
 
 
161
  raise HTTPException(status_code=500, detail=str(e))
162
 
163
 
164
+ # Pydantic model for album request
165
+ class AlbumRequest(BaseModel):
166
+ album_id: str
167
+
168
+
169
  # Fetch album data
170
  @app.post("/album")
171
+ def fetch_album(request: AlbumRequest):
172
+ album_id = request.album_id
173
  try:
174
  response = requests.get(f"{DEEZER_API_URL}/album/{album_id}")
175
  response.raise_for_status()
176
  return response.json()
177
  except requests.exceptions.RequestException as e:
178
  logger.error(f"Network error fetching album: {e}")
179
+ raise HTTPException(status_code = 500, detail=str(e))
180
  except Exception as e:
181
  logger.error(f"Error fetching album: {e}")
182
+ raise HTTPException(status_code = 500, detail=str(e))
183
+
184
+
185
+ # Pydantic model for playlist request
186
+ class PlaylistRequest(BaseModel):
187
+ playlist_id: str
188
 
189
 
190
  # Fetch playlist data
191
  @app.post("/playlist")
192
+ def fetch_playlist(request: PlaylistRequest):
193
+ playlist_id = request.playlist_id
194
  try:
195
  response = requests.get(f"{DEEZER_API_URL}/playlist/{playlist_id}")
196
  response.raise_for_status()
197
  return response.json()
198
  except requests.exceptions.RequestException as e:
199
  logger.error(f"Network error fetching playlist: {e}")
200
+ raise HTTPException(status_code = 500, detail=str(e))
201
  except Exception as e:
202
  logger.error(f"Error fetching playlist: {e}")
203
+ raise HTTPException(status_code = 500, detail=str(e))
204
 
205
 
206