diff --git a/src/goof.py b/src/goof.py index 83e8324..da0beb9 100644 --- a/src/goof.py +++ b/src/goof.py @@ -2,5 +2,5 @@ from music_kraken.pages import ( EncyclopaediaMetallum ) -print(EncyclopaediaMetallum.search_by_query("Ghost Bath")) -EncyclopaediaMetallum.search_by_query("#a Ghost Bath #r Self Loather") +# print(EncyclopaediaMetallum.search_by_query("Death")) +EncyclopaediaMetallum.search_by_query("#a Ghost Bath #r Self Loather #t hide from the sun") diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index b875661..2bd7f07 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -57,9 +57,18 @@ class Page: self.album = input_ continue if type_ == "t": - self.song = type_ + self.song = input_ continue + def get_str(self, string): + if string is None: + return "" + return string + + artist_str = property(fget=lambda self: self.get_str(self.artist)) + album_str = property(fget=lambda self: self.get_str(self.album)) + song_str = property(fget=lambda self: self.get_str(self.song)) + @classmethod def search_by_query(cls, query: str) -> List[MusicObject]: """ diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index 8983de3..aa2fde6 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -11,7 +11,8 @@ from ..database import ( MusicObject, Artist, Source, - SourcePages + SourcePages, + Song ) @@ -29,10 +30,28 @@ class EncyclopaediaMetallum(Page): if query_obj.is_raw: return cls.simple_search(query_obj) - print(query_obj) + return cls.advanced_search(query_obj) @classmethod - def simple_search(cls, query: Page.Query): + def advanced_search(cls, query: Page.Query) -> List[MusicObject]: + if query.song is not None: + return cls.search_for_song(query=query) + return [] + + @classmethod + def search_for_song(cls, query: Page.Query) -> List[Song]: + endpoint = "https://www.metal-archives.com/search/ajax-advanced/searching/songs/?songTitle={song}&bandName={artist}&releaseTitle={album}&lyrics=&genre=&sEcho=1&iColumns=5&sColumns=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&_=1674550595663" + + r = cls.API_SESSION.get(endpoint.format(song=query.song_str, 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 [] + + print(r.json()['aaData']) + return [] + + @classmethod + def simple_search(cls, query: Page.Query) -> List[Artist]: """ Searches the default endpoint from metal archives, which intern searches only for bands, but it is the default, thus I am rolling with it @@ -45,7 +64,10 @@ class EncyclopaediaMetallum(Page): return [] print(r.json()) - return cls.get_many_artists_from_json(r.json()['aaData']) + return [ + cls.get_artist_from_json(raw_artist[0], raw_artist[1], raw_artist[2]) + for raw_artist in r.json()['aaData'] + ] @classmethod def get_artist_from_json(cls, html, genre, country) -> Artist: @@ -78,7 +100,3 @@ class EncyclopaediaMetallum(Page): ], notes = notes ) - - @classmethod - def get_many_artists_from_json(cls, raw_artist_list: list) -> List[Artist]: - return [cls.get_artist_from_json(raw_artist) for raw_artist in raw_artist_list]