From 013e3dccfd0e6726e73a26fa320767a21a584ba8 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Wed, 11 Jan 2023 15:28:22 +0100 Subject: [PATCH] fixed DISGUSTING bug --- src/goof.py | 4 +- src/music_kraken/database/objects/song.py | 45 +++++++++++++++++----- test.db | Bin 69632 -> 69632 bytes 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/goof.py b/src/goof.py index 33b90d5..4313320 100644 --- a/src/goof.py +++ b/src/goof.py @@ -85,9 +85,9 @@ song_output_list = cache.pull_songs(song_ref=song_ref) print(len(song_output_list), song_output_list, song_output_list[0].album, sep=" | ") song = song_output_list[0] print("tracksort", song_output_list[0].tracksort, sep=": ") -print("ID3 stuff") +print("ID3", dict(song.metadata)) print(str(song_output_list[0].metadata)) -print("sources:") +print("--src--") for source in song.sources: print(source) diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index f8f5e7c..677accb 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -45,12 +45,19 @@ class Metadata: def __init__(self, data: dict = {}) -> None: # this is pretty self explanatory # the key is a 4 letter key from the id3 standarts like TITL - self.id3_attributes: Dict[str, any] = {} + self.id3_attributes: Dict[str, list] = {} + + # its a null byte for the later concatination of text frames + self.null_byte = "\x00" def get_all_metadata(self): return list(self.id3_attributes.items()) - def __setitem__(self, key, value): + def __setitem__(self, key: str, value: list): + if len(value) == 0: + return + if type(value) != list: + raise ValueError(f"can only set attribute to list, not {type(value)}") self.id3_attributes[key] = value def __getitem__(self, key): @@ -62,6 +69,26 @@ class Metadata: if key in self.id3_attributes: return self.id3_attributes.pop(key) + def get_id3_value(self, key: str): + if key not in self.id3_attributes: + return None + + list_data = self.id3_attributes[key] + + """ + Version 2.4 of the specification prescribes that all text fields (the fields that start with a T, except for TXXX) can contain multiple values separated by a null character. + Thus if above conditions are met, I concetonate the list, + else I take the first element + """ + if key[0].upper() == "T" and key.upper() != "TXXX": + return self.null_byte.join(list_data) + + return list_data[0] + + def __iter__(self): + for key in self.id3_attributes: + yield (key, self.get_id3_value(key)) + def __str__(self) -> str: rows = [] for key, value in self.id3_attributes.items(): @@ -191,9 +218,7 @@ class Song(DatabaseObject): self.tracksort: int | None = tracksort if sources is not None: - fuck_you_garbage_collector = sources[:] - print("constructor", sources) - self.sources = sources + self.set_sources(source_list=sources) if target is None: target = Target() @@ -263,7 +288,7 @@ class Song(DatabaseObject): if type(value) == int: id3_value = str(value) - self.metadata[attribute_map[name].value] = id3_value + self.metadata[attribute_map[name].value] = [id3_value] def add_source(self, source_obj: Source): source_obj.add_song(self) @@ -273,10 +298,10 @@ class Song(DatabaseObject): self.metadata[ID3_MAPPING.FILE_WEBPAGE_URL.value] = source_obj.url def set_sources(self, source_list): - self.metadata.delete_item(ID3_MAPPING.FILE_WEBPAGE_URL.value) - self._sources = [] - for source in source_list: - self.add_source(source) + self._sources = source_list + for source in self._sources: + source.add_song(self) + self.metadata[ID3_MAPPING.FILE_WEBPAGE_URL.value] = [s.url for s in self._sources] def get_metadata(self): return self.metadata.get_all_metadata() diff --git a/test.db b/test.db index e482c537c25c085cafbdf99cbb5f6a3ba6697681..232709a98dc44bad6bde174c4cbb0ecb2f30f35d 100644 GIT binary patch delta 2340 zcmc&#&ubl36rT4cFD8O-@-~)Yu|XbfAw6(^|A1mD2rk-y5@zE@?!9wwQ(BThUZHd| z5wr_;GIZlA3m5L9?|}>WVV8ai)&jwc4!;@Z z95g@vs%mq3EpL_eAg9;i&9YwqPuPh1t)eJ~)ugBv>ts?*xwqUnA;2XnK~SH-*+3yE zW`x#CA!XhB+c!VSsr>}`d*|NTdQC)Z0yPPeM`lFiSYIiNTH45!r%q_q{kVN&np1Ut zcTw%+;9PQ$bM*YFpuBTSXw)$#igt{ z(3fZyqvJ3C&)F)+zxT6s@^U77;+8&oh1 zsE(L=5tGJSd@_VELye75=~+CQ#r+&n4p8i!Nlg`%GDQbmFb};?FutUP7?^I*k=|P~ z+lxnWvpYM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