From 4e4e72104df86843e32afe82cb6493c795b5ded7 Mon Sep 17 00:00:00 2001 From: Hellow Date: Mon, 27 Mar 2023 17:48:06 +0200 Subject: [PATCH] improved run function --- src/metal_archives.py | 38 +++++++++++++++---- .../pages/encyclopaedia_metallum.py | 17 ++++++--- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/metal_archives.py b/src/metal_archives.py index 523e93f..c151f5c 100644 --- a/src/metal_archives.py +++ b/src/metal_archives.py @@ -1,15 +1,37 @@ from music_kraken import objects +from music_kraken.pages import EncyclopaediaMetallum -from music_kraken.pages import ( - EncyclopaediaMetallum -) +def search(): + results = EncyclopaediaMetallum.search_by_query("#a Ghost Bath") + print(results) -results = EncyclopaediaMetallum.search_by_query("#a Ghost Bath") +def fetch_artist(): + artist = objects.Artist( + source_list=[objects.Source(objects.SourcePages.MUSIFY, "https://musify.club/artist/psychonaut-4-83193")] + ) -artist = results[0] -artist: objects.Artist = EncyclopaediaMetallum.fetch_details(artist) + artist = EncyclopaediaMetallum.fetch_details(artist) + print(artist.options) -print(artist.options) -print() + +def fetch_album(): + album = objects.Album( + source_list=[objects.Source(objects.SourcePages.MUSIFY, + "https://musify.club/release/linkin-park-hybrid-theory-2000-188")] + ) + + album: objects.Album = EncyclopaediaMetallum.fetch_details(album) + print(album.options) + + song: objects.Song + for artist in album.artist_collection: + print(artist.id, artist.name) + for song in album.song_collection: + for artist in song.main_artist_collection: + print(artist.id, artist.name) + + +if __name__ == "__main__": + search() diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index 987d6c9..dc5e2c9 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -95,11 +95,16 @@ class EncyclopaediaMetallum(Page): @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" + 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)}") + + data_key = 'aaData' + parsed_data = r.json() + if data_key not in parsed_data: return [] return [ @@ -176,7 +181,7 @@ class EncyclopaediaMetallum(Page): source_list=[ Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url) ], - artists=[ + artist_list=[ cls.get_artist_from_json(artist_html=artist_html) ] ) @@ -197,7 +202,9 @@ class EncyclopaediaMetallum(Page): main_artist_list=[ cls.get_artist_from_json(artist_html=artist_html) ], - album=cls.get_album_from_json(album_html=album_html, release_type=release_type, artist_html=artist_html), + album_list=[ + cls.get_album_from_json(album_html=album_html, release_type=release_type, artist_html=artist_html) + ], source_list=[ Source(SourcePages.ENCYCLOPAEDIA_METALLUM, song_id) ]