mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 03:05:35 +00:00
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
from flask import Blueprint, request
|
|
from app.plugins.lyrics import Lyrics
|
|
from app.utils.hashing import create_hash
|
|
|
|
api = Blueprint("lyricsplugin", __name__, url_prefix="/plugins/lyrics")
|
|
|
|
|
|
@api.route("/search", methods=["POST"])
|
|
def search_lyrics():
|
|
data = request.get_json()
|
|
|
|
title = data.get("title", "")
|
|
artist = data.get("artist", "")
|
|
album = data.get("album", "")
|
|
filepath = data.get("filepath", None)
|
|
|
|
finder = Lyrics()
|
|
|
|
data = finder.search_lyrics_by_title_and_artist(title, artist)
|
|
|
|
if not data:
|
|
return {"downloaded": False, "all": []}, 404
|
|
|
|
perfect_match = data[0]
|
|
|
|
for track in data:
|
|
i_title = track["title"]
|
|
i_album = track["album"]
|
|
|
|
if create_hash(i_title) == create_hash(title) and create_hash(
|
|
i_album
|
|
) == create_hash(album):
|
|
perfect_match = track
|
|
break
|
|
|
|
track_id = perfect_match["track_id"]
|
|
downloaded = finder.download_lyrics_to_path_by_id(track_id, filepath)
|
|
|
|
return {"downloaded": downloaded, "all": data}, 200
|