This commit is contained in:
Hellow 2023-01-14 14:41:40 +01:00
parent d9925aea53
commit cf300a2a91
7 changed files with 34 additions and 18 deletions

View File

@ -5,7 +5,8 @@ from music_kraken import (
Target, Target,
Source, Source,
Album, Album,
Artist Artist,
ID3Timestamp
) )
from music_kraken.tagging import ( from music_kraken.tagging import (
@ -16,7 +17,6 @@ from music_kraken.tagging import (
import music_kraken.database.new_database as db import music_kraken.database.new_database as db
import datetime
import pycountry import pycountry
@ -43,7 +43,7 @@ feature_artist = Artist(
album_input = Album( album_input = Album(
title="One Final Action", title="One Final Action",
date=datetime.date(1986, 3, 1), date=ID3Timestamp(year=1986, month=3, day=1),
language=pycountry.languages.get(alpha_2="en"), language=pycountry.languages.get(alpha_2="en"),
label="cum productions" label="cum productions"
) )

View File

@ -44,6 +44,7 @@ Source = database.Source
Target = database.Target Target = database.Target
Lyrics = database.Lyrics Lyrics = database.Lyrics
Album = database.Album Album = database.Album
ID3Timestamp = database.ID3Timestamp
MetadataSearch = metadata.MetadataSearch MetadataSearch = metadata.MetadataSearch
MetadataDownload = metadata.MetadataDownload MetadataDownload = metadata.MetadataDownload

View File

@ -3,6 +3,7 @@ from . import (
objects objects
) )
ID3Timestamp = objects.ID3Timestamp
Song = objects.Song Song = objects.Song
Source = objects.Source Source = objects.Source
Target = objects.Target Target = objects.Target

View File

@ -5,6 +5,7 @@ from . import (
) )
ID3_MAPPING = metadata.Mapping ID3_MAPPING = metadata.Mapping
ID3Timestamp = metadata.ID3Timestamp
Song = song.Song Song = song.Song
Artist = song.Artist Artist = song.Artist

View File

@ -1,5 +1,7 @@
from enum import Enum from enum import Enum
from typing import List, Dict, Tuple from typing import List, Dict, Tuple
import dateutil.tz
from mutagen import id3 from mutagen import id3
import datetime import datetime
@ -98,7 +100,7 @@ class Mapping(Enum):
return cls.get_url_instance(key, value) return cls.get_url_instance(key, value)
class ID3Timestamp(datetime.datetime): class ID3Timestamp():
def __init__( def __init__(
self, self,
year: int = None, year: int = None,
@ -109,7 +111,6 @@ class ID3Timestamp(datetime.datetime):
second: int = None, second: int = None,
microsecond=0, microsecond=0,
tzinfo=None, tzinfo=None,
*,
fold=0 fold=0
): ):
self.has_year = year is not None self.has_year = year is not None
@ -126,7 +127,10 @@ class ID3Timestamp(datetime.datetime):
month = 1 month = 1
if not self.has_day: if not self.has_day:
day = 1 day = 1
super().__init__(
# https://stackoverflow.com/questions/399022/why-cant-i-subclass-datetime-date
super().__new__(
cls=type(self),
year=year, year=year,
month=month, month=month,
day=day, day=day,
@ -188,15 +192,8 @@ class Metadata:
Shall only be read or edited via the Song object. Shall only be read or edited via the Song object.
call it like a dict to read/write values call it like a dict to read/write values
""" """
class FrameValue:
def __init__(self, values: list, modified_by: str) -> None:
"""
Parameters:
values (list): the values.
"""
pass
def __init__(self, data: dict = {}) -> None: def __init__(self) -> None:
# this is pretty self-explanatory # this is pretty self-explanatory
# the key is a 4 letter key from the id3 standards like TITL # the key is a 4 letter key from the id3 standards like TITL
@ -251,6 +248,16 @@ class Metadata:
list_data = self.id3_attributes[key] list_data = self.id3_attributes[key]
# convert for example the time objects to timestamps
for i, element in enumerate(list_data):
# for performances sake I don't do other checks if it is already the right type
if type(element) == str:
continue
if type(element) == ID3Timestamp:
list_data[i] = element.timestamp
continue
""" """
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. 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 concatenate the list, Thus if above conditions are met, I concatenate the list,
@ -265,6 +272,9 @@ class Metadata:
return Mapping.get_mutagen_instance(Mapping(key), self.get_id3_value(key)) return Mapping.get_mutagen_instance(Mapping(key), self.get_id3_value(key))
def __iter__(self): def __iter__(self):
# set the tagging timestamp to the current time
self.__setitem__(Mapping.TAGGING_TIME.value, [ID3Timestamp.now()])
for key in self.id3_attributes: for key in self.id3_attributes:
yield key, self.get_mutagen_object(key) yield key, self.get_mutagen_object(key)

View File

@ -5,7 +5,8 @@ import pycountry
from .metadata import ( from .metadata import (
Mapping as ID3_MAPPING, Mapping as ID3_MAPPING,
Metadata Metadata,
ID3Timestamp
) )
from ...utils.shared import ( from ...utils.shared import (
MUSIC_DIR, MUSIC_DIR,
@ -282,7 +283,7 @@ class Album(DatabaseObject, ID3Metadata):
label: str = None, label: str = None,
album_status: str = None, album_status: str = None,
language: pycountry.Languages = None, language: pycountry.Languages = None,
date: datetime.date = None, date: ID3Timestamp = None,
country: str = None, country: str = None,
barcode: str = None, barcode: str = None,
is_split: bool = False, is_split: bool = False,
@ -294,11 +295,12 @@ class Album(DatabaseObject, ID3Metadata):
self.album_status: str = album_status self.album_status: str = album_status
self.label = label self.label = label
self.language: pycountry.Languages = language self.language: pycountry.Languages = language
self.date: datetime.date = date self.date: ID3Timestamp = date
self.country: str = country self.country: str = country
""" """
TODO TODO
find out the id3 tag for barcode and implement it find out the id3 tag for barcode and implement it
maybee look at how mutagen does it with easy_id3
""" """
self.barcode: str = barcode self.barcode: str = barcode
self.is_split: bool = is_split self.is_split: bool = is_split
@ -335,7 +337,8 @@ class Album(DatabaseObject, ID3Metadata):
ID3_MAPPING.ALBUM: [self.title], ID3_MAPPING.ALBUM: [self.title],
ID3_MAPPING.COPYRIGHT: [self.copyright], ID3_MAPPING.COPYRIGHT: [self.copyright],
ID3_MAPPING.LANGUAGE: [self.iso_639_2_language], ID3_MAPPING.LANGUAGE: [self.iso_639_2_language],
ID3_MAPPING.ALBUM_ARTIST: [a.name for a in self.artists] ID3_MAPPING.ALBUM_ARTIST: [a.name for a in self.artists],
ID3_MAPPING.DATE: [self.date.timestamp]
} }
def get_copyright(self) -> str: def get_copyright(self) -> str:

Binary file not shown.