mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
implement artist split ingore list
+ move post processing of tags to the track model + rebuild stores on settings update via API + check files from the store instead of the db when streaming + remove deprecetated table columns +misc
This commit is contained in:
+14
-114
@@ -7,11 +7,7 @@ from app.api.auth import admin_required
|
||||
|
||||
from app.db.userdata import PluginTable
|
||||
from app.lib.index import index_everything
|
||||
from app.logger import log
|
||||
from app.settings import Info
|
||||
from app.store.albums import AlbumStore
|
||||
from app.store.artists import ArtistStore
|
||||
from app.store.tracks import TrackStore
|
||||
from app.config import UserConfig
|
||||
|
||||
bp_tag = Tag(name="Settings", description="Customize stuff")
|
||||
@@ -24,65 +20,6 @@ def get_child_dirs(parent: str, children: list[str]):
|
||||
return [_dir for _dir in children if _dir.startswith(parent) and _dir != parent]
|
||||
|
||||
|
||||
def reload_everything(instance_key: str):
|
||||
"""
|
||||
Reloads all stores using the current database items
|
||||
"""
|
||||
try:
|
||||
TrackStore.load_all_tracks(instance_key)
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
|
||||
try:
|
||||
AlbumStore.load_albums(instance_key=instance_key)
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
|
||||
try:
|
||||
ArtistStore.load_artists(instance_key)
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
|
||||
|
||||
# CHECKPOINT: TEST SETTINGS API ENDPOINTS
|
||||
|
||||
# @background
|
||||
# def rebuild_store(db_dirs: list[str]):
|
||||
# """
|
||||
# Restarts watchdog and rebuilds the music library.
|
||||
# """
|
||||
# instance_key = get_random_str()
|
||||
|
||||
# log.info("Rebuilding library...")
|
||||
# trackdb.remove_tracks_not_in_folders(db_dirs)
|
||||
# reload_everything(instance_key)
|
||||
|
||||
# try:
|
||||
# populate.Populate(instance_key=instance_key)
|
||||
# except populate.PopulateCancelledError as e:
|
||||
# print(e)
|
||||
# reload_everything(instance_key)
|
||||
# return
|
||||
|
||||
# WatchDog().restart()
|
||||
|
||||
# log.info("Rebuilding library... ✅")
|
||||
|
||||
|
||||
# # I freaking don't know what this function does anymore
|
||||
# def finalize(new_: list[str], removed_: list[str], db_dirs_: list[str]):
|
||||
# """
|
||||
# Params:
|
||||
# new_: will be added to the database
|
||||
# removed_: will be removed from the database
|
||||
# db_dirs_: will be used to remove tracks that
|
||||
# are outside these directories from the database and store.
|
||||
# """
|
||||
# sdb.remove_root_dirs(removed_)
|
||||
# sdb.add_root_dirs(new_)
|
||||
# rebuild_store(db_dirs_)
|
||||
|
||||
|
||||
class AddRootDirsBody(BaseModel):
|
||||
new_dirs: list[str] = Field(
|
||||
description="The new directories to add",
|
||||
@@ -151,18 +88,6 @@ def get_root_dirs():
|
||||
return {"dirs": UserConfig().rootDirs}
|
||||
|
||||
|
||||
# maps settings to their parser flags
|
||||
# mapp = {
|
||||
# "artist_separators": SessionVarKeys.ARTIST_SEPARATORS,
|
||||
# "extract_feat": SessionVarKeys.EXTRACT_FEAT,
|
||||
# "remove_prod": SessionVarKeys.REMOVE_PROD,
|
||||
# "clean_album_title": SessionVarKeys.CLEAN_ALBUM_TITLE,
|
||||
# "remove_remaster": SessionVarKeys.REMOVE_REMASTER_FROM_TRACK,
|
||||
# "merge_albums": SessionVarKeys.MERGE_ALBUM_VERSIONS,
|
||||
# "show_albums_as_singles": SessionVarKeys.SHOW_ALBUMS_AS_SINGLES,
|
||||
# }
|
||||
|
||||
|
||||
@api.get("")
|
||||
def get_all_settings():
|
||||
"""
|
||||
@@ -176,11 +101,6 @@ def get_all_settings():
|
||||
return config
|
||||
|
||||
|
||||
# @background
|
||||
# def reload_all_for_set_setting():
|
||||
# reload_everything(get_random_str())
|
||||
|
||||
|
||||
class SetSettingBody(BaseModel):
|
||||
key: str = Field(
|
||||
description="The setting key",
|
||||
@@ -192,39 +112,6 @@ class SetSettingBody(BaseModel):
|
||||
)
|
||||
|
||||
|
||||
# @api.post("/set")
|
||||
# @admin_required()
|
||||
# def set_setting(body: SetSettingBody):
|
||||
# """
|
||||
# Set a setting.
|
||||
# """
|
||||
# key = body.key
|
||||
# value = body.value
|
||||
|
||||
# if key is None or value is None or key == "root_dirs":
|
||||
# return {"msg": "Invalid arguments!"}, 400
|
||||
|
||||
# root_dir = sdb.get_root_dirs()
|
||||
|
||||
# if not root_dir:
|
||||
# return {"msg": "No root directories set!"}, 400
|
||||
|
||||
# if key not in mapp:
|
||||
# return {"msg": "Invalid key!"}, 400
|
||||
|
||||
# if key == "artist_separators":
|
||||
# value = str(value).split(",")
|
||||
# value = set(value)
|
||||
|
||||
# reload_all_for_set_setting()
|
||||
|
||||
# # if value is a set, convert it to a string
|
||||
# # (artist_separators)
|
||||
# if type(value) == set:
|
||||
# value = ",".join(value)
|
||||
|
||||
# return {"result": value}
|
||||
|
||||
@api.get("/trigger-scan")
|
||||
def trigger_scan():
|
||||
"""
|
||||
@@ -256,7 +143,20 @@ def update_config(body: UpdateConfigBody):
|
||||
body.value = body.value.split(",")
|
||||
|
||||
setattr(config, body.key, body.value)
|
||||
print(getattr(config, body.key))
|
||||
|
||||
# INFO: Rebuild stores when these settings are updated
|
||||
reset_stores_lists = {
|
||||
"artistSeparators",
|
||||
"artistSplitIgnoreList",
|
||||
"removeProdBy",
|
||||
"removeRemasterInfo",
|
||||
"mergeAlbums",
|
||||
"cleanAlbumTitle",
|
||||
"showAlbumsAsSingles",
|
||||
}
|
||||
|
||||
if body.key in reset_stores_lists:
|
||||
index_everything()
|
||||
|
||||
return {
|
||||
"msg": "Config updated!",
|
||||
|
||||
+38
-8
@@ -10,8 +10,7 @@ from pydantic import BaseModel, Field
|
||||
from app.api.apischemas import TrackHashSchema
|
||||
from app.lib.trackslib import get_silence_paddings
|
||||
|
||||
# from app.store.tracks import TrackStore
|
||||
from app.db.libdata import TrackTable
|
||||
from app.store.tracks import TrackStore
|
||||
from app.utils.files import guess_mime_type
|
||||
|
||||
bp_tag = Tag(name="File", description="Audio files")
|
||||
@@ -35,10 +34,26 @@ def send_track_file_legacy(path: TrackHashSchema, query: SendTrackFileQuery):
|
||||
filepath = query.filepath
|
||||
msg = {"msg": "File Not Found"}
|
||||
|
||||
track = TrackTable.get_track_by_trackhash(trackhash, filepath)
|
||||
track_exists = track is not None and os.path.exists(track.filepath)
|
||||
track = None
|
||||
tracks = TrackStore.get_tracks_by_filepaths([filepath])
|
||||
|
||||
if track_exists:
|
||||
|
||||
if len(tracks) > 0 and os.path.exists(filepath):
|
||||
track = tracks[0]
|
||||
else:
|
||||
res = TrackStore.trackhashmap.get(trackhash)
|
||||
|
||||
# When finding by trackhash, sort by bitrate
|
||||
# and get the first track that exists
|
||||
if res is not None:
|
||||
tracks = sorted(res.tracks, key=lambda x: x.bitrate, reverse=True)
|
||||
|
||||
for t in tracks:
|
||||
if os.path.exists(t.filepath):
|
||||
track = t
|
||||
break
|
||||
|
||||
if track is not None:
|
||||
audio_type = guess_mime_type(filepath)
|
||||
return send_file(filepath, mimetype=audio_type, conditional=True)
|
||||
|
||||
@@ -57,10 +72,25 @@ def send_track_file(path: TrackHashSchema, query: SendTrackFileQuery):
|
||||
msg = {"msg": "File Not Found"}
|
||||
|
||||
# If filepath is provided, try to send that
|
||||
track = TrackTable.get_track_by_trackhash(trackhash, filepath)
|
||||
track_exists = track is not None and os.path.exists(track.filepath)
|
||||
track = None
|
||||
tracks = TrackStore.get_tracks_by_filepaths([filepath])
|
||||
|
||||
if track_exists:
|
||||
if len(tracks) > 0 and os.path.exists(filepath):
|
||||
track = tracks[0]
|
||||
else:
|
||||
res = TrackStore.trackhashmap.get(trackhash)
|
||||
|
||||
# When finding by trackhash, sort by bitrate
|
||||
# and get the first track that exists
|
||||
if res is not None:
|
||||
tracks = sorted(res.tracks, key=lambda x: x.bitrate, reverse=True)
|
||||
|
||||
for t in tracks:
|
||||
if os.path.exists(t.filepath):
|
||||
track = t
|
||||
break
|
||||
|
||||
if track is not None:
|
||||
audio_type = guess_mime_type(filepath)
|
||||
return send_file_as_chunks(track.filepath, audio_type)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user