Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, jsonify, request
|
| 2 |
+
from ytmusicapi import YTMusic
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
ytmusic = YTMusic()
|
| 7 |
+
|
| 8 |
+
@app.route('/')
|
| 9 |
+
def index():
|
| 10 |
+
return render_template('index.html')
|
| 11 |
+
|
| 12 |
+
@app.route('/search', methods=['POST'])
|
| 13 |
+
def search():
|
| 14 |
+
query = request.json.get('query', '')
|
| 15 |
+
search_results = ytmusic.search(query, filter="songs")
|
| 16 |
+
return jsonify(search_results)
|
| 17 |
+
|
| 18 |
+
@app.route('/get_artist', methods=['GET'])
|
| 19 |
+
def get_artist():
|
| 20 |
+
artist_id = request.args.get('id')
|
| 21 |
+
artist_info = ytmusic.get_artist(artist_id)
|
| 22 |
+
return jsonify(artist_info)
|
| 23 |
+
|
| 24 |
+
@app.route('/get_album', methods=['GET'])
|
| 25 |
+
def get_album():
|
| 26 |
+
album_id = request.args.get('id')
|
| 27 |
+
album_info = ytmusic.get_album(album_id)
|
| 28 |
+
return jsonify(album_info)
|
| 29 |
+
|
| 30 |
+
if __name__ == '__main__':
|
| 31 |
+
app.run(debug=True)
|