feat: fetch beat metadata from api
This commit is contained in:
38
api.py
38
api.py
@@ -753,6 +753,44 @@ def playlist(playlist_id):
|
||||
})
|
||||
|
||||
|
||||
@app.route("/metadata", methods=["GET"])
|
||||
@require_auth
|
||||
def get_metadata():
|
||||
track_id = request.args.get("trackId")
|
||||
meta_type = request.args.get("type", "beats")
|
||||
|
||||
if not track_id:
|
||||
return jsonify({"ok": False, "error": "Missing trackId"}), 400
|
||||
|
||||
access_token = g.spotify_access_token
|
||||
profile = spotify_get_me(access_token)
|
||||
spotify_user_id = profile["id"]
|
||||
|
||||
conn = db()
|
||||
row = conn.execute("""
|
||||
SELECT file_name FROM uploaded_metadata
|
||||
WHERE spotify_user_id = ? AND track_id = ? AND type = ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
""", (spotify_user_id, track_id, meta_type)).fetchone()
|
||||
conn.close()
|
||||
|
||||
if not row:
|
||||
return jsonify({"ok": False, "error": "Not found"}), 404
|
||||
|
||||
file_path = os.path.join(METADATA_UPLOAD_DIR, row["file_name"])
|
||||
if not os.path.isfile(file_path):
|
||||
return jsonify({"ok": False, "error": "Not found"}), 404
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
collection = json.load(f)
|
||||
|
||||
if not isinstance(collection, dict):
|
||||
return jsonify({"ok": False, "error": "Invalid metadata file"}), 500
|
||||
|
||||
return jsonify({"ok": True, "collection": collection})
|
||||
|
||||
|
||||
@app.route("/metadata", methods=["POST"])
|
||||
@require_auth
|
||||
def upload_metadata():
|
||||
|
||||
Reference in New Issue
Block a user