From ece7ffa5db91dda8dccbdd7be243f833cdc99a00 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 7 Feb 2023 13:32:49 +0100 Subject: [PATCH] hs --- src/music_kraken/database/objects/metadata.py | 2 +- .../pages/encyclopaedia_metallum.py | 45 +++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/music_kraken/database/objects/metadata.py b/src/music_kraken/database/objects/metadata.py index c14ed85..c98e7de 100644 --- a/src/music_kraken/database/objects/metadata.py +++ b/src/music_kraken/database/objects/metadata.py @@ -16,7 +16,7 @@ class Mapping(Enum): # Textframes TITLE = "TIT2" ISRC = "TSRC" - LENGTH = "TLEN" + LENGTH = "TLEN" # in milliseconds DATE = "TYER" TRACKNUMBER = "TRCK" TOTALTRACKS = "TRCK" # Stored in the same frame with TRACKNUMBER, separated by '/': e.g. '4/9'. diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index 721aca1..c4d44e3 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -446,6 +446,19 @@ class EncyclopaediaMetallum(Page): LOGGER.warning(f"code {r.status_code} at {source.url}") return album + # prepare tracklist + track_by_url = dict() + track_by_name = dict() + for track in album._tracklist: + track_by_name[string_processing.unify(track.title)] = track + for source in track.get_sources_from_page(cls.SOURCE_TYPE): + track_by_url[source.url] = album + old_tracklist = album._tracklist.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_tracklist = [] + soup = BeautifulSoup(r.text, 'html.parser') tracklist_soup = soup.find("table", {"class": "table_lyrics"}).find("tbody") @@ -473,13 +486,37 @@ class EncyclopaediaMetallum(Page): duration_stamp = row_list[2].text minutes, seconds = duration_stamp.split(":") - duration_in_seconds = int(minutes) * 60 + int(seconds) - print(track_sort, track_id) - print(title) - print(duration_in_seconds) + length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds + + track: Song + if track_id in track_by_url: + track = track_by_url[track_id] + used_ids.add(track.id) + elif title in track_by_name: + track = track_by_name[title] + used_ids.add(track.id) + else: + track = Song( + id_=track_id, + title=title, + length=length, + tracksort=track_sort + ) + track.add_source(Source(cls.SOURCE_TYPE, track_id)) + + new_tracklist.append(track) + + print(track) print("-"*20) # print(row) + for old_track in old_tracklist: + if old_track.dynamic: + continue + if old_track.id not in used_ids: + new_tracklist.append(old_track) + album.tracklist = new_tracklist + return album @classmethod