mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-07 03:35:35 +00:00
add a store method to count the number of tracks in a folder
~ Courtesy of chatgpt3.5 + add a few a TODO
This commit is contained in:
parent
a5d61e8919
commit
32bb3d37e1
@ -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)
|
||||
|
@ -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]:
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user