Compare commits

..

No commits in common. "0b216b7d40476f6566c7bd7c7cc7ccb91e238f5a" and "fa9fd5d72be98912fc4df2e12fa9fa312eddad6f" have entirely different histories.

6 changed files with 45 additions and 44 deletions

View File

@ -26,7 +26,6 @@
"OKBLUE", "OKBLUE",
"Referer", "Referer",
"tracksort", "tracksort",
"unmap",
"youtube" "youtube"
] ]
} }

View File

@ -6,8 +6,8 @@ logging.getLogger().setLevel(logging.DEBUG)
if __name__ == "__main__": if __name__ == "__main__":
commands = [ commands = [
"s: #a Ghost Bath", "s: #a And End...",
"4", "d: 10",
] ]

View File

@ -101,7 +101,7 @@ class Connection:
} }
if self.HOST is not None: if self.HOST is not None:
# headers["Host"] = self.HOST.netloc headers["Host"] = self.HOST.netloc
headers["Referer"] = self.base_url(url=self.HOST) headers["Referer"] = self.base_url(url=self.HOST)
headers.update(header_values) headers.update(header_values)
@ -215,6 +215,10 @@ class Connection:
self.save(r, name, **kwargs) self.save(r, name, **kwargs)
return r return r
if self.SEMANTIC_NOT_FOUND and r.status_code == 404:
self.LOGGER.warning(f"Couldn't find url (404): {request_url}")
return None
# the server rejected the request, or the internet is lacking # the server rejected the request, or the internet is lacking
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
self.LOGGER.warning(f"Request timed out at \"{request_url}\": ({try_count}-{self.TRIES})") self.LOGGER.warning(f"Request timed out at \"{request_url}\": ({try_count}-{self.TRIES})")
@ -227,11 +231,9 @@ class Connection:
finally: finally:
self.lock = False self.lock = False
if r is None: if not connection_failed:
self.LOGGER.warning(f"{self.HOST.netloc} didn't respond at {url}. ({try_count}-{self.TRIES})")
self.LOGGER.debug("request headers:\n\t"+ "\n\t".join(f"{k}\t=\t{v}" for k, v in headers.items()))
else:
self.LOGGER.warning(f"{self.HOST.netloc} responded wit {r.status_code} at {url}. ({try_count}-{self.TRIES})") self.LOGGER.warning(f"{self.HOST.netloc} responded wit {r.status_code} at {url}. ({try_count}-{self.TRIES})")
if r is not None:
self.LOGGER.debug("request headers:\n\t"+ "\n\t".join(f"{k}\t=\t{v}" for k, v in r.request.headers.items())) self.LOGGER.debug("request headers:\n\t"+ "\n\t".join(f"{k}\t=\t{v}" for k, v in r.request.headers.items()))
self.LOGGER.debug("response headers:\n\t"+ "\n\t".join(f"{k}\t=\t{v}" for k, v in r.headers.items())) self.LOGGER.debug("response headers:\n\t"+ "\n\t".join(f"{k}\t=\t{v}" for k, v in r.headers.items()))
self.LOGGER.debug(r.content) self.LOGGER.debug(r.content)
@ -239,9 +241,6 @@ class Connection:
if name != "": if name != "":
self.save(r, name, error=True, **kwargs) self.save(r, name, error=True, **kwargs)
if self.SEMANTIC_NOT_FOUND and r.status_code == 404:
return None
if sleep_after_404 != 0: if sleep_after_404 != 0:
self.LOGGER.warning(f"Waiting for {sleep_after_404} seconds.") self.LOGGER.warning(f"Waiting for {sleep_after_404} seconds.")
time.sleep(sleep_after_404) time.sleep(sleep_after_404)

View File

