Update app.py
Browse files
app.py
CHANGED
@@ -117,10 +117,12 @@ async def match():
|
|
117 |
title = track_info["entitiesByUniqueId"][entityUniqueId]["title"]
|
118 |
search_results = ytmusic.search(title, filter="songs")
|
119 |
first_song = next((song for song in search_results if 'videoId' in song and song['videoId']), {}) if search_results else {}
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
124 |
|
125 |
# If no URLs found, return an error
|
126 |
raise HTTPException(status_code=404, detail="No matching URL found")
|
|
|
117 |
title = track_info["entitiesByUniqueId"][entityUniqueId]["title"]
|
118 |
search_results = ytmusic.search(title, filter="songs")
|
119 |
first_song = next((song for song in search_results if 'videoId' in song and song['videoId']), {}) if search_results else {}
|
120 |
+
if 'videoId' in first_song:
|
121 |
+
videoId = first_song["videoId"]
|
122 |
+
ym_url = f'https://www.youtube.com/watch?v={videoId}'
|
123 |
+
return {"filename": title, "url": ym_url}
|
124 |
+
else:
|
125 |
+
raise HTTPException(status_code=404, detail="Video ID not found")
|
126 |
|
127 |
# If no URLs found, return an error
|
128 |
raise HTTPException(status_code=404, detail="No matching URL found")
|