improved run function

This commit is contained in:
Hellow 2023-03-27 17:48:06 +02:00
parent e973ac618d
commit 4e4e72104d
2 changed files with 42 additions and 13 deletions

View File

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

View File

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