feat: improved the youtube music album fetching
This commit is contained in:
@@ -93,18 +93,6 @@ class Collection(Generic[T]):
|
||||
return self._indexed_values[name][value]
|
||||
|
||||
return None
|
||||
|
||||
def _merge_into_contained_object(self, existing: T, other: T, **kwargs):
|
||||
"""
|
||||
This function merges the other object into the existing object, which is contained in the current collection.
|
||||
This also modifies the correct mapping.
|
||||
"""
|
||||
|
||||
if existing.id == other.id:
|
||||
return
|
||||
|
||||
self._map_element(existing)
|
||||
existing.merge(other, **kwargs)
|
||||
|
||||
def _append_new_object(self, other: T, **kwargs):
|
||||
"""
|
||||
@@ -113,7 +101,6 @@ class Collection(Generic[T]):
|
||||
"""
|
||||
|
||||
self._data.append(other)
|
||||
self._map_element(other)
|
||||
|
||||
# all of the existing hooks to get the defined datastructure
|
||||
for collection_attribute, generator in self.extend_object_to_attribute.items():
|
||||
@@ -128,17 +115,10 @@ class Collection(Generic[T]):
|
||||
if a is b:
|
||||
continue
|
||||
|
||||
"""
|
||||
no_sync_collection: Set[Collection] = kwargs.get("no_sync_collection", set())
|
||||
if id(b) in no_sync_collection:
|
||||
continue
|
||||
"""
|
||||
object_trace(f"Syncing [{a}] = [{b}]")
|
||||
|
||||
|
||||
b_data = b.data.copy()
|
||||
b_collection_for = b._collection_for.copy()
|
||||
# no_sync_collection.add(id(b))
|
||||
|
||||
del b
|
||||
|
||||
@@ -166,6 +146,7 @@ class Collection(Generic[T]):
|
||||
|
||||
object_trace(f"Appending {other.option_string} to {self}")
|
||||
|
||||
# switching collection in the case of push to
|
||||
for c in self.push_to:
|
||||
r = c._find_object(other)
|
||||
if r is not None:
|
||||
@@ -173,25 +154,24 @@ class Collection(Generic[T]):
|
||||
return c.append(other, **kwargs)
|
||||
|
||||
|
||||
pull_from: Optional[Tuple[Collection, T]] = None
|
||||
for c in self.pull_from:
|
||||
r = c._find_object(other)
|
||||
if r is not None:
|
||||
output("found pull from", r, other, self, color=BColors.RED, sep="\t")
|
||||
other.merge(r, **kwargs)
|
||||
c.remove(r, **kwargs)
|
||||
c.remove(r, existing=r, **kwargs)
|
||||
break
|
||||
|
||||
existing_object = self._find_object(other, no_push_to=kwargs.get("no_push_to", False))
|
||||
existing_object = self._find_object(other)
|
||||
|
||||
if existing_object is None:
|
||||
self._append_new_object(other, **kwargs)
|
||||
else:
|
||||
existing_object.merge(other, **kwargs)
|
||||
|
||||
def remove(self, *other_list: List[T], silent: bool = False, **kwargs):
|
||||
def remove(self, *other_list: List[T], silent: bool = False, existing: Optional[T] = None, **kwargs):
|
||||
for other in other_list:
|
||||
existing: Optional[T] = self._indexed_values["id"].get(other.id, None)
|
||||
existing: Optional[T] = existing or self._indexed_values["id"].get(other.id, None)
|
||||
if existing is None:
|
||||
if not silent:
|
||||
raise ValueError(f"Object {other} not found in {self}")
|
||||
@@ -233,6 +213,7 @@ class Collection(Generic[T]):
|
||||
yield from self._data
|
||||
|
||||
def __merge__(self, other: Collection, **kwargs):
|
||||
object_trace(f"merging {str(self)} | {str(other)}")
|
||||
self.extend(other, **kwargs)
|
||||
|
||||
def __getitem__(self, item: int):
|
||||
@@ -242,3 +223,9 @@ class Collection(Generic[T]):
|
||||
if item >= len(self._data):
|
||||
return default
|
||||
return self._data[item]
|
||||
|
||||
def __eq__(self, other: Collection) -> bool:
|
||||
if self.empty and other.empty:
|
||||
return True
|
||||
|
||||
return self._data == other._data
|
||||
|
@@ -156,7 +156,7 @@ class Song(Base):
|
||||
return
|
||||
|
||||
if isinstance(object_list, Artist):
|
||||
self.main_artist_collection.extend(object_list)
|
||||
self.feature_artist_collection.extend(object_list)
|
||||
return
|
||||
|
||||
if isinstance(object_list, Album):
|
||||
|
Reference in New Issue
Block a user