From aa139a7f7333a7576ee3012df11f92f7ee827c6e Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:43:33 +0100 Subject: [PATCH] fixed the mapping in source maps --- .idea/vcs.xml | 2 ++ src/actual_donwload.py | 3 +-- src/music_kraken/download/page_attributes.py | 1 + src/music_kraken/download/results.py | 3 --- src/music_kraken/objects/__init__.py | 4 ++- src/music_kraken/objects/parents.py | 6 ++++- src/music_kraken/objects/source.py | 24 +++++------------ src/music_kraken/pages/abstract.py | 28 +------------------- 8 files changed, 19 insertions(+), 52 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..0823e82 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,7 @@ + + \ No newline at end of file diff --git a/src/actual_donwload.py b/src/actual_donwload.py index 5070293..293fe33 100644 --- a/src/actual_donwload.py +++ b/src/actual_donwload.py @@ -43,8 +43,7 @@ if __name__ == "__main__": bandcamp_test = [ "s: #a Ghost Bath", - "3", - "d: 0" + "0" ] diff --git a/src/music_kraken/download/page_attributes.py b/src/music_kraken/download/page_attributes.py index 8409660..c655d11 100644 --- a/src/music_kraken/download/page_attributes.py +++ b/src/music_kraken/download/page_attributes.py @@ -41,6 +41,7 @@ if DEBUG_PAGES: ALL_PAGES = {DEBUGGING_PAGE} AUDIO_PAGES = ALL_PAGES.union(AUDIO_PAGES) + class Pages: def __init__(self, exclude_pages: Set[Type[Page]] = None, exclude_shady: bool = False) -> None: # initialize all page instances diff --git a/src/music_kraken/download/results.py b/src/music_kraken/download/results.py index 46911b1..bbe63bb 100644 --- a/src/music_kraken/download/results.py +++ b/src/music_kraken/download/results.py @@ -34,9 +34,6 @@ class Results: for index, music_object in self._by_index.items(): if index == exclude_index: continue - - music_object.strip_details() - class SearchResults(Results): def __init__( diff --git a/src/music_kraken/objects/__init__.py b/src/music_kraken/objects/__init__.py index 5596a2c..b4e75cb 100644 --- a/src/music_kraken/objects/__init__.py +++ b/src/music_kraken/objects/__init__.py @@ -20,4 +20,6 @@ from .collection import Collection from .country import Country from .contact import Contact -from .parents import OuterProxy as DatabaseObject +from .parents import OuterProxy + +DatabaseObject = TypeVar('T', bound=OuterProxy) diff --git a/src/music_kraken/objects/parents.py b/src/music_kraken/objects/parents.py index 2619d33..42172f3 100644 --- a/src/music_kraken/objects/parents.py +++ b/src/music_kraken/objects/parents.py @@ -136,7 +136,7 @@ class OuterProxy: def __eq__(self, other: Any): return self.__hash__() == other.__hash__() - def merge(self, __other: OuterProxy, override: bool = False): + def merge(self, __other: Optional[OuterProxy], override: bool = False): """ 1. merges the data of __other in self 2. replaces the data of __other with the data of self @@ -145,6 +145,10 @@ class OuterProxy: :param override: :return: """ + if __other is None: + _ = "debug" + return + self._inner.__merge__(__other._inner, override=override) __other._inner = self._inner diff --git a/src/music_kraken/objects/source.py b/src/music_kraken/objects/source.py index fff1bcc..0bc5694 100644 --- a/src/music_kraken/objects/source.py +++ b/src/music_kraken/objects/source.py @@ -1,6 +1,6 @@ from collections import defaultdict from enum import Enum -from typing import List, Dict, Set, Tuple, Optional +from typing import List, Dict, Set, Tuple, Optional, Iterable from urllib.parse import urlparse from ..utils.enums.source import SourcePages, SourceTypes @@ -12,14 +12,6 @@ from .collection import Collection class Source(OuterProxy): - """ - create somehow like that - ```python - # url won't be a valid one due to it being just an example - Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd") - ``` - """ - page_enum: SourcePages referer_page: SourcePages @@ -37,9 +29,6 @@ class Source(OuterProxy): if referer_page is None: referer_page = page_enum - if audio_url is None: - audio_url = url - super().__init__(page_enum=page_enum, url=url, referer_page=referer_page, audio_url=audio_url, **kwargs) @classmethod @@ -120,16 +109,15 @@ class Source(OuterProxy): class SourceCollection(Collection): - def __init__(self, source_list: List[Source] = None): - source_list = source_list if source_list is not None else [] + def __init__(self, data: Optional[Iterable[Source]] = None, **kwargs): self._page_to_source_list: Dict[SourcePages, List[Source]] = defaultdict(list) - super().__init__(data=source_list) + super().__init__(data=data, **kwargs) - def map_element(self, source: Source): - super().map_element(source) + def _map_element(self, __object: Source, **kwargs): + super()._map_element(__object, **kwargs) - self._page_to_source_list[source.page_enum].append(source) + self._page_to_source_list[__object.page_enum].append(__object) @property def source_pages(self) -> Set[SourcePages]: diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index bffc15c..2a42bde 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -174,34 +174,8 @@ class Page: # set this to true, if all song details can also be fetched by fetching album details NO_ADDITIONAL_DATA_FROM_SONG = False - - - def __init__(self): - super().__init__() - - """ - CODE I NEED WHEN I START WITH MULTITHREADING - - def __init__(self, end_event: EndThread, search_queue: Queue, search_result_queue: Queue): - self.end_event = end_event - - self.search_queue = search_queue - self.search_result_queue = search_result_queue - - super().__init__() - - @property - def _empty_working_queues(self): - return self.search_queue.empty() - def run(self) -> None: - while bool(self.end_event) and self._empty_working_queues: - if not self.search_queue.empty(): - self.search(self.search_queue.get()) - self.search_result_queue.put(FinishedSearch()) - continue - """ - + def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]: return None