From fda000646d1dd499dd503d4a41a58c30b2d4f3fd Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 16 Jan 2023 12:26:56 +0100 Subject: [PATCH] date support --- src/music_kraken/database/new_database.py | 3 +- src/music_kraken/database/objects/metadata.py | 71 +++++++++++++----- test.db | Bin 69632 -> 69632 bytes 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/music_kraken/database/new_database.py b/src/music_kraken/database/new_database.py index 7df0cce..a0888fe 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -14,7 +14,8 @@ from .objects import ( Metadata, Target, Artist, - Album + Album, + ID3Timestamp ) diff --git a/src/music_kraken/database/objects/metadata.py b/src/music_kraken/database/objects/metadata.py index b764be2..e452c21 100644 --- a/src/music_kraken/database/objects/metadata.py +++ b/src/music_kraken/database/objects/metadata.py @@ -100,7 +100,7 @@ class Mapping(Enum): return cls.get_url_instance(key, value) -class ID3Timestamp(): +class ID3Timestamp: def __init__( self, year: int = None, @@ -108,18 +108,21 @@ class ID3Timestamp(): day: int = None, hour: int = None, minute: int = None, - second: int = None, - microsecond=0, - tzinfo=None, - fold=0 + second: int = None ): + self.year = year + self.month = month + self.day = day + self.hour = hour + self.minute = minute + self.second = second + self.has_year = year is not None self.has_month = month is not None self.has_day = day is not None self.has_hour = hour is not None self.has_minute = minute is not None self.has_second = second is not None - self.has_microsecond = microsecond is not None if not self.has_year: year = 1 @@ -127,19 +130,20 @@ class ID3Timestamp(): month = 1 if not self.has_day: day = 1 + if not self.has_hour: + hour = 1 + if not self.has_minute: + minute = 1 + if not self.has_second: + second = 1 - # https://stackoverflow.com/questions/399022/why-cant-i-subclass-datetime-date - super().__new__( - cls=type(self), + self.date_obj = datetime.datetime( year=year, month=month, day=day, hour=hour, minute=minute, - second=second, - microsecond=microsecond, - tzinfo=tzinfo, - fold=fold + second=second ) def get_timestamp(self) -> str: @@ -165,19 +169,48 @@ class ID3Timestamp(): """ if self.has_year and self.has_month and self.has_day and self.has_hour and self.has_minute and self.has_second: - return self.strftime("%Y-%m-%dT%H:%M:%S") + return self.date_obj.strftime("%Y-%m-%dT%H:%M:%S") if self.has_year and self.has_month and self.has_day and self.has_hour and self.has_minute: - return self.strftime("%Y-%m-%dT%H:%M") + return self.date_obj.strftime("%Y-%m-%dT%H:%M") if self.has_year and self.has_month and self.has_day and self.has_hour: - return self.strftime("%Y-%m-%dT%H") + return self.date_obj.strftime("%Y-%m-%dT%H") if self.has_year and self.has_month and self.has_day: - return self.strftime("%Y-%m-%d") + return self.date_obj.strftime("%Y-%m-%d") if self.has_year and self.has_month: - return self.strftime("%Y-%m") + return self.date_obj.strftime("%Y-%m") if self.has_year: - return self.strftime("%Y") + return self.date_obj.strftime("%Y") return "" + @classmethod + def strptime(cls, time_stamp: str, format: str): + date_obj = datetime.datetime.strftime(time_stamp, format) + + return cls( + year=date_obj.year, + month=date_obj.month, + day=date_obj.day, + hour=date_obj.hour, + minute=date_obj.minute, + second=date_obj.second + ) + + @classmethod + def now(cls): + date_obj = datetime.datetime.now() + + return cls( + year=date_obj.year, + month=date_obj.month, + day=date_obj.day, + hour=date_obj.hour, + minute=date_obj.minute, + second=date_obj.second + ) + + def strftime(self, format: str) -> str: + return self.date_obj.strftime(format) + def __str__(self) -> str: return self.timestamp diff --git a/test.db b/test.db index b3393308953ba9f3a1cdef97ba963903b2495829..643f7f6c661b6f8cb10740995e488456f8415c71 100644 GIT binary patch delta 2514 zcmd5;O>10L7``);n`AOcZll!rg&AwGh4{kx{s1)=Azh@UiriHxc)o5L8z;e;fG9ZK zn3W6Vg5WL^7lKGI1FriE?8ZeGUAT2qbl0V4#!Vv)9(OJ-mwP$)InVn%@AIB}=Wy!I z;nbHOTzHr*ep}pIXe|yp{rUTIo1Kl$bL}g0FU@}6etzbQ=^yilqos2;AN`si8TTh0-zDK@|`((wZ#!B$#< z)|JI^y^zFw(wHgN*P4woNXezO1~5e;ZmuX8Y$#|<5XL;9mbAY9X=RP1z|Lh^)+!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