diff --git a/src/music_kraken/database/database.py b/src/music_kraken/database/database.py index ddc211b..8cbe196 100644 --- a/src/music_kraken/database/database.py +++ b/src/music_kraken/database/database.py @@ -44,12 +44,12 @@ FROM Lyrics WHERE {where}; """ ALBUM_QUERY_UNJOINED = """ -SELECT Album.id AS album_id, title, label, album_status, language, date, country, barcode, albumsort, is_split +SELECT Album.id AS album_id, title, label, album_status, language, date, date_format, country, barcode, albumsort, is_split FROM Album WHERE {where}; """ ALBUM_QUERY_JOINED = """ -SELECT a.id AS album_id, a.title, a.label, a.album_status, a.language, a.date, a.country, a.barcode, a.albumsort, a.is_split +SELECT a.id AS album_id, a.title, a.label, a.album_status, a.language, a.date, a.date_format, a.country, a.barcode, a.albumsort, a.is_split FROM Song INNER JOIN Album a ON Song.album_id=a.id WHERE {where}; @@ -136,7 +136,9 @@ class Database: def push_album(self, album: Album): table = "Album" - query = f"INSERT OR REPLACE INTO {table} (id, title, label, album_status, language, date, country, barcode, albumsort, is_split) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" + query = f"INSERT OR REPLACE INTO {table} (id, title, label, album_status, language, date, date_format, country, barcode, albumsort, is_split) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" + + date_format, date = album.date.get_timestamp_w_format() values = ( album.id, @@ -144,7 +146,8 @@ class Database: album.label, album.album_status, album.iso_639_2_language, - album.date.strftime("%Y-%m-%d"), + date, + date_format, album.country, album.barcode, album.albumsort, @@ -583,7 +586,7 @@ class Database: label=album_result['label'], album_status=album_result['album_status'], language=language, - date=ID3Timestamp.strptime(album_result['date'], "%Y-%m-%d"), + date=ID3Timestamp.strptime(album_result['date'], album_result['date_format']), country=album_result['country'], barcode=album_result['barcode'], is_split=album_result['is_split'], diff --git a/src/music_kraken/database/objects/metadata.py b/src/music_kraken/database/objects/metadata.py index 5ffe146..c14ed85 100644 --- a/src/music_kraken/database/objects/metadata.py +++ b/src/music_kraken/database/objects/metadata.py @@ -142,7 +142,7 @@ class ID3Timestamp: second=second ) - def get_timestamp(self) -> str: + def get_time_format(self) -> str: """ https://mutagen-specs.readthedocs.io/en/latest/id3/id3v2.4.0-structure.html @@ -165,19 +165,30 @@ 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.date_obj.strftime("%Y-%m-%dT%H:%M:%S") + return "%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.date_obj.strftime("%Y-%m-%dT%H:%M") + return "%Y-%m-%dT%H:%M" if self.has_year and self.has_month and self.has_day and self.has_hour: - return self.date_obj.strftime("%Y-%m-%dT%H") + return "%Y-%m-%dT%H" if self.has_year and self.has_month and self.has_day: - return self.date_obj.strftime("%Y-%m-%d") + return "%Y-%m-%d" if self.has_year and self.has_month: - return self.date_obj.strftime("%Y-%m") + return "%Y-%m" if self.has_year: - return self.date_obj.strftime("%Y") + return "%Y" return "" + + def get_timestamp(self) -> str: + time_format = self.get_time_format() + return self.date_obj.strftime(time_format) + + + def get_timestamp_w_format(self) -> Tuple[str, str]: + time_format = self.get_time_format() + return time_format, self.date_obj.strftime(time_format) + + @classmethod def strptime(cls, time_stamp: str, format: str): """ diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index c2a7166..1feb08e 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -269,6 +269,8 @@ class Album(DatabaseObject, SourceAttribute, MetadataAttribute): self.label = label self.language: pycountry.Languages = language self.date: ID3Timestamp = date + if date is None: + self.date = ID3Timestamp() self.country: str = country """ TODO diff --git a/src/music_kraken/static_files/new_db.sql b/src/music_kraken/static_files/new_db.sql index 7210dc0..fd9cd0d 100644 --- a/src/music_kraken/static_files/new_db.sql +++ b/src/music_kraken/static_files/new_db.sql @@ -32,6 +32,7 @@ CREATE TABLE Album album_status TEXT, language TEXT, date TEXT, + date_format TEXT, country TEXT, barcode TEXT, albumsort INT, diff --git a/test.db b/test.db index 5d18970..f30bb96 100644 Binary files a/test.db and b/test.db differ