From 8ff283cbcbc1cfb2900f406dcf201929f93b4d8b Mon Sep 17 00:00:00 2001 From: cwilvx Date: Sun, 8 Dec 2024 16:20:58 +0300 Subject: [PATCH] update mix api endpoint payload shape --- TODO.md | 2 +- app/plugins/mixes.py | 3 ++- app/store/tracks.py | 16 ++++++++++++++++ manage.py | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index cd34050f..b668a9db 100644 --- a/TODO.md +++ b/TODO.md @@ -21,7 +21,7 @@ -# DONE + # DONE - Support auth headers - Add recently played playlist diff --git a/app/plugins/mixes.py b/app/plugins/mixes.py index 174b3dca..0c3a2b29 100644 --- a/app/plugins/mixes.py +++ b/app/plugins/mixes.py @@ -79,7 +79,8 @@ class MixesPlugin(Plugin): """ queries = [ { - "query": f"{track.title} - {','.join(a['name'] for a in track.artists)}", + "title": track.title, + "artists": [a["name"] for a in track.artists], "album": track.og_album, "with_help": with_help, } diff --git a/app/store/tracks.py b/app/store/tracks.py index cc82efc8..7b0524cf 100644 --- a/app/store/tracks.py +++ b/app/store/tracks.py @@ -1,6 +1,7 @@ # from tqdm import tqdm import itertools +import json from typing import Callable, Iterable from app.db.libdata import TrackTable @@ -313,3 +314,18 @@ class TrackStore: def get_recently_played(cls, limit: int): tracks = cls.get_flat_list() return sorted(tracks, key=lambda x: x.lastplayed, reverse=True)[:limit] + + @classmethod + def export(cls): + path = "tracks.json" + + with open(path, "w") as f: + data = [ + { + "title": t.title, + "album": t.album, + "artists": [a["name"] for a in t.artists], + } + for t in cls.get_flat_list() + ] + json.dump(data, f) diff --git a/manage.py b/manage.py index afdb7a85..d6fe3f3e 100644 --- a/manage.py +++ b/manage.py @@ -27,6 +27,7 @@ from app.plugins.register import register_plugins from app.settings import FLASKVARS, TCOLOR, Info from app.setup import load_into_mem, run_setup from app.start_info_logger import log_startup_info +from app.store.tracks import TrackStore from app.utils.filesystem import get_home_res_path from app.utils.paths import getClientFilesExtensions from app.utils.threading import background @@ -227,6 +228,7 @@ if __name__ == "__main__": load_into_mem() run_swingmusic() + TrackStore.export() host = FLASKVARS.get_flask_host() port = FLASKVARS.get_flask_port()