fixed DISGUSTING bug

This commit is contained in:
Hellow2 2023-03-20 14:40:32 +01:00
parent 1ae01ed1fd
commit dc6a176c24
2 changed files with 48 additions and 37 deletions

View File

@ -14,7 +14,8 @@ from ..objects import (
Lyrics, Lyrics,
Target, Target,
MusicObject, MusicObject,
Options Options,
SourcePages
) )
@ -28,6 +29,8 @@ class Page:
API_SESSION.proxies = shared.proxies API_SESSION.proxies = shared.proxies
TIMEOUT = 5 TIMEOUT = 5
TRIES = 5 TRIES = 5
SOURCE_TYPE: SourcePages
@classmethod @classmethod
def get_request(cls, url: str, accepted_response_codes: set = set((200,)), trie: int = 0) -> Optional[ def get_request(cls, url: str, accepted_response_codes: set = set((200,)), trie: int = 0) -> Optional[
@ -166,6 +169,10 @@ class Page:
raise NotImplementedError(f"MusicObject {type(music_object)} has not been implemented yet") raise NotImplementedError(f"MusicObject {type(music_object)} has not been implemented yet")
@classmethod
def fetch_song_from_source(cls, source: Source, flat: bool = False) -> Song:
return Song()
@classmethod @classmethod
def fetch_song_details(cls, song: Song, flat: bool = False) -> Song: def fetch_song_details(cls, song: Song, flat: bool = False) -> Song:
""" """
@ -181,9 +188,18 @@ class Page:
:return detailed_song: it modifies the input song :return detailed_song: it modifies the input song
""" """
source: Source
for source in song.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
new_song = cls.fetch_song_from_source(source, flat)
song.merge(new_song)
return song return song
@classmethod
def fetch_album_from_source(cls, source: Source, flat: bool = False) -> Album:
return Album()
@classmethod @classmethod
def fetch_album_details(cls, album: Album, flat: bool = False) -> Album: def fetch_album_details(cls, album: Album, flat: bool = False) -> Album:
""" """
@ -201,8 +217,17 @@ class Page:
:return detailed_artist: it modifies the input artist :return detailed_artist: it modifies the input artist
""" """
source: Source
for source in album.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
new_album: Album = cls.fetch_album_from_source(source, flat)
album.merge(new_album)
return album return album
@classmethod
def fetch_artist_from_source(cls, source: Source, flat: bool = False) -> Artist:
return Artist()
@classmethod @classmethod
def fetch_artist_details(cls, artist: Artist, flat: bool = False) -> Artist: def fetch_artist_details(cls, artist: Artist, flat: bool = False) -> Artist:
""" """
@ -217,5 +242,10 @@ class Page:
:return detailed_artist: it modifies the input artist :return detailed_artist: it modifies the input artist
""" """
source: Source
for source in artist.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
new_artist: Artist = cls.fetch_artist_from_source(source, flat)
artist.merge(new_artist)
return artist return artist

View File

@ -516,7 +516,7 @@ class Musify(Page):
) )
@classmethod @classmethod
def get_discography(cls, url: MusifyUrl) -> List[Album]: def get_discography(cls, url: MusifyUrl, flat=False) -> List[Album]:
""" """
POST https://musify.club/artist/filteralbums POST https://musify.club/artist/filteralbums
ArtistID: 280348 ArtistID: 280348
@ -539,7 +539,13 @@ class Musify(Page):
discography: List[Album] = [] discography: List[Album] = []
for card_soup in soup.find_all("div", {"class": "card"}): for card_soup in soup.find_all("div", {"class": "card"}):
discography.append(cls.parse_album_card(card_soup)) new_album: Album = cls.parse_album_card(card_soup)
album_source: Source
if not flat:
for album_source in new_album.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
new_album.merge(cls.get_album_from_source(album_source))
discography.append(new_album)
return discography return discography
@ -556,7 +562,7 @@ class Musify(Page):
r = cls.get_request(f"https://musify.club/{url.source_type.value}/{url.name_with_id}?_pjax=#bodyContent") r = cls.get_request(f"https://musify.club/{url.source_type.value}/{url.name_with_id}?_pjax=#bodyContent")
if r is None: if r is None:
return Artist(_id=url.musify_id, name="") return Artist(_id=url.musify_id)
soup = BeautifulSoup(r.content, "html.parser") soup = BeautifulSoup(r.content, "html.parser")
@ -592,11 +598,11 @@ class Musify(Page):
name = None name = None
source_list: List[Source] = [] source_list: List[Source] = []
country = None country = None
notes: FormattedText = None notes: FormattedText = FormattedText()
breadcrumbs: BeautifulSoup = soup.find("ol", {"class": "breadcrumb"}) breadcrumbs: BeautifulSoup = soup.find("ol", {"class": "breadcrumb"})
if breadcrumbs is not None: if breadcrumbs is not None:
breadcrumb_list: List[BeautifulSoup] = breadcrumbs.find_all("li", {"class": "breadcrumb"}, recursive=False) breadcrumb_list: List[BeautifulSoup] = breadcrumbs.find_all("li", {"class": "breadcrumb-item"}, recursive=False)
if len(breadcrumb_list) == 3: if len(breadcrumb_list) == 3:
name = breadcrumb_list[-1].get_text(strip=True) name = breadcrumb_list[-1].get_text(strip=True)
else: else:
@ -624,7 +630,7 @@ class Musify(Page):
content_title: BeautifulSoup = soup.find("header", {"class": "content__title"}) content_title: BeautifulSoup = soup.find("header", {"class": "content__title"})
if content_title is not None: if content_title is not None:
h1_name: BeautifulSoup = soup.find("h1", recursive=False) h1_name: BeautifulSoup = content_title.find("h1", recursive=False)
if h1_name is not None: if h1_name is not None:
name = h1_name.get_text(strip=True) name = h1_name.get_text(strip=True)
@ -663,7 +669,7 @@ class Musify(Page):
note_soup: BeautifulSoup = soup.find(id="text-main") note_soup: BeautifulSoup = soup.find(id="text-main")
if note_soup is not None: if note_soup is not None:
notes = FormattedText(html=note_soup.decode_contents()) notes.html = note_soup.decode_contents()
return Artist( return Artist(
_id=url.musify_id, _id=url.musify_id,
@ -674,7 +680,7 @@ class Musify(Page):
) )
@classmethod @classmethod
def get_artist_from_source(cls, source: Source, flat: bool = False) -> Artist: def fetch_artist_from_source(cls, source: Source, flat: bool = False) -> Artist:
""" """
fetches artist from source fetches artist from source
@ -698,32 +704,7 @@ class Musify(Page):
artist.main_album_collection.extend(discography) artist.main_album_collection.extend(discography)
return artist return artist
@classmethod @classmethod
def fetch_artist_details(cls, artist: Artist, flat: bool = False) -> Artist: def get_album_from_source(cls, source: Source, flat: bool = False) -> Album:
source_list = artist.source_collection.get_sources_from_page(cls.SOURCE_TYPE) return Album()
if len(source_list) == 0:
return artist
for source in source_list:
artist.merge(cls.get_artist_from_source(source, flat=flat))
return artist
@classmethod
def fetch_album_details(cls, album: Album, flat: bool = False) -> Album:
return album
@classmethod
def fetch_song_details(cls, song: Song, flat: bool = False) -> Song:
source_list = song.source_collection.get_sources_from_page(cls.SOURCE_TYPE)
if len(source_list) == 0:
return song
"""
TODO
lyrics
"""
return song