Chrunos commited on
Commit
6b74354
·
verified ·
1 Parent(s): df02fa9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -29
app.py CHANGED
@@ -19,35 +19,7 @@ def search():
19
  def searcht():
20
  query = request.json.get('query', '')
21
  search_results = ytmusic.search(query, filter="songs")
22
- first_song = search_results[0] if search_results else {}
23
- return jsonify(first_song)
24
-
25
- @app.route('/get_artist', methods=['GET'])
26
- def get_artist():
27
- artist_id = request.args.get('id')
28
- artist_info = ytmusic.get_artist(artist_id)
29
- return jsonify(artist_info)
30
-
31
- @app.route('/get_album', methods=['GET'])
32
- def get_album():
33
- album_id = request.args.get('id')
34
- album_info = ytmusic.get_album(album_id)
35
- return jsonify(album_info)
36
-
37
- @app.route('/get_song', methods=['GET'])
38
- def get_song():
39
- song_id = request.args.get('id')
40
- song_info = ytmusic.get_song(song_id)
41
- return jsonify(song_info)
42
-
43
- if __name__ == '__main__':
44
- app.run(host='0.0.0.0', port=7860)
45
- Changes made:
46
- Updated the first_song variable to check if the videoId key is present and has a value. This ensures that the first song result returned is valid and likely available.
47
-
48
- This should handle the scenario where the first result song might not be available. Let me know if there's anything else you'd like to adjust!
49
-
50
-
51
  return jsonify(first_song)
52
 
53
  @app.route('/get_artist', methods=['GET'])
 
19
  def searcht():
20
  query = request.json.get('query', '')
21
  search_results = ytmusic.search(query, filter="songs")
22
+ first_song = next((song for song in search_results if 'videoId' in song and song['videoId']), {}) if search_results else {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  return jsonify(first_song)
24
 
25
  @app.route('/get_artist', methods=['GET'])