diff --git a/src/goof.py b/src/goof.py index c2644e6..f53f965 100644 --- a/src/goof.py +++ b/src/goof.py @@ -2,5 +2,7 @@ from music_kraken.pages import ( EncyclopaediaMetallum ) -# print(EncyclopaediaMetallum.search_by_query("Death")) +print(EncyclopaediaMetallum.search_by_query("Psychonaut")) +print(EncyclopaediaMetallum.search_by_query("#a Ghost Bath")) +print(EncyclopaediaMetallum.search_by_query("#a Ghost Bath #r Self Loather")) print(EncyclopaediaMetallum.search_by_query("#a Ghost Bath #r Self Loather #t hide from the sun")) diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index 6087497..3d85247 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -240,7 +240,8 @@ class Album(DatabaseObject, ID3Metadata): is_split: bool = False, albumsort: int = None, dynamic: bool = False, - sources: List[Source] = None + sources: List[Source] = None, + artists: list = None ) -> None: DatabaseObject.__init__(self, id_=id_, dynamic=dynamic) self.title: str = title @@ -259,11 +260,14 @@ class Album(DatabaseObject, ID3Metadata): self.albumsort: int | None = albumsort self.tracklist: List[Song] = [] - self.artists: List[Artist] = [] self._sources = [] self.sources = sources + self.artists = [] + if artists is not None: + self.artists = artists + def __str__(self) -> str: return f"Album: \"{self.title}\"" diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index c604371..ca76eab 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -37,6 +37,10 @@ class EncyclopaediaMetallum(Page): def advanced_search(cls, query: Page.Query) -> List[MusicObject]: if query.song is not None: return cls.search_for_song(query=query) + if query.album is not None: + return cls.search_for_album(query=query) + if query.artist is not None: + return cls.search_for_artist(query=query) return [] @classmethod @@ -48,7 +52,6 @@ class EncyclopaediaMetallum(Page): LOGGER.warning(f"code {r.status_code} at {endpoint.format(song=query.song_str, artist=query.artist_str, album=query.album_str)}") return [] - print(r.json()['aaData']) return [cls.get_song_from_json( artist_html=raw_song[0], album_html=raw_song[1], @@ -56,6 +59,35 @@ class EncyclopaediaMetallum(Page): title=raw_song[3] ) for raw_song in r.json()['aaData']] + @classmethod + def search_for_album(cls, query: Page.Query) -> List[Album]: + endpoint = "https://www.metal-archives.com/search/ajax-advanced/searching/albums/?bandName={artist}&releaseTitle={album}&releaseYearFrom=&releaseMonthFrom=&releaseYearTo=&releaseMonthTo=&country=&location=&releaseLabelName=&releaseCatalogNumber=&releaseIdentifiers=&releaseRecordingInfo=&releaseDescription=&releaseNotes=&genre=&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&_=1674563943747" + + r = cls.API_SESSION.get(endpoint.format(artist=query.artist_str, album=query.album_str)) + if r.status_code != 200: + LOGGER.warning(f"code {r.status_code} at {endpoint.format(song=query.song_str, artist=query.artist_str, album=query.album_str)}") + return [] + + return [cls.get_album_from_json( + artist_html=raw_album[0], + album_html=raw_album[1], + release_type=[2] + ) for raw_album in r.json()['aaData']] + + @classmethod + def search_for_artist(cls, query: Page.Query) -> List[Artist]: + endpoint = "https://www.metal-archives.com/search/ajax-advanced/searching/bands/?bandName={artist}&genre=&country=&yearCreationFrom=&yearCreationTo=&bandNotes=&status=&themes=&location=&bandLabelName=&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&_=1674565459976" + + r = cls.API_SESSION.get(endpoint.format(artist=query.artist)) + if r.status_code != 200: + LOGGER.warning(f"code {r.status_code} at {endpoint.format(artist=query.artist)}") + return [] + + return [ + 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 simple_search(cls, query: Page.Query) -> List[Artist]: """ @@ -69,7 +101,6 @@ class EncyclopaediaMetallum(Page): LOGGER.warning(f"code {r.status_code} at {endpoint.format(query=query.query)}") return [] - print(r.json()) return [ cls.get_artist_from_json(html=raw_artist[0], genre=raw_artist[1], country=raw_artist[2]) for raw_artist in r.json()['aaData'] @@ -108,7 +139,7 @@ class EncyclopaediaMetallum(Page): ) @classmethod - def get_album_from_json(cls, album_html=None, release_type=None) -> Album: + def get_album_from_json(cls, album_html=None, release_type=None, artist_html=None) -> Album: # parse the html # Self Loather' soup = BeautifulSoup(album_html, 'html.parser') @@ -136,5 +167,5 @@ class EncyclopaediaMetallum(Page): 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) + album=cls.get_album_from_json(album_html=album_html, release_type=release_type, artist_html=artist_html) )