mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
add methods to open lyric files
+ add api endpoints to check and get lyrics
This commit is contained in:
+23
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user