add lyrics route and methods

This commit is contained in:
mungai-njoroge
2023-10-29 13:47:03 +03:00
parent 123dd1eca7
commit 5fb465c921
3 changed files with 84 additions and 0 deletions
+2
View File
@@ -17,6 +17,7 @@ from app.api import (
search,
send_file,
settings,
lyrics
)
@@ -43,5 +44,6 @@ def create_api():
app.register_blueprint(imgserver.api)
app.register_blueprint(settings.api)
app.register_blueprint(colors.api)
app.register_blueprint(lyrics.api)
return app
+25
View File
@@ -0,0 +1,25 @@
from flask import Blueprint, request
from app.lib.lyrics import get_lyrics
api = Blueprint("lyrics", __name__, url_prefix="")
@api.route("/lyrics", methods=["POST"])
def send_lyrics():
"""
Returns the lyrics for a track
"""
data = request.get_json()
filepath = data.get("filepath", None)
if filepath is None:
return {"error": "No filepath provided"}, 400
lyrics = get_lyrics(filepath)
if lyrics is None:
return {"error": "No lyrics found"}, 204
return {"lyrics": lyrics}, 200