@ -110,7 +110,7 @@ class Collection(Generic[T]):
if self._contained_in_self(__object): if self._contained_in_self(__object):
return [self] return [self]
for collection in self.children: for collection in (*self.children, *self.parents):
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))
if break_at_first: if break_at_first:
@ -198,7 +198,7 @@ class Collection(Generic[T]):
if value in self._indexed_values[name]: if value in self._indexed_values[name]:
return self._indexed_to_objects[value][0] return self._indexed_to_objects[value][0]
def _find_object(self, __object: T, no_sibling: bool = False) -> Tuple[Collection[T], Optional[T]]: def _find_object(self, __object: T) -> Tuple[Collection[T], Optional[T]]:
other_object = self._find_object_in_self(__object) other_object = self._find_object_in_self(__object)
if other_object is not None: if other_object is not None:
return self, other_object return self, other_object
@ -208,19 +208,6 @@ class Collection(Generic[T]):
if other_object is not None: if other_object is not None:
return o, other_object return o, other_object
if no_sibling:
return self, None
# find in siblings and all children of siblings
for parent in self.parents:
for sibling in parent.children:
if sibling is self:
continue
o, other_object = sibling._find_object(__object, no_sibling=True)
if other_object is not None:
return o, other_object
return self, None return self, None
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):
@ -242,14 +229,33 @@ class Collection(Generic[T]):
if existing_object is None: if existing_object is None:
# append # append
# print("appending", existing_object, __object)
append_to._data.append(__object) append_to._data.append(__object)
append_to._map_element(__object, from_map=from_map)
else: else:
# merge # merge
append_to._unmap_element(existing_object) append_to._unmap_element(existing_object)
existing_object.merge(__object) existing_object.merge(__object)
append_to._map_element(existing_object, from_map=from_map)
append_to._map_element(__object, from_map=from_map)
"""
exists_in_collection = self._contained_in_sub(__object)
if len(exists_in_collection) and self is exists_in_collection[0]:
# assuming that the object already is contained in the correct collections
if not already_is_parent:
self.merge_into_self(__object, from_map=from_map)
return
if not len(exists_in_collection):
self._append(__object, from_map=from_map)
else:
exists_in_collection[0].merge_into_self(__object, from_map=from_map)
if not already_is_parent or not self._is_root:
for parent_collection in self._get_parents_of_multiple_contained_children(__object):
pass
parent_collection.append(__object, already_is_parent=True, from_map=from_map)
"""
def extend(self, __iterable: Optional[Iterable[T]], from_map: bool = False): def extend(self, __iterable: Optional[Iterable[T]], from_map: bool = False):
if __iterable is None: if __iterable is None:
@ -290,7 +296,8 @@ class Collection(Generic[T]):
@property @property
def data(self) -> List[T]: def data(self) -> List[T]:
return list(i for i in self.__iter__()) return [*self._data,
*(__object for collection in self.children for __object in collection.shallow_list)]
def __len__(self) -> int: def __len__(self) -> int:
return len(self._data) + sum(len(collection) for collection in self.children) return len(self._data) + sum(len(collection) for collection in self.children)
@ -299,17 +306,13 @@ class Collection(Generic[T]):
def empty(self) -> bool: def empty(self) -> bool:
return self.__len__() <= 0 return self.__len__() <= 0
def __iter__(self, finished_ids: set = None) -> Iterator[T]: def __iter__(self) -> Iterator[T]:
_finished_ids = finished_ids or set()
for element in self._data: for element in self._data:
if element.id in _finished_ids:
continue
_finished_ids.add(element.id)
yield element yield element
for c in self.children: for c in self.children:
yield from c.__iter__(finished_ids=finished_ids) for element in c:
yield element
def __merge__(self, __other: Collection, override: bool = False): def __merge__(self, __other: Collection, override: bool = False):
self.extend(__other._data, from_map=True) self.extend(__other._data, from_map=True)

View File

@ -299,7 +299,7 @@ class Album(Base):
@property @property
def option_string(self) -> str: def option_string(self) -> str:
return f"{self.__repr__()} " \ return f"{self.__repr__()} " \
f"by Artist({OPTION_STRING_DELIMITER.join([artist.name + str(artist.id) for artist in self.artist_collection])}) " \ f"by Artist({OPTION_STRING_DELIMITER.join([artist.name for artist in self.artist_collection])}) " \
f"under Label({OPTION_STRING_DELIMITER.join([label.name for label in self.label_collection])})" f"under Label({OPTION_STRING_DELIMITER.join([label.name for label in self.label_collection])})"
@property @property

View File

@ -13,7 +13,7 @@ if not load_dotenv(Path(__file__).parent.parent.parent / ".env"):
__stage__ = os.getenv("STAGE", "prod") __stage__ = os.getenv("STAGE", "prod")
DEBUG = (__stage__ == "dev") and True DEBUG = (__stage__ == "dev") and True
DEBUG_LOGGING = DEBUG and True DEBUG_LOGGING = DEBUG and False
DEBUG_TRACE = DEBUG and True DEBUG_TRACE = DEBUG and True
DEBUG_OBJECT_TRACE = DEBUG and False DEBUG_OBJECT_TRACE = DEBUG and False
DEBUG_YOUTUBE_INITIALIZING = DEBUG and False DEBUG_YOUTUBE_INITIALIZING = DEBUG and False