Chrunos commited on
Commit
179ee8b
·
verified ·
1 Parent(s): 6a2ee0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
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
- song_json = jsonify(first_song)
121
- videoId = song_json["videoId"]
122
- ym_url = f'https://www.youtube.com/watch?v={videoId}'
123
- return {"filename": {title}, "url": ym_url}
 
 
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")