fixed appending

This commit is contained in:
Hellow 2023-03-10 18:38:32 +01:00
parent be454bb91a
commit 76a91f57cb
5 changed files with 43 additions and 46 deletions

View File

@ -62,14 +62,16 @@ artist = EncyclopaediaMetallum.fetch_artist_details(artist, flat=False)
print_artist(artist)
"""
results = EncyclopaediaMetallum.search_by_query("#a only smile")
results = EncyclopaediaMetallum.search_by_query("#a Ghost Bath")
artist = results[0]
print(artist)
artist: objects.Artist = EncyclopaediaMetallum.fetch_details(artist)
print(artist.option_string)
for release in artist.main_album_collection:
print(release)
print(release.option_string)
print(release.song_collection)

View File

@ -42,6 +42,9 @@ class Collection:
def map_element(self, element: DatabaseObject):
for name, value in element.indexing_values:
if value is None:
continue
self._attribute_to_object_map[name][value] = element
def append(self, element: DatabaseObject, merge_on_conflict: bool = True):
@ -57,6 +60,7 @@ class Collection:
for name, value in element.indexing_values:
if value in self._attribute_to_object_map[name]:
if merge_on_conflict:
# if the object does already exist
# thus merging and don't add it afterwards
existing_object = self._attribute_to_object_map[name][value]

View File

@ -56,12 +56,12 @@ class DatabaseObject:
return list()
def merge(self, other, override: bool = False):
if isinstance(other, type(self)):
if not isinstance(other, type(self)):
LOGGER.warning(f"can't merge \"{type(other)}\" into \"{type(self)}\"")
return
for collection in type(self).COLLECTION_ATTRIBUTES:
getattr(self, collection).extend(collection)
getattr(self, collection).extend(getattr(other, collection))
for simple_attribute in type(self).SIMPLE_ATTRIBUTES:
if getattr(other, simple_attribute) is None:

View File

@ -87,7 +87,7 @@ class Song(MainObject):
return [
('id', self.id),
('title', self.unified_title),
('isrc', self.isrc.strip()),
('isrc', self.isrc),
*[('url', source.url) for source in self.source_collection]
]

View File

@ -211,7 +211,6 @@ class EncyclopaediaMetallum(Page):
"""
discography_url = "https://www.metal-archives.com/band/discography/id/{}/tab/all"
# make the request
r = cls.API_SESSION.get(discography_url.format(ma_artist_id))
if r.status_code != 200:
@ -237,15 +236,15 @@ class EncyclopaediaMetallum(Page):
except ValueError():
pass
artist.main_album_collection.append(Album(
artist.main_album_collection.append(
Album(
id_=album_id,
title=album_name,
album_type=album_type,
date=date_obj,
source_list=[
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url)
]
))
source_list=[Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url)]
)
)
if not flat:
for album in artist.main_album_collection:
@ -346,9 +345,13 @@ class EncyclopaediaMetallum(Page):
label_url = None
if label_anchor is not None:
label_url = label_anchor.get("href")
print(label_url)
label_id = None
if type(label_url) is str and "/" in label_url:
label_id = label_url.split("/")[-1]
artist.label_collection.append( Label(
artist.label_collection.append(
Label(
_id=label_id,
name=label_name,
source_list=[
Source(cls.SOURCE_TYPE, label_url)
@ -378,7 +381,7 @@ class EncyclopaediaMetallum(Page):
@classmethod
def fetch_artist_details(cls, artist: Artist, flat: bool = False) -> Artist:
source_list = artist.get_sources_from_page(cls.SOURCE_TYPE)
source_list = artist.source_collection.get_sources_from_page(cls.SOURCE_TYPE)
if len(source_list) == 0:
return artist
@ -412,7 +415,7 @@ class EncyclopaediaMetallum(Page):
@classmethod
def fetch_album_details(cls, album: Album, flat: bool = False) -> Album:
source_list = album.get_sources_from_page(cls.SOURCE_TYPE)
source_list = album.source_collection.get_sources_from_page(cls.SOURCE_TYPE)
if len(source_list) == 0:
return album
@ -458,33 +461,21 @@ class EncyclopaediaMetallum(Page):
minutes, seconds = duration_stamp.split(":")
length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds
track: Song = album.song_collection.get_object_with_source(track_id) or album.song_collection.get_object_with_attribute("title", title)
if track is not None:
track.add_source(Source(cls.SOURCE_TYPE, track_id))
if length is not None:
track.length = length
track.tracksort = track_sort
continue
track = Song(
album.song_collection.append(
Song(
id_=track_id,
title=title,
length=length,
tracksort=track_sort,
source_list=[
Source(cls.SOURCE_TYPE, track_id)
]
source_list=[Source(cls.SOURCE_TYPE, track_id)]
)
)
album.song_collection.append(track)
return album
@classmethod
def fetch_song_details(cls, song: Song, flat: bool = False) -> Song:
source_list = song.get_sources_from_page(cls.SOURCE_TYPE)
source_list = song.source_collection.get_sources_from_page(cls.SOURCE_TYPE)
if len(source_list) == 0:
return song