This commit is contained in:
Lars Noack 2023-01-12 17:14:21 +01:00
parent 133e360562
commit a00cbb0d0c
6 changed files with 57 additions and 20 deletions

View File

@ -222,7 +222,7 @@ class Database:
values = (
source.id,
source.song_ref_id,
source.src,
source.type_str,
source.url
)

View File

@ -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"
@ -59,3 +53,16 @@ class Mapping(Enum):
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"

View File

@ -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)

View File

@ -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()

View File

@ -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))

BIN
test.db

Binary file not shown.