add methods to open lyric files

+ add api endpoints to check and get lyrics
This commit is contained in:
mungai-njoroge
2023-10-30 17:44:24 +03:00
parent 5fb465c921
commit 2321288be0
2 changed files with 69 additions and 6 deletions
+23 -3
View File
@@ -1,6 +1,6 @@
from flask import Blueprint, request
from app.lib.lyrics import get_lyrics
from app.lib.lyrics import get_lyrics, check_lyrics_file, get_lyrics_from_duplicates
api = Blueprint("lyrics", __name__, url_prefix="")
@@ -13,13 +13,33 @@ def send_lyrics():
data = request.get_json()
filepath = data.get("filepath", None)
trackhash = data.get("trackhash", None)
if filepath is None:
return {"error": "No filepath provided"}, 400
if filepath is None or trackhash is None:
return {"error": "No filepath or trackhash provided"}, 400
lyrics = get_lyrics(filepath)
if lyrics is None:
lyrics = get_lyrics_from_duplicates(trackhash, filepath)
if lyrics is None:
return {"error": "No lyrics found"}, 204
return {"lyrics": lyrics}, 200
@api.route("/lyrics/check", methods=["POST"])
def check_lyrics():
data = request.get_json()
filepath = data.get("filepath", None)
trackhash = data.get("trackhash", None)
if filepath is None or trackhash is None:
return {"error": "No filepath or trackhash provided"}, 400
exists, filepath = check_lyrics_file(filepath, trackhash)
if exists:
return {"filepath": filepath}, 200