diff --git a/app/api/album.py b/app/api/album.py index cdc74ad..6d2c7cf 100644 --- a/app/api/album.py +++ b/app/api/album.py @@ -71,9 +71,7 @@ def get_album_tracks_and_info(): album.check_is_single(tracks) - if album.is_single: - album.is_single = True - else: + if not album.is_single: album.check_type() album.is_favorite = check_is_fav(albumhash, FavType.album) diff --git a/app/db/store.py b/app/db/store.py index 51b3777..56d7399 100644 --- a/app/db/store.py +++ b/app/db/store.py @@ -235,6 +235,7 @@ class Store: """ Returns a folder object by its path. """ + # TODO: Modify this method to accept a list of paths, sorting is computationally expensive. folders = sorted(cls.folders, key=lambda x: x.path) folder = UseBisection(folders, "path", [path])()[0] @@ -250,6 +251,21 @@ class Store: cls.folders.append(folder) return folder + @classmethod + def get_folders_count(cls, paths: list[str]) -> list[dict[str, int]]: + count_dict = {path: 0 for path in paths} + + for track in cls.tracks: + for path in paths: + if track.filepath.startswith(path): + count_dict[path] += 1 + + result = [{"path": path, "count": count_dict[path]} for path in paths] + + # TODO: Modify this method to return Folder objects with + # track count mapped. Keep an eye on function complexity. + return result + @classmethod def get_tracks_by_filepaths(cls, paths: list[str]) -> list[Track]: """ diff --git a/app/lib/folderslib.py b/app/lib/folderslib.py index 0193036..800e149 100644 --- a/app/lib/folderslib.py +++ b/app/lib/folderslib.py @@ -1,5 +1,6 @@ import os from concurrent.futures import ThreadPoolExecutor +from pprint import pprint from app.db.store import Store from app.models import Folder, Track @@ -50,10 +51,16 @@ class GetFilesAndDirs: tracks = Store.get_tracks_by_filepaths(files) + # TODO: Remove this threadpool and modify the get_folder store + # method to accept a list of paths. with ThreadPoolExecutor() as pool: iterable = pool.map(Store.get_folder, dirs) folders = [i for i in iterable if i is not None] folders = filter(lambda f: f.has_tracks, folders) + folders_with_count_dict = Store.get_folders_count(dirs) + pprint(folders_with_count_dict) + # TODO: Map folder count to folder object + return tracks, folders # type: ignore diff --git a/app/models/album.py b/app/models/album.py index 0aee8b7..b01d33c 100644 --- a/app/models/album.py +++ b/app/models/album.py @@ -110,7 +110,7 @@ class Album: """ if ( len(tracks) == 1 - and tracks[0].title == self.title + and tracks[0].title.lower() == self.title.lower() # and tracks[0].track == 1 # and tracks[0].disc == 1