implemented method to fetch stuff
This commit is contained in:
parent
21e81c82a3
commit
11974fd2eb
@ -193,12 +193,23 @@ class Page:
|
||||
return music_object
|
||||
|
||||
@classmethod
|
||||
def fetch_object_from_source(cls, source: Source):
|
||||
def fetch_object_from_source(cls, source: Source, stop_at_level: int = 2):
|
||||
obj_type = cls._get_type_of_url(source.url)
|
||||
if obj_type is None:
|
||||
return Artist()
|
||||
|
||||
return cls._fetch_object_from_source(source=source, obj_type=obj_type)
|
||||
music_object = cls._fetch_object_from_source(source=source, obj_type=obj_type, stop_at_level=stop_at_level)
|
||||
|
||||
collections = {
|
||||
Label: Collection(element_type=Label),
|
||||
Artist: Collection(element_type=Artist),
|
||||
Album: Collection(element_type=Album),
|
||||
Song: Collection(element_type=Song)
|
||||
}
|
||||
|
||||
cls._clean_music_object(music_object, collections)
|
||||
music_object.compile(merge_into=True)
|
||||
return music_object
|
||||
|
||||
|
||||
@classmethod
|
||||
|
@ -1,8 +1,8 @@
|
||||
from typing import Tuple, Type, Set, Union, List
|
||||
from typing import Optional, Tuple, Type, Set, Union, List
|
||||
|
||||
from . import page_attributes
|
||||
from ..abstract import Page
|
||||
from ...objects import Song, Album, Artist, Label
|
||||
from ...objects import Song, Album, Artist, Label, Source
|
||||
|
||||
MusicObject = Union[Song, Album, Artist, Label]
|
||||
|
||||
@ -34,3 +34,12 @@ class Download:
|
||||
for page in self.pages:
|
||||
page.fetch_details(music_object=music_object)
|
||||
return music_object
|
||||
|
||||
def fetch_source(self, source: Source) -> Optional[MusicObject]:
|
||||
source_page = page_attributes.SOURCE_PAGE_MAP[source.page_enum]
|
||||
|
||||
if source_page not in self.pages:
|
||||
return
|
||||
|
||||
return source_page.fetch_object_from_source(source)
|
||||
|
@ -1,11 +1,13 @@
|
||||
from typing import Tuple, Type, Dict
|
||||
|
||||
from ...objects import SourcePages
|
||||
from ..abstract import Page
|
||||
from ..encyclopaedia_metallum import EncyclopaediaMetallum
|
||||
from ..musify import Musify
|
||||
|
||||
NAME_PAGE_MAP: Dict[str, Type[Page]] = dict()
|
||||
PAGE_NAME_MAP: Dict[Type[Page], str] = dict()
|
||||
SOURCE_PAGE_MAP: Dict[SourcePages, Type[Page]]
|
||||
|
||||
ALL_PAGES: Tuple[Type[Page]] = (
|
||||
EncyclopaediaMetallum,
|
||||
@ -27,3 +29,6 @@ for i, page in enumerate(ALL_PAGES):
|
||||
NAME_PAGE_MAP[SHORTHANDS[i].lower()] = page
|
||||
|
||||
PAGE_NAME_MAP[page] = SHORTHANDS[i]
|
||||
|
||||
SOURCE_PAGE_MAP[page.SOURCE_TYPE] = page
|
||||
|
Loading…
Reference in New Issue
Block a user