This commit is contained in:
Hellow2 2023-03-10 08:40:50 +01:00
parent dfe894a532
commit 3b4fe88d42

View File

@ -150,69 +150,3 @@ class SourceCollection(Collection):
YouTube or musify
"""
return self._page_to_source_list[source_page]
class SourceAttribute(DatabaseObject):
"""
This is a class that is meant to be inherited from.
it adds the source_list attribute to a class
"""
_source_dict: Dict[SourcePages, List[Source]]
source_url_map: Dict[str, Source]
def __new__(cls, **kwargs):
new = object.__new__(cls)
new._source_dict = {page_enum: list() for page_enum in SourcePages}
new.source_url_map = dict()
return new
def match_source_with_url(self, url: str) -> bool:
"""
this function returns true, if a source with this url exists,
else it returns false
:param url:
:return source_with_url_exists:
"""
return url in self.source_url_map
def match_source(self, source: Source) -> bool:
return self.match_source_with_url(source.url)
def add_source(self, source: Source):
"""
adds a new Source to the sources
"""
if self.match_source(source):
return
self.source_url_map[source.url] = source
self._source_dict[source.page_enum].append(source)
def get_sources_from_page(self, page_enum) -> List[Source]:
"""
getting the sources for a specific page like
youtube or musify
"""
return self._source_dict[page_enum]
def get_source_list(self) -> List[Source]:
"""
gets all sources
"""
return [item for _, page_list in self._source_dict.items() for item in page_list]
def set_source_list(self, source_list: List[Source]):
self._source_dict = {page_enum: list() for page_enum in SourcePages}
for source in source_list:
self.add_source(source)
def get_source_dict(self) -> Dict[object, List[Source]]:
"""
gets a dictionary of all Sources,
where the key is a page enum,
and the value is a List with all sources of according page
"""
return self._source_dict
source_list: List[Source] = property(fget=get_source_list, fset=set_source_list)
source_dict: Dict[object, List[Source]] = property(fget=get_source_dict)