diff --git a/app/api/artist.py b/app/api/artist.py index a25e300..4106c05 100644 --- a/app/api/artist.py +++ b/app/api/artist.py @@ -48,9 +48,9 @@ class ArtistsCache: """ for (index, albums) in enumerate(cls.artists): if albums.artisthash == artisthash: - return (albums.albums, index) + return albums.albums, index - return ([], -1) + return [], -1 @classmethod def albums_cached(cls, artisthash: str) -> bool: @@ -214,7 +214,6 @@ def get_artist_albums(artisthash: str): limit = int(limit) - all_albums = [] is_cached = ArtistsCache.albums_cached(artisthash) if not is_cached: diff --git a/app/api/folder.py b/app/api/folder.py index 370070a..36132c7 100644 --- a/app/api/folder.py +++ b/app/api/folder.py @@ -22,6 +22,7 @@ def get_folder_tree(): Returns a list of all the folders and tracks in the given folder. """ data = request.get_json() + req_dir = "$home" if data is not None: try: @@ -60,7 +61,6 @@ def get_folder_tree(): else: req_dir = "/" + req_dir + "/" if not req_dir.startswith("/") else req_dir + "/" - print(req_dir) tracks, folders = GetFilesAndDirs(req_dir)() return { @@ -127,9 +127,3 @@ def list_folders(): return { "folders": sorted(dirs, key=lambda i: i["name"]), } - -# todo: - -# - handle showing windows disks in root_dir configuration -# - handle the above, but for all partitions mounted in linux. -# - handle the "\" in client's folder page breadcrumb diff --git a/app/api/playlist.py b/app/api/playlist.py index bfae768..c9100ed 100644 --- a/app/api/playlist.py +++ b/app/api/playlist.py @@ -97,7 +97,7 @@ def add_track_to_playlist(playlist_id: str): return {"error": "Track already exists in playlist"}, 409 add_artist_to_playlist(int(playlist_id), trackhash) - PL.update_last_updated(playlist_id) + PL.update_last_updated(int(playlist_id)) return {"msg": "Done"}, 200 diff --git a/app/api/search.py b/app/api/search.py index afd3515..6218820 100644 --- a/app/api/search.py +++ b/app/api/search.py @@ -199,20 +199,20 @@ def search_load_more(): if s_type == "tracks": t = SearchResults.tracks return { - "tracks": t[index : index + SEARCH_COUNT], + "tracks": t[index: index + SEARCH_COUNT], "more": len(t) > index + SEARCH_COUNT, } elif s_type == "albums": a = SearchResults.albums return { - "albums": a[index : index + SEARCH_COUNT], + "albums": a[index: index + SEARCH_COUNT], "more": len(a) > index + SEARCH_COUNT, } elif s_type == "artists": a = SearchResults.artists return { - "artists": a[index : index + SEARCH_COUNT], + "artists": a[index: index + SEARCH_COUNT], "more": len(a) > index + SEARCH_COUNT, } diff --git a/app/db/sqlite/playlists.py b/app/db/sqlite/playlists.py index f367c78..0e38ad2 100644 --- a/app/db/sqlite/playlists.py +++ b/app/db/sqlite/playlists.py @@ -90,23 +90,9 @@ class SQLitePlaylistMethods: @staticmethod def add_item_to_json_list(playlist_id: int, field: str, items: list[str]): """ - Adds a string item to a json dumped list using a playlist id and field name. Takes the playlist ID, a field name, an item to add to the field, and an error to raise if the item is already in the field. - - Parameters - ---------- - playlist_id : int - The ID of the playlist to add the item to. - field : str - The field in the database that you want to add the item to. - item : str - The item to add to the list. - error : Exception - The error to raise if the item is already in the list. - - Returns - ------- - A list of strings. - + Adds a string item to a json dumped list using a playlist id and field name. + Takes the playlist ID, a field name, + an item to add to the field, and an error to raise if the item is already in the field. """ sql = f"SELECT {field} FROM playlists WHERE id = ?" diff --git a/app/db/sqlite/tracks.py b/app/db/sqlite/tracks.py index ea1b760..8ec8a00 100644 --- a/app/db/sqlite/tracks.py +++ b/app/db/sqlite/tracks.py @@ -130,7 +130,7 @@ class SQLiteTrackMethods: cur.execute("DELETE FROM tracks WHERE filepath=?", (filepath,)) @staticmethod - def remove_tracks_by_folders(folders: list[str]): + def remove_tracks_by_folders(folders: set[str]): sql = "DELETE FROM tracks WHERE folder = ?" with SQLiteManager() as cur: diff --git a/app/functions.py b/app/functions.py index 375b1c1..3b039df 100644 --- a/app/functions.py +++ b/app/functions.py @@ -7,8 +7,8 @@ from requests import ReadTimeout from app import utils from app.lib.artistlib import CheckArtistImages -from app.lib.colorlib import ProcessAlbumColors, ProcessArtistColors -from app.lib.populate import Populate, ProcessTrackThumbnails, PopulateCancelledError +from app.lib.colorlib import ProcessArtistColors +from app.lib.populate import Populate, PopulateCancelledError from app.lib.trackslib import validate_tracks from app.logger import log diff --git a/app/lib/artistlib.py b/app/lib/artistlib.py index 77f7835..1e4ac73 100644 --- a/app/lib/artistlib.py +++ b/app/lib/artistlib.py @@ -82,7 +82,7 @@ class CheckArtistImages: """ Checks if an artist image exists and downloads it if not. - :param artistname: The artist name + :param artist: The artist name """ img_path = Path(settings.ARTIST_IMG_SM_PATH) / f"{artist.artisthash}.webp" diff --git a/app/lib/folderslib.py b/app/lib/folderslib.py index 6490678..18ee2f7 100644 --- a/app/lib/folderslib.py +++ b/app/lib/folderslib.py @@ -20,7 +20,7 @@ class GetFilesAndDirs: try: entries = os.scandir(self.path) except FileNotFoundError: - return ([], []) + return [], [] dirs, files = [], [] @@ -56,4 +56,4 @@ class GetFilesAndDirs: folders = filter(lambda f: f.has_tracks, folders) - return (tracks, folders) # type: ignore + return tracks, folders # type: ignore diff --git a/app/lib/populate.py b/app/lib/populate.py index b1a4df1..39cf853 100644 --- a/app/lib/populate.py +++ b/app/lib/populate.py @@ -1,5 +1,4 @@ from concurrent.futures import ThreadPoolExecutor -import os from tqdm import tqdm from app import settings @@ -139,4 +138,4 @@ class ProcessTrackThumbnails: ) ) - results = [r for r in results] + list(results) diff --git a/app/lib/taglib.py b/app/lib/taglib.py index 4f1f16e..afa7af6 100644 --- a/app/lib/taglib.py +++ b/app/lib/taglib.py @@ -111,7 +111,7 @@ def get_tags(filepath: str): if p == "" or p is None: maybe = parse_artist_from_filename(filename) - if maybe != []: + if maybe: setattr(tags, tag, ", ".join(maybe)) else: setattr(tags, tag, "Unknown") @@ -174,8 +174,3 @@ def get_tags(filepath: str): del tags[tag] return tags - - for tag in to_delete: - del tags[tag] - - return tags diff --git a/manage.py b/manage.py index 9af1c69..90e361d 100644 --- a/manage.py +++ b/manage.py @@ -181,6 +181,7 @@ def log_startup_info(): adresses = ["localhost", get_ip()] for address in adresses: + # noinspection HttpUrlsUsage print( f"Started app on: {TCOLOR.OKGREEN}http://{address}:{Variables.FLASK_PORT}{TCOLOR.ENDC}" ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 765467a..9c9e1eb 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,4 @@ from hypothesis import given -from hypothesis import strategies as st - -import app.utils from app.utils import parse_feat_from_title diff --git a/wsgi.py b/wsgi.py index 1ea1dcc..bc1e420 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,4 +1,4 @@ -from app import create_api +from app.api import create_api if __name__ == '__main__': app = create_api()