fixed appending
This commit is contained in:
parent
be454bb91a
commit
76a91f57cb
@ -62,14 +62,16 @@ artist = EncyclopaediaMetallum.fetch_artist_details(artist, flat=False)
|
|||||||
print_artist(artist)
|
print_artist(artist)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
results = EncyclopaediaMetallum.search_by_query("#a only smile")
|
results = EncyclopaediaMetallum.search_by_query("#a Ghost Bath")
|
||||||
|
|
||||||
artist = results[0]
|
artist = results[0]
|
||||||
print(artist)
|
print(artist)
|
||||||
|
|
||||||
artist: objects.Artist = EncyclopaediaMetallum.fetch_details(artist)
|
artist: objects.Artist = EncyclopaediaMetallum.fetch_details(artist)
|
||||||
|
print(artist.option_string)
|
||||||
|
|
||||||
for release in artist.main_album_collection:
|
for release in artist.main_album_collection:
|
||||||
print(release)
|
print(release.option_string)
|
||||||
|
|
||||||
print(release.song_collection)
|
print(release.song_collection)
|
||||||
|
|
||||||
|
@ -42,6 +42,9 @@ class Collection:
|
|||||||
|
|
||||||
def map_element(self, element: DatabaseObject):
|
def map_element(self, element: DatabaseObject):
|
||||||
for name, value in element.indexing_values:
|
for name, value in element.indexing_values:
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
self._attribute_to_object_map[name][value] = element
|
self._attribute_to_object_map[name][value] = element
|
||||||
|
|
||||||
def append(self, element: DatabaseObject, merge_on_conflict: bool = True):
|
def append(self, element: DatabaseObject, merge_on_conflict: bool = True):
|
||||||
@ -57,6 +60,7 @@ class Collection:
|
|||||||
|
|
||||||
for name, value in element.indexing_values:
|
for name, value in element.indexing_values:
|
||||||
if value in self._attribute_to_object_map[name]:
|
if value in self._attribute_to_object_map[name]:
|
||||||
|
if merge_on_conflict:
|
||||||
# if the object does already exist
|
# if the object does already exist
|
||||||
# thus merging and don't add it afterwards
|
# thus merging and don't add it afterwards
|
||||||
existing_object = self._attribute_to_object_map[name][value]
|
existing_object = self._attribute_to_object_map[name][value]
|
||||||
|
@ -56,12 +56,12 @@ class DatabaseObject:
|
|||||||
return list()
|
return list()
|
||||||
|
|
||||||
def merge(self, other, override: bool = False):
|
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)}\"")
|
LOGGER.warning(f"can't merge \"{type(other)}\" into \"{type(self)}\"")
|
||||||
return
|
return
|
||||||
|
|
||||||
for collection in type(self).COLLECTION_ATTRIBUTES:
|
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:
|
for simple_attribute in type(self).SIMPLE_ATTRIBUTES:
|
||||||
if getattr(other, simple_attribute) is None:
|
if getattr(other, simple_attribute) is None:
|
||||||
|
@ -87,7 +87,7 @@ class Song(MainObject):
|
|||||||
return [
|
return [
|
||||||
('id', self.id),
|
('id', self.id),
|
||||||
('title', self.unified_title),
|
('title', self.unified_title),
|
||||||
('isrc', self.isrc.strip()),
|
('isrc', self.isrc),
|
||||||
*[('url', source.url) for source in self.source_collection]
|
*[('url', source.url) for source in self.source_collection]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -211,7 +211,6 @@ class EncyclopaediaMetallum(Page):
|
|||||||
"""
|
"""
|
||||||
discography_url = "https://www.metal-archives.com/band/discography/id/{}/tab/all"
|
discography_url = "https://www.metal-archives.com/band/discography/id/{}/tab/all"
|
||||||
|
|
||||||
|
|
||||||
# make the request
|
# make the request
|
||||||
r = cls.API_SESSION.get(discography_url.format(ma_artist_id))
|
r = cls.API_SESSION.get(discography_url.format(ma_artist_id))
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
@ -237,15 +236,15 @@ class EncyclopaediaMetallum(Page):
|
|||||||
except ValueError():
|
except ValueError():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
artist.main_album_collection.append(Album(
|
artist.main_album_collection.append(
|
||||||
|
Album(
|
||||||
id_=album_id,
|
id_=album_id,
|
||||||
title=album_name,
|
title=album_name,
|
||||||
album_type=album_type,
|
album_type=album_type,
|
||||||
date=date_obj,
|
date=date_obj,
|
||||||
source_list=[
|
source_list=[Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url)]
|
||||||
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url)
|
)
|
||||||
]
|
)
|
||||||
))
|
|
||||||
|
|
||||||
if not flat:
|
if not flat:
|
||||||
for album in artist.main_album_collection:
|
for album in artist.main_album_collection:
|
||||||
@ -346,9 +345,13 @@ class EncyclopaediaMetallum(Page):
|
|||||||
label_url = None
|
label_url = None
|
||||||
if label_anchor is not None:
|
if label_anchor is not None:
|
||||||
label_url = label_anchor.get("href")
|
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,
|
name=label_name,
|
||||||
source_list=[
|
source_list=[
|
||||||
Source(cls.SOURCE_TYPE, label_url)
|
Source(cls.SOURCE_TYPE, label_url)
|
||||||
@ -378,7 +381,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fetch_artist_details(cls, artist: Artist, flat: bool = False) -> Artist:
|
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:
|
if len(source_list) == 0:
|
||||||
return artist
|
return artist
|
||||||
|
|
||||||
@ -412,7 +415,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fetch_album_details(cls, album: Album, flat: bool = False) -> Album:
|
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:
|
if len(source_list) == 0:
|
||||||
return album
|
return album
|
||||||
|
|
||||||
@ -458,33 +461,21 @@ class EncyclopaediaMetallum(Page):
|
|||||||
minutes, seconds = duration_stamp.split(":")
|
minutes, seconds = duration_stamp.split(":")
|
||||||
length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds
|
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)
|
album.song_collection.append(
|
||||||
|
Song(
|
||||||
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(
|
|
||||||
id_=track_id,
|
id_=track_id,
|
||||||
title=title,
|
title=title,
|
||||||
length=length,
|
length=length,
|
||||||
tracksort=track_sort,
|
tracksort=track_sort,
|
||||||
source_list=[
|
source_list=[Source(cls.SOURCE_TYPE, track_id)]
|
||||||
Source(cls.SOURCE_TYPE, track_id)
|
)
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
album.song_collection.append(track)
|
|
||||||
|
|
||||||
return album
|
return album
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fetch_song_details(cls, song: Song, flat: bool = False) -> Song:
|
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:
|
if len(source_list) == 0:
|
||||||
return song
|
return song
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user