finished fetching of tracklist
This commit is contained in:
parent
42852fbd32
commit
9efc806bec
@ -1,7 +1,8 @@
|
|||||||
from music_kraken import (
|
from music_kraken import (
|
||||||
Song,
|
Song,
|
||||||
Database,
|
Database,
|
||||||
Artist
|
Artist,
|
||||||
|
Album
|
||||||
)
|
)
|
||||||
|
|
||||||
from music_kraken.pages import (
|
from music_kraken.pages import (
|
||||||
@ -13,7 +14,6 @@ test_db = Database("test.db")
|
|||||||
# test_db.reset()
|
# test_db.reset()
|
||||||
|
|
||||||
def print_source(source_obj):
|
def print_source(source_obj):
|
||||||
print("---source---")
|
|
||||||
for source in source_obj.source_list:
|
for source in source_obj.source_list:
|
||||||
print(source)
|
print(source)
|
||||||
|
|
||||||
@ -33,10 +33,15 @@ def print_song(song_: Song):
|
|||||||
|
|
||||||
def print_artist(artist: Artist):
|
def print_artist(artist: Artist):
|
||||||
print(artist)
|
print(artist)
|
||||||
|
print_source(artist)
|
||||||
print("---discography---")
|
print("---discography---")
|
||||||
for album in artist.discography:
|
for album in artist.discography:
|
||||||
print(album)
|
print_album(album)
|
||||||
print_source(artist)
|
|
||||||
|
|
||||||
|
def print_album(album: Album):
|
||||||
|
print(album)
|
||||||
|
print_source(album)
|
||||||
|
|
||||||
|
|
||||||
# only_smile = EncyclopaediaMetallum.search_by_query("only smile")
|
# only_smile = EncyclopaediaMetallum.search_by_query("only smile")
|
||||||
@ -57,14 +62,5 @@ else:
|
|||||||
print_song(song)
|
print_song(song)
|
||||||
|
|
||||||
artist = song.main_artist_list[0]
|
artist = song.main_artist_list[0]
|
||||||
|
artist = EncyclopaediaMetallum.fetch_artist_details(artist, flat=False)
|
||||||
# print_artist(artist)
|
print_artist(artist)
|
||||||
|
|
||||||
# artist = EncyclopaediaMetallum.fetch_artist_details(artist, flat=False)
|
|
||||||
|
|
||||||
album = EncyclopaediaMetallum.fetch_album_details(song.album, flat=False)
|
|
||||||
print(album)
|
|
||||||
|
|
||||||
# print_artist(artist)
|
|
||||||
|
|
||||||
# print(only_smile)
|
|
||||||
|
@ -73,3 +73,12 @@ class Collection:
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "\n".join([f"{str(j).zfill(2)}: {i}" for j, i in enumerate(self._data)])
|
return "\n".join([f"{str(j).zfill(2)}: {i}" for j, i in enumerate(self._data)])
|
||||||
|
|
||||||
|
def __len__(self) -> int:
|
||||||
|
return len(self._data)
|
||||||
|
|
||||||
|
def copy(self) -> List:
|
||||||
|
"""
|
||||||
|
returns a shallow copy of the data list
|
||||||
|
"""
|
||||||
|
return self._data.copy()
|
||||||
|
@ -264,9 +264,17 @@ class Album(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
dynamic: bool = False,
|
dynamic: bool = False,
|
||||||
source_list: List[Source] = None,
|
source_list: List[Source] = None,
|
||||||
artists: list = None,
|
artists: list = None,
|
||||||
tracklist: List[Song] = None
|
tracklist: List[Song] = None,
|
||||||
|
album_type: str = None
|
||||||
) -> None:
|
) -> None:
|
||||||
DatabaseObject.__init__(self, id_=id_, dynamic=dynamic)
|
DatabaseObject.__init__(self, id_=id_, dynamic=dynamic)
|
||||||
|
|
||||||
|
"""
|
||||||
|
TODO
|
||||||
|
add to db
|
||||||
|
"""
|
||||||
|
self.album_type = album_type
|
||||||
|
|
||||||
self.title: str = title
|
self.title: str = title
|
||||||
self.album_status: str = album_status
|
self.album_status: str = album_status
|
||||||
self.label = label
|
self.label = label
|
||||||
@ -413,9 +421,18 @@ class Artist(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
self.name: str | None = name
|
self.name: str | None = name
|
||||||
|
|
||||||
self.main_songs = main_songs
|
self.main_songs = main_songs
|
||||||
self.feature_songs = feature_songs
|
|
||||||
|
|
||||||
self.main_albums = main_albums
|
self.feature_songs = Collection(
|
||||||
|
data=feature_songs,
|
||||||
|
map_attributes=["title"],
|
||||||
|
element_type=Song
|
||||||
|
)
|
||||||
|
|
||||||
|
self.main_albums = Collection(
|
||||||
|
data=main_albums,
|
||||||
|
map_attributes=["title"],
|
||||||
|
element_type=Album
|
||||||
|
)
|
||||||
|
|
||||||
if source_list is not None:
|
if source_list is not None:
|
||||||
self.source_list = source_list
|
self.source_list = source_list
|
||||||
@ -467,10 +484,6 @@ class Artist(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
return flat_copy_discography
|
return flat_copy_discography
|
||||||
|
|
||||||
def get_metadata(self) -> MetadataAttribute.Metadata:
|
def get_metadata(self) -> MetadataAttribute.Metadata:
|
||||||
"""
|
|
||||||
TODO refactor
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
metadata = MetadataAttribute.Metadata({
|
metadata = MetadataAttribute.Metadata({
|
||||||
id3Mapping.ARTIST: [self.name]
|
id3Mapping.ARTIST: [self.name]
|
||||||
})
|
})
|
||||||
|
@ -210,19 +210,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"
|
||||||
|
|
||||||
# prepare tracklist
|
|
||||||
album_by_url = dict()
|
|
||||||
album_by_name = dict()
|
|
||||||
for album in artist.main_albums:
|
|
||||||
album_by_name[string_processing.unify(album.title)] = album
|
|
||||||
for source in album.get_sources_from_page(cls.SOURCE_TYPE):
|
|
||||||
album_by_url[source.url] = album
|
|
||||||
old_discography = artist.main_albums.copy()
|
|
||||||
# save the ids of the albums, that are added to this set, so I can
|
|
||||||
# efficiently add all leftover albums from the discography to the new one
|
|
||||||
used_ids = set()
|
|
||||||
|
|
||||||
new_discography: List[Album] = []
|
|
||||||
|
|
||||||
# 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))
|
||||||
@ -243,37 +230,32 @@ class EncyclopaediaMetallum(Page):
|
|||||||
album_id = album_url.split('/')[-1]
|
album_id = album_url.split('/')[-1]
|
||||||
album_type = td_list[1].text
|
album_type = td_list[1].text
|
||||||
album_year = td_list[2].text
|
album_year = td_list[2].text
|
||||||
|
date_obj = None
|
||||||
unified_name = string_processing.unify(album_name)
|
|
||||||
|
|
||||||
album_obj: Album = Album(id_=album_id)
|
|
||||||
|
|
||||||
if album_url in album_by_url:
|
|
||||||
album_obj = album_by_url[album_url]
|
|
||||||
used_ids.add(album_obj.id)
|
|
||||||
|
|
||||||
elif unified_name in album_by_name:
|
|
||||||
album_obj = album_by_name[unified_name]
|
|
||||||
album_obj.add_source(Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url))
|
|
||||||
used_ids.add(album_obj.id)
|
|
||||||
else:
|
|
||||||
album_obj.add_source(Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url))
|
|
||||||
|
|
||||||
album_obj.title = album_name
|
|
||||||
album_obj.album_type = album_type
|
|
||||||
try:
|
try:
|
||||||
album_obj.date = ID3Timestamp(year=int(album_year))
|
date_obj = ID3Timestamp(year=int(album_year))
|
||||||
except ValueError():
|
except ValueError():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
new_discography.append(album_obj)
|
|
||||||
|
|
||||||
# add the albums back, which weren't on this page
|
album_obj: Album = artist.main_albums.get_object_with_source(album_url) or artist.main_albums.get_object_with_attribute("title", album_name)
|
||||||
for old_object in old_discography:
|
|
||||||
if old_object.id not in used_ids:
|
|
||||||
new_discography.append(old_object)
|
|
||||||
|
|
||||||
artist.main_albums = new_discography
|
if album_obj is not None:
|
||||||
|
album_obj.add_source(Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url))
|
||||||
|
album_obj.title = album_name
|
||||||
|
album_obj.album_type = album_type
|
||||||
|
if date_obj is not None:
|
||||||
|
album_obj.date = date_obj
|
||||||
|
continue
|
||||||
|
|
||||||
|
artist.main_albums.append(Album(
|
||||||
|
id_=album_id,
|
||||||
|
title=album_name,
|
||||||
|
album_type=album_type,
|
||||||
|
date=date_obj,
|
||||||
|
source_list=[
|
||||||
|
Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url)
|
||||||
|
]
|
||||||
|
))
|
||||||
|
|
||||||
if not flat:
|
if not flat:
|
||||||
for album in artist.main_albums:
|
for album in artist.main_albums:
|
||||||
|
Loading…
Reference in New Issue
Block a user