diff --git a/src/goof.py b/src/goof.py index da0beb9..c2644e6 100644 --- a/src/goof.py +++ b/src/goof.py @@ -3,4 +3,4 @@ from music_kraken.pages import ( ) # print(EncyclopaediaMetallum.search_by_query("Death")) -EncyclopaediaMetallum.search_by_query("#a Ghost Bath #r Self Loather #t hide from the sun") +print(EncyclopaediaMetallum.search_by_query("#a Ghost Bath #r Self Loather #t hide from the sun")) diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index aa2fde6..c604371 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -12,7 +12,8 @@ from ..database import ( Artist, Source, SourcePages, - Song + Song, + Album ) @@ -48,7 +49,12 @@ class EncyclopaediaMetallum(Page): return [] print(r.json()['aaData']) - return [] + return [cls.get_song_from_json( + artist_html=raw_song[0], + album_html=raw_song[1], + release_type=raw_song[2], + title=raw_song[3] + ) for raw_song in r.json()['aaData']] @classmethod def simple_search(cls, query: Page.Query) -> List[Artist]: @@ -65,12 +71,12 @@ class EncyclopaediaMetallum(Page): print(r.json()) return [ - cls.get_artist_from_json(raw_artist[0], raw_artist[1], raw_artist[2]) + cls.get_artist_from_json(html=raw_artist[0], genre=raw_artist[1], country=raw_artist[2]) for raw_artist in r.json()['aaData'] ] @classmethod - def get_artist_from_json(cls, html, genre, country) -> Artist: + def get_artist_from_json(cls, html=None, genre=None, country=None) -> Artist: """ TODO parse the country to a standart """ @@ -100,3 +106,35 @@ class EncyclopaediaMetallum(Page): ], notes = notes ) + + @classmethod + def get_album_from_json(cls, album_html=None, release_type=None) -> Album: + # parse the html + # Self Loather' + soup = BeautifulSoup(album_html, 'html.parser') + anchor = soup.find('a') + album_name = anchor.text + album_url = anchor.get('href') + album_id = int(album_url.split("/")[-1]) + + """ + TODO implement release type + TODO add artist argument to + """ + return Album( + id_=album_id, + title=album_name, + sources=[ + Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url) + ] + ) + + @classmethod + def get_song_from_json(cls, artist_html=None, album_html=None, release_type=None, title=None) -> Song: + return Song( + title=title, + main_artist_list=[ + cls.get_artist_from_json(html=artist_html) + ], + album=cls.get_album_from_json(album_html=album_html, release_type=release_type) + )