mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +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:
@@ -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]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user