metal enzyclopedie

This commit is contained in:
Lars Noack 2023-01-24 12:09:47 +01:00
parent 3957dc4088
commit 081a57360f
2 changed files with 43 additions and 5 deletions

View File

@ -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"))

View File

@ -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
# <a href="https://www.metal-archives.com/albums/Ghost_Bath/Self_Loather/970834">Self Loather</a>'
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)
)