From d71c2f19e76138a1d314c8c8bcea9e6adaf7c696 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 11 Apr 2024 15:44:59 +0200 Subject: [PATCH] fix: updating the tracksort on songs --- music_kraken/__main__.py | 2 +- music_kraken/objects/song.py | 36 ++++++---------------------------- music_kraken/pages/abstract.py | 7 +++---- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/music_kraken/__main__.py b/music_kraken/__main__.py index b90757b..a04e82a 100644 --- a/music_kraken/__main__.py +++ b/music_kraken/__main__.py @@ -144,7 +144,7 @@ def cli(): genre=genre, download_all=arguments.all, direct_download_url=arguments.url, - process_metadata_anyway=arguments.force_post_process or arguments.test + process_metadata_anyway=True or arguments.test ) diff --git a/music_kraken/objects/song.py b/music_kraken/objects/song.py index a7b50dc..c9c8c96 100644 --- a/music_kraken/objects/song.py +++ b/music_kraken/objects/song.py @@ -320,40 +320,16 @@ class Album(Base): return tracksort_map: Dict[int, Song] = { - song.tracksort: song for song in self.song_collection if song.tracksort is not None + song.tracksort: song for song in self.song_collection if song.tracksort != 0 } - # place the songs, with set tracksort attribute according to it - for tracksort, song in tracksort_map.items(): - index = tracksort - 1 - """ - I ONLY modify the `Collection._data` attribute directly, - to bypass the mapping of the attributes, because I will add the item in the next step - """ + existing_list = self.song_collection.shallow_list + for i in range(1, len(existing_list) + 1): + if i not in tracksort_map: + tracksort_map[i] = existing_list.pop(0) + tracksort_map[i].tracksort = i - """ - but for some reason, neither - `self.song_collection._data.index(song)` - `self.song_collection._data.remove(song)` - get the right object. - - I have NO FUCKING CLUE why xD - But I just implemented it myself. - """ - for old_index, temp_song in enumerate(self.song_collection._data): - if song is temp_song: - break - - # the list can't be empty - del self.song_collection._data[old_index] - self.song_collection._data.insert(index, song) - - # fill in the empty tracksort attributes - for i, song in enumerate(self.song_collection): - if song.tracksort is not None: - continue - song.tracksort = i + 1 def compile(self, merge_into: bool = False): """ diff --git a/music_kraken/pages/abstract.py b/music_kraken/pages/abstract.py index 09b07b9..29ba68c 100644 --- a/music_kraken/pages/abstract.py +++ b/music_kraken/pages/abstract.py @@ -335,7 +335,7 @@ class Page: music_object: DatabaseObject, genre: str, download_all: bool = False, - process_metadata_anyway: bool = False + process_metadata_anyway: bool = True ) -> DownloadResult: naming_dict: NamingDict = NamingDict({"genre": genre}) @@ -362,7 +362,7 @@ class Page: naming_dict: NamingDict, download_all: bool = False, skip_details: bool = False, - process_metadata_anyway: bool = False + process_metadata_anyway: bool = True ) -> DownloadResult: trace(f"downloading {type(music_object).__name__} [{music_object.title_string}]") skip_next_details = skip_details @@ -381,7 +381,6 @@ class Page: if isinstance(music_object, Album): music_object.update_tracksort() - naming_dict.add_object(music_object) if isinstance(music_object, Song): @@ -400,7 +399,7 @@ class Page: return download_result - def _download_song(self, song: Song, naming_dict: NamingDict, process_metadata_anyway: bool = False): + def _download_song(self, song: Song, naming_dict: NamingDict, process_metadata_anyway: bool = True): if "genre" not in naming_dict and song.genre is not None: naming_dict["genre"] = song.genre