hs
This commit is contained in:
@@ -60,8 +60,10 @@ artist = song.main_artist_list[0]
|
||||
|
||||
# print_artist(artist)
|
||||
|
||||
artist = EncyclopaediaMetallum.fetch_artist_details(artist)
|
||||
# artist = EncyclopaediaMetallum.fetch_artist_details(artist, flat=False)
|
||||
|
||||
print_artist(artist)
|
||||
album = EncyclopaediaMetallum.fetch_album_details(song.album, flat=False)
|
||||
|
||||
# print_artist(artist)
|
||||
|
||||
# print(only_smile)
|
||||
|
@@ -84,17 +84,17 @@ class Page:
|
||||
:return possible_music_objects:
|
||||
"""
|
||||
|
||||
raise NotImplementedError()
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
def fetch_details(cls, music_object: MusicObject, simple: bool = False) -> MusicObject:
|
||||
def fetch_details(cls, music_object: MusicObject, flat: bool = False) -> MusicObject:
|
||||
"""
|
||||
when a music object with laccing data is passed in, it returns
|
||||
the SAME object **(no copy)** with more detailed data.
|
||||
If you for example put in an album, it fetches the tracklist
|
||||
|
||||
:param music_object:
|
||||
:param simple:
|
||||
:param flat:
|
||||
if it is true it fetches only the most important information (only one level)
|
||||
if an Artist is passed in, it fetches only the discography of the artist, and not the
|
||||
tracklist of every album of the artist.
|
||||
@@ -102,22 +102,23 @@ class Page:
|
||||
"""
|
||||
|
||||
if type(music_object) == Song:
|
||||
return cls.fetch_song_details(music_object, simple=simple)
|
||||
return cls.fetch_song_details(music_object, flat=flat)
|
||||
|
||||
if type(music_object) == Album:
|
||||
return cls.fetch_album_details(music_object, simple=simple)
|
||||
return cls.fetch_album_details(music_object, flat=flat)
|
||||
|
||||
if type(music_object) == Artist:
|
||||
return cls.fetch_artist_details(music_object, simple=simple)
|
||||
return cls.fetch_artist_details(music_object, flat=flat)
|
||||
|
||||
raise NotImplementedError(f"MusicObject {type(music_object)} has not been implemented yet")
|
||||
|
||||
def fetch_song_details(cls, song: Song, simple: bool = False) -> Song:
|
||||
@classmethod
|
||||
def fetch_song_details(cls, song: Song, flat: bool = False) -> Song:
|
||||
"""
|
||||
for a general description check cls.fetch_details
|
||||
|
||||
:param song: song without much data
|
||||
:param simple:
|
||||
:param flat:
|
||||
when True it only fetches the artist and the album, and the attributes of those,
|
||||
who can be gotten with one api request
|
||||
when False it fetches everything including, but not limited to:
|
||||
@@ -127,14 +128,15 @@ class Page:
|
||||
:return detailed_song: it modifies the input song
|
||||
"""
|
||||
|
||||
raise NotImplementedError()
|
||||
return song
|
||||
|
||||
def fetch_album_details(cls, album: Album, simple: bool = False) -> Album:
|
||||
@classmethod
|
||||
def fetch_album_details(cls, album: Album, flat: bool = False) -> Album:
|
||||
"""
|
||||
for a general description check cls.fetch_details
|
||||
|
||||
:param album: album without much data
|
||||
:param simple:
|
||||
:param flat:
|
||||
when True it only fetches the artist and the tracklist, and the attributes of those,
|
||||
which can be gotten with one api request
|
||||
when False it fetches everything including, but not limited to:
|
||||
@@ -145,14 +147,15 @@ class Page:
|
||||
:return detailed_artist: it modifies the input artist
|
||||
"""
|
||||
|
||||
raise NotImplementedError()
|
||||
return album
|
||||
|
||||
def fetch_artist_details(cls, artist: Artist, simple: bool = False) -> Artist:
|
||||
@classmethod
|
||||
def fetch_artist_details(cls, artist: Artist, flat: bool = False) -> Artist:
|
||||
"""
|
||||
for a general description check cls.fetch_details
|
||||
|
||||
:param artist: artist without much data
|
||||
:param simple:
|
||||
:param flat:
|
||||
when True it only fetches the discographie, meaning every album, but not every tracklist
|
||||
when False it fetches everything including, but not limited to:
|
||||
- the whole discography
|
||||
@@ -161,4 +164,4 @@ class Page:
|
||||
:return detailed_artist: it modifies the input artist
|
||||
"""
|
||||
|
||||
raise NotImplementedError()
|
||||
return artist
|
||||
|
@@ -202,7 +202,7 @@ class EncyclopaediaMetallum(Page):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def fetch_artist_discography(cls, artist: Artist, ma_artist_id: str) -> Artist:
|
||||
def fetch_artist_discography(cls, artist: Artist, ma_artist_id: str, flat: bool = False) -> Artist:
|
||||
"""
|
||||
TODO
|
||||
I'd guess this funktion has quite some possibility for optimizations
|
||||
@@ -275,6 +275,10 @@ class EncyclopaediaMetallum(Page):
|
||||
|
||||
artist.main_albums = new_discography
|
||||
|
||||
if not flat:
|
||||
for album in artist.main_albums:
|
||||
cls.fetch_album_details(album, flat=flat)
|
||||
|
||||
return artist
|
||||
|
||||
@classmethod
|
||||
@@ -376,12 +380,6 @@ class EncyclopaediaMetallum(Page):
|
||||
# print(data)
|
||||
# print(band_stat_soup)
|
||||
|
||||
print("country", country)
|
||||
print("formed in", formed_in_year)
|
||||
print("genre", genre)
|
||||
print("lyrical themes", lyrical_themes)
|
||||
print("label", label_name, label_url)
|
||||
|
||||
return artist
|
||||
|
||||
@classmethod
|
||||
@@ -398,7 +396,7 @@ class EncyclopaediaMetallum(Page):
|
||||
return artist
|
||||
|
||||
@classmethod
|
||||
def fetch_artist_details(cls, artist: Artist) -> Artist:
|
||||
def fetch_artist_details(cls, artist: Artist, flat: bool = False) -> Artist:
|
||||
source_list = artist.get_sources_from_page(cls.SOURCE_TYPE)
|
||||
if len(source_list) == 0:
|
||||
return artist
|
||||
@@ -406,8 +404,6 @@ class EncyclopaediaMetallum(Page):
|
||||
# taking the fist source, cuz I only need one and multiple sources don't make that much sense
|
||||
source = source_list[0]
|
||||
artist_id = source.url.split("/")[-1]
|
||||
print(source)
|
||||
print("id", artist_id)
|
||||
|
||||
"""
|
||||
TODO
|
||||
@@ -423,7 +419,7 @@ class EncyclopaediaMetallum(Page):
|
||||
artist = cls.fetch_artist_attributes(artist, source.url)
|
||||
|
||||
# DISCOGRAPHY
|
||||
artist = cls.fetch_artist_discography(artist, artist_id)
|
||||
artist = cls.fetch_artist_discography(artist, artist_id, flat=flat)
|
||||
|
||||
# EXTERNAL SOURCES
|
||||
artist = cls.fetch_artist_sources(artist, artist_id)
|
||||
@@ -432,3 +428,35 @@ class EncyclopaediaMetallum(Page):
|
||||
artist = cls.fetch_band_notes(artist, artist_id)
|
||||
|
||||
return artist
|
||||
|
||||
@classmethod
|
||||
def fetch_album_details(cls, album: Album, flat: bool = False) -> Album:
|
||||
source_list = album.get_sources_from_page(cls.SOURCE_TYPE)
|
||||
if len(source_list) == 0:
|
||||
return album
|
||||
|
||||
source = source_list[0]
|
||||
album_id = source.url.split("/")[-1]
|
||||
|
||||
print(source)
|
||||
# <table class="display table_lyrics
|
||||
|
||||
r = cls.API_SESSION.get(source.url)
|
||||
if r.status_code != 200:
|
||||
LOGGER.warning(f"code {r.status_code} at {source.url}")
|
||||
return album
|
||||
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
|
||||
tracklist_soup = soup.find("table", {"class": "table_lyrics"})
|
||||
print(tracklist_soup.prettify)
|
||||
|
||||
return album
|
||||
|
||||
@classmethod
|
||||
def fetch_song_details(cls, song: Song, flat: bool = False) -> Song:
|
||||
source_list = song.get_sources_from_page(cls.SOURCE_TYPE)
|
||||
if len(source_list) == 0:
|
||||
return song
|
||||
|
||||
return song
|
||||
|
Reference in New Issue
Block a user