fix: updating the tracksort on songs

This commit is contained in:
Hazel 2024-04-11 15:44:59 +02:00
parent 38f3b1da1d
commit d71c2f19e7
3 changed files with 10 additions and 35 deletions

View File

@ -144,7 +144,7 @@ def cli():
genre=genre, genre=genre,
download_all=arguments.all, download_all=arguments.all,
direct_download_url=arguments.url, direct_download_url=arguments.url,
process_metadata_anyway=arguments.force_post_process or arguments.test process_metadata_anyway=True or arguments.test
) )

View File

@ -320,40 +320,16 @@ class Album(Base):
return return
tracksort_map: Dict[int, Song] = { 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
""" existing_list = self.song_collection.shallow_list
I ONLY modify the `Collection._data` attribute directly, for i in range(1, len(existing_list) + 1):
to bypass the mapping of the attributes, because I will add the item in the next step 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): def compile(self, merge_into: bool = False):
""" """

View File

@ -335,7 +335,7 @@ class Page:
music_object: DatabaseObject, music_object: DatabaseObject,
genre: str, genre: str,
download_all: bool = False, download_all: bool = False,
process_metadata_anyway: bool = False process_metadata_anyway: bool = True
) -> DownloadResult: ) -> DownloadResult:
naming_dict: NamingDict = NamingDict({"genre": genre}) naming_dict: NamingDict = NamingDict({"genre": genre})
@ -362,7 +362,7 @@ class Page:
naming_dict: NamingDict, naming_dict: NamingDict,
download_all: bool = False, download_all: bool = False,
skip_details: bool = False, skip_details: bool = False,
process_metadata_anyway: bool = False process_metadata_anyway: bool = True
) -> DownloadResult: ) -> DownloadResult:
trace(f"downloading {type(music_object).__name__} [{music_object.title_string}]") trace(f"downloading {type(music_object).__name__} [{music_object.title_string}]")
skip_next_details = skip_details skip_next_details = skip_details
@ -381,7 +381,6 @@ class Page:
if isinstance(music_object, Album): if isinstance(music_object, Album):
music_object.update_tracksort() music_object.update_tracksort()
naming_dict.add_object(music_object) naming_dict.add_object(music_object)
if isinstance(music_object, Song): if isinstance(music_object, Song):
@ -400,7 +399,7 @@ class Page:
return download_result 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: if "genre" not in naming_dict and song.genre is not None:
naming_dict["genre"] = song.genre naming_dict["genre"] = song.genre