From a00cbb0d0cc1d5599cf3a2dddad54c6b78cefb41 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 12 Jan 2023 17:14:21 +0100 Subject: [PATCH] dfsa --- src/music_kraken/database/new_database.py | 2 +- .../database/objects/id3_mapping.py | 27 ++++++++++------- src/music_kraken/database/objects/parents.py | 7 +++++ src/music_kraken/database/objects/song.py | 28 +++++++++++++----- src/music_kraken/database/objects/source.py | 13 ++++++-- test.db | Bin 69632 -> 69632 bytes 6 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/music_kraken/database/new_database.py b/src/music_kraken/database/new_database.py index b830bd8..bc9a14a 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -222,7 +222,7 @@ class Database: values = ( source.id, source.song_ref_id, - source.src, + source.type_str, source.url ) diff --git a/src/music_kraken/database/objects/id3_mapping.py b/src/music_kraken/database/objects/id3_mapping.py index 9f651b3..d5da52e 100644 --- a/src/music_kraken/database/objects/id3_mapping.py +++ b/src/music_kraken/database/objects/id3_mapping.py @@ -1,11 +1,14 @@ from enum import Enum class Mapping(Enum): + """ + These frames belong to the id3 standart + """ + # Textframes TITLE = "TIT2" ISRC = "TSRC" LENGTH = "TLEN" DATE = "TYER" - UNSYNCED_LYRICS = "USLT" TRACKNUMBER = "TRCK" TOTALTRACKS = "TRCK" # Stored in the same frame with TRACKNUMBER, separated by '/': e.g. '4/9'. TITLESORTORDER = "TSOT" @@ -24,12 +27,6 @@ class Mapping(Enum): ORIGINAL_RELEASE_DATE = "TDOR" ORIGINAL_ARTIST = "TOPE" ORIGINAL_ALBUM = "TOAL" - INTERNET_RADIO_WEBPAGE_URL = "WORS" - SOURCE_WEBPAGE_URL = "WOAS" - FILE_WEBPAGE_URL = "WOAF" - ARTIST_WEBPAGE_URL = "WOAR" - MOVEMENT_INDEX = "MVIN" - MOVEMENT_NAME = "MVNM" MEDIA_TYPE = "TMED" LYRICIST = "TEXT" WRITER = "TEXT" @@ -42,15 +39,12 @@ class Mapping(Enum): INITIAL_KEY = "TKEY" OWNER = "TOWN" ENCODED_BY = "TENC" - COPYRIGHT_URL = "WCOP" COPYRIGHT = "TCOP" GENRE = "TCON" GROUPING = "TIT1" CONDUCTOR = "TPE3" COMPOSERSORTORDER = "TSOC" COMPOSER = "TCOM" - COMMERCIAL_INFORMATION_URL = "WCOM" - COMMENT = "COMM" BPM = "TBPM" ALBUM_ARTIST = "TPE2" BAND = "TPE2" @@ -58,4 +52,17 @@ class Mapping(Enum): ALBUM = "TALB" ALBUMSORTORDER = "TSOA" ALBUMARTISTSORTORDER = "TSO2" + + SOURCE_WEBPAGE_URL = "WOAS" + FILE_WEBPAGE_URL = "WOAF" + INTERNET_RADIO_WEBPAGE_URL = "WORS" + ARTIST_WEBPAGE_URL = "WOAR" + COPYRIGHT_URL = "WCOP" + COMMERCIAL_INFORMATION_URL = "WCOM" + + MOVEMENT_INDEX = "MVIN" + MOVEMENT_NAME = "MVNM" + + UNSYNCED_LYRICS = "USLT" + COMMENT = "COMM" \ No newline at end of file diff --git a/src/music_kraken/database/objects/parents.py b/src/music_kraken/database/objects/parents.py index 6e104d8..d5d4e92 100644 --- a/src/music_kraken/database/objects/parents.py +++ b/src/music_kraken/database/objects/parents.py @@ -64,3 +64,10 @@ class SongAttribute: self.song_ref = Reference(song_id) song_ref_id = property(fget=get_ref_song_id, fset=set_ref_song_id) + + +class ID3Metadata: + def get_id3_dict(self) -> dict: + return {} + + id3_dict: dict = property(fget=get_id3_dict) diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index 0cb0c62..49e3b69 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -10,7 +10,8 @@ from ...utils.shared import ( from .parents import ( DatabaseObject, Reference, - SongAttribute + SongAttribute, + ID3Metadata ) from .source import Source @@ -19,9 +20,6 @@ All Objects dependent """ - - - class Metadata: """ Shall only be read or edited via the Song object. @@ -39,20 +37,35 @@ class Metadata: def get_all_metadata(self): return list(self.id3_attributes.items()) - def __setitem__(self, key: str, value: list): + def __setitem__(self, key: str, value: list, override_existing: bool = True): 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[0], "HHHHSSSS"] - self.id3_attributes[key] = value[0] + if override_existing: + self.id3_attributes[key] = value + else: + if key not in self.id3_attributes: + self.id3_attributes[key] = value + return + self.id3_attributes[key].extend(value) def __getitem__(self, key): if key not in self.id3_attributes: return None return self.id3_attributes[key] + def add_id3_metadata_obj(self, id3_metadata: ID3Metadata, override_existing: bool = True): + metadata_dict = id3_metadata.get_id3_dict() + for field_enum, value in metadata_dict.items(): + self.__setitem__(field_enum.value, value, override_existing=override_existing) + + def add_many_id3_metadata_obj(self, id3_metadata_list: List[ID3Metadata], override_existing: bool = False): + for id3_metadata in id3_metadata_list: + self.add_id3_metadata_obj(id3_metadata, override_existing=override_existing) + def delete_item(self, key: str): if key in self.id3_attributes: return self.id3_attributes.pop(key) @@ -273,7 +286,8 @@ class Song(DatabaseObject): for source in self._sources: source.add_song(self) - self.metadata[ID3_MAPPING.FILE_WEBPAGE_URL.value] = [s.url for s in self._sources] + # self.metadata[ID3_MAPPING.FILE_WEBPAGE_URL.value] = [s.url for s in self._sources] + self.metadata.add_many_id3_metadata_obj(self._sources) def get_metadata(self): return self.metadata.get_all_metadata() diff --git a/src/music_kraken/database/objects/source.py b/src/music_kraken/database/objects/source.py index 75cc89c..3d84a3c 100644 --- a/src/music_kraken/database/objects/source.py +++ b/src/music_kraken/database/objects/source.py @@ -1,8 +1,10 @@ from enum import Enum +from .id3_mapping import Mapping from .parents import ( DatabaseObject, - SongAttribute + SongAttribute, + ID3Metadata ) class sources(Enum): @@ -19,7 +21,7 @@ class sources(Enum): -class Source(DatabaseObject, SongAttribute): +class Source(DatabaseObject, SongAttribute, ID3Metadata): """ create somehow like that ```python @@ -35,7 +37,14 @@ class Source(DatabaseObject, SongAttribute): self.src = sources(src) self.url = url + def get_id3_dict(self) -> dict: + return { + Mapping.FILE_WEBPAGE_URL: [self.url], + Mapping.SOURCE_WEBPAGE_URL: [self.homepage] + } + def __str__(self): return f"{self.src}: {self.url}" + type_str = property(fget=lambda self: self.src.value) homepage = property(fget=lambda self: sources.get_homepage(self.src)) diff --git a/test.db b/test.db index 10a5c2dce2bbeb2a8a8796264d305fffdbbfc5c0..820065b8d300fefe3c45a99256d04ff67481acb2 100644 GIT binary patch literal 69632 zcmeI*%X8bt9S3ke^tLV7lW{qoUe=SD+8TQ;fW$M8CUQcjs%0s$$j0d;)hu=w5@HHe z0ML!vrX4GZXL@N5z2(-)AK;nx-g9of^x)~Ke?w2bwF`ihNIQ1Xq@7C17bB4%p1=L< z0w8zs*nDd(OeG2W@h(eAt8%tdtyW$oq*AF|RR8DH|EQZ+JyW9(>b*MF|FqtVm1}SR z@Qn74%Gv3^R2F}){rOCNF+KIp=|>C3sjCbBoTm#@bHACd%*HdnQxl+r00bZafv+WS z|E06Djpv@L9&Dw|@5xZK)Ze++ZnsxDZPHn}zSbscz{2GPqPievyE5xhU8jAgbG7It zloFG0wil+XM|v`qaYB0GT}e83?%c`eyvKTji8=G3Nk7`&3Prw@>#J|9u6M5H!*6Wd zZm+(vPHwi}xjdX^iQI1AXy0zHzt-L)n`*wxp;%g2y8o^=+j#!@>cOw_@K<{NV0R@> z!z3N+Jv)({u@S>$5yG!QoSmb<> z>G|uK36cVA$T2KzBZif3XJc!1T}^+hz1|^j-d?@6a{HaE+!bkvhUGmg>-rm$Jz*`;x_@*e1sarhY?=bw}&r{Xvw*`-kI>#`rAe zeQ`9~(U?58q#qBXK0Jh|eO0ojw$RbSp1!wQSX!EyX}sKc>UNzU8;l%(_8_X~CHhk* z&#BG+Am*}ootnt2V%V2tR>_P?Vm=BzFUNBjMB_fksQuEwvSe0 z)M5K@!k2YIzfY7`m=Ga@Fj70W-acVO9l6y`GszR0my=>ZvG%8`8bz4n$DShL|M5mQ z^{nlvP~I|%_vwQx)!D}R^VLth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