layed out the complete fetching of album

This commit is contained in:
Hellow 2023-03-20 21:50:19 +01:00
parent 96f2d7ef6e
commit f39c3c11ad
3 changed files with 207 additions and 568 deletions

File diff suppressed because one or more lines are too long

View File

@ -60,6 +60,7 @@ X-Requested-With: XMLHttpRequest
class MusifyTypes(Enum):
ARTIST = "artist"
RELEASE = "release"
@dataclass
@ -85,6 +86,30 @@ class Musify(Page):
SOURCE_TYPE = SourcePages.MUSIFY
@classmethod
def parse_url(cls, url: str) -> MusifyUrl:
parsed = urlparse(url)
path = parsed.path.split("/")
split_name = path[2].split("-")
url_id = split_name[-1]
name_for_url = "-".join(split_name[:-1])
try:
type_enum = MusifyTypes(path[1])
except ValueError as e:
print(f"{path[1]} is not yet implemented, add it to MusifyTypes")
raise e
return MusifyUrl(
source_type=type_enum,
name_without_id=name_for_url,
name_with_id=path[2],
musify_id=url_id,
url=url
)
@classmethod
def search_by_query(cls, query: str) -> Options:
query_obj = cls.Query(query)
@ -358,24 +383,6 @@ class Musify(Page):
return Options(search_results)
@classmethod
def parse_url(cls, url: str) -> MusifyUrl:
parsed = urlparse(url)
path = parsed.path.split("/")
split_name = path[2].split("-")
url_id = split_name[-1]
name_for_url = "-".join(split_name[:-1])
return MusifyUrl(
source_type=MusifyTypes(path[1]),
name_without_id=name_for_url,
name_with_id=path[2],
musify_id=url_id,
url=url
)
@classmethod
def parse_album_card(cls, album_card: BeautifulSoup, artist_name: str = None) -> Album:
"""
@ -706,7 +713,7 @@ class Musify(Page):
fetches artist from source
[x] discography
[x] attributes *(name and country... wooooow and I waste one request for this)*
[x] attributes
[] picture gallery
Args:
@ -728,14 +735,27 @@ class Musify(Page):
@classmethod
def fetch_album_from_source(cls, source: Source, flat: bool = False) -> Album:
"""_summary_
Args:
source (Source): _description_
flat (bool, optional): _description_. Defaults to False.
Returns:
Album: _description_
"""
fetches album from source:
eg. 'https://musify.club/release/linkin-park-hybrid-theory-2000-188'
/html/musify/album_overview.html
[] tracklist
[] attributes *(name and country... wooooow and I waste one request for this)*
[] ratings
:param source:
:param flat:
:return:
"""
url = cls.parse_url(source.url)
endpoint = cls.HOST + "/release/" + url.name_with_id
r = cls.get_request(endpoint)
if r is None:
return Album()
soup = BeautifulSoup(r.content, "html.parser")
return Album(title="works")

View File

@ -15,9 +15,11 @@ def fetch_artist():
artist = Musify.fetch_details(artist)
print(artist.options)
def fetch_album():
album = objects.Album(
source_list=[objects.Source(objects.SourcePages.MUSIFY, "https://musify.club/release/linkin-park-hybrid-theory-2000-188")]
source_list=[objects.Source(objects.SourcePages.MUSIFY,
"https://musify.club/release/linkin-park-hybrid-theory-2000-188")]
)
album = Musify.fetch_details(album)