fixed the merging of collections

This commit is contained in:
Hellow 2023-12-29 16:15:54 +01:00
parent aa139a7f73
commit 4cbbee26e4
6 changed files with 17 additions and 14 deletions

View File

@ -48,3 +48,4 @@ if __name__ == "__main__":
music_kraken.cli.download(genre="test", command_list=bandcamp_test, process_metadata_anyway=True) music_kraken.cli.download(genre="test", command_list=bandcamp_test, process_metadata_anyway=True)
_ = "debug"

View File

@ -295,9 +295,6 @@ class Downloader:
page: Type[Page] page: Type[Page]
music_object: DatabaseObject music_object: DatabaseObject
if self.current_results is not None:
self.current_results.delete_details(index)
try: try:
page, music_object = self.current_results.get_music_object_by_index(index) page, music_object = self.current_results.get_music_object_by_index(index)
except KeyError: except KeyError:
@ -308,6 +305,8 @@ class Downloader:
self.pages.fetch_details(music_object) self.pages.fetch_details(music_object)
print(music_object)
print(music_object.options)
self.set_current_options(PageResults(page, music_object.options)) self.set_current_options(PageResults(page, music_object.options))
self.print_current_options() self.print_current_options()

View File

@ -30,10 +30,6 @@ class Results:
# if this throws a key error, either the formatted generator needs to be iterated, or the option doesn't exist. # if this throws a key error, either the formatted generator needs to be iterated, or the option doesn't exist.
return self._page_by_index[index], self._by_index[index] return self._page_by_index[index], self._by_index[index]
def delete_details(self, exclude_index: int):
for index, music_object in self._by_index.items():
if index == exclude_index:
continue
class SearchResults(Results): class SearchResults(Results):
def __init__( def __init__(

View File

@ -107,8 +107,6 @@ class Collection(Generic[T]):
if self._contained_in_self(__object): if self._contained_in_self(__object):
return [self] return [self]
print(len(self.children), id(self), ";".join(str(id(i)) for i in self.children))
print()
for collection in self.children: for collection in self.children:
results.extend(collection._contained_in_sub(__object, break_at_first=break_at_first)) results.extend(collection._contained_in_sub(__object, break_at_first=break_at_first))
@ -186,11 +184,11 @@ class Collection(Generic[T]):
return len(self._contained_in_sub(__object)) > 0 return len(self._contained_in_sub(__object)) > 0
def _append(self, __object: T, from_map: bool = False): def _append(self, __object: T, from_map: bool = False):
# print(self, __object)
self._map_element(__object, from_map=from_map) self._map_element(__object, from_map=from_map)
self._data.append(__object) self._data.append(__object)
def append(self, __object: Optional[T], already_is_parent: bool = False, from_map: bool = False): def append(self, __object: Optional[T], already_is_parent: bool = False, from_map: bool = False):
print(__object)
if __object is None or __object.id in self._contains_ids: if __object is None or __object.id in self._contains_ids:
return return
@ -264,3 +262,6 @@ class Collection(Generic[T]):
def __iter__(self) -> Iterator[T]: def __iter__(self) -> Iterator[T]:
for element in self._data: for element in self._data:
yield element yield element
def __merge__(self, __other: Collection, override: bool = False):
self.extend(__other.shallow_list)

View File

@ -47,7 +47,7 @@ class InnerData:
# if the object of value implemented __merge__, it merges # if the object of value implemented __merge__, it merges
existing = self.__getattribute__(key) existing = self.__getattribute__(key)
if hasattr(type(existing), "__merge__"): if hasattr(type(existing), "__merge__"):
existing.merge_into_self(value, override) existing.__merge__(value, override)
continue continue
# override the existing value if requested # override the existing value if requested

View File

@ -446,6 +446,12 @@ class Artist(Base):
"current_artist_collection": self "current_artist_collection": self
} }
@property
def options(self) -> List[P]:
options = [self, *self.main_album_collection.shallow_list, *self.feature_album]
print(options)
return options
def update_albumsort(self): def update_albumsort(self):
""" """
This updates the albumsort attributes, of the albums in This updates the albumsort attributes, of the albums in