mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
set up plugins
This commit is contained in:
+7
-1
@@ -6,6 +6,7 @@ from flask import Flask
|
||||
from flask_compress import Compress
|
||||
from flask_cors import CORS
|
||||
|
||||
from .plugins import lyrics as lyrics_plugin
|
||||
from app.api import (
|
||||
album,
|
||||
artist,
|
||||
@@ -17,7 +18,8 @@ from app.api import (
|
||||
search,
|
||||
send_file,
|
||||
settings,
|
||||
lyrics
|
||||
lyrics,
|
||||
plugins,
|
||||
)
|
||||
|
||||
|
||||
@@ -46,4 +48,8 @@ def create_api():
|
||||
app.register_blueprint(colors.api)
|
||||
app.register_blueprint(lyrics.api)
|
||||
|
||||
# Plugins
|
||||
app.register_blueprint(plugins.api)
|
||||
app.register_blueprint(lyrics_plugin.api)
|
||||
|
||||
return app
|
||||
|
||||
@@ -56,3 +56,4 @@ def check_lyrics():
|
||||
exists = get_lyrics_from_tags(filepath, just_check=True)
|
||||
|
||||
return {"exists": exists}, 200
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from flask import Blueprint, request
|
||||
|
||||
from app.db.sqlite.plugins import PluginsMethods
|
||||
|
||||
|
||||
api = Blueprint("plugins", __name__, url_prefix="/plugins")
|
||||
|
||||
|
||||
@api.route("/", methods=["GET"])
|
||||
def get_all_plugins():
|
||||
plugins = PluginsMethods.get_all_plugins()
|
||||
|
||||
return {"plugins": plugins}
|
||||
|
||||
|
||||
@api.route("/setactive", methods=["GET"])
|
||||
def activate_deactivate_plugin():
|
||||
name = request.args.get("plugin", None)
|
||||
state = request.args.get("state", None)
|
||||
|
||||
if not name or not state:
|
||||
return {"error": "Missing plugin or state"}, 400
|
||||
|
||||
PluginsMethods.plugin_set_active(name, int(state))
|
||||
|
||||
return {"message": "OK"}, 200
|
||||
@@ -0,0 +1,39 @@
|
||||
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
|
||||
Reference in New Issue
Block a user