fixed issue with date formats and the database
This commit is contained in:
parent
65ccdee2cb
commit
ae9a70fb04
@ -44,12 +44,12 @@ FROM Lyrics
|
|||||||
WHERE {where};
|
WHERE {where};
|
||||||
"""
|
"""
|
||||||
ALBUM_QUERY_UNJOINED = """
|
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
|
FROM Album
|
||||||
WHERE {where};
|
WHERE {where};
|
||||||
"""
|
"""
|
||||||
ALBUM_QUERY_JOINED = """
|
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
|
FROM Song
|
||||||
INNER JOIN Album a ON Song.album_id=a.id
|
INNER JOIN Album a ON Song.album_id=a.id
|
||||||
WHERE {where};
|
WHERE {where};
|
||||||
@ -136,7 +136,9 @@ class Database:
|
|||||||
|
|
||||||
def push_album(self, album: Album):
|
def push_album(self, album: Album):
|
||||||
table = "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 = (
|
values = (
|
||||||
album.id,
|
album.id,
|
||||||
@ -144,7 +146,8 @@ class Database:
|
|||||||
album.label,
|
album.label,
|
||||||
album.album_status,
|
album.album_status,
|
||||||
album.iso_639_2_language,
|
album.iso_639_2_language,
|
||||||
album.date.strftime("%Y-%m-%d"),
|
date,
|
||||||
|
date_format,
|
||||||
album.country,
|
album.country,
|
||||||
album.barcode,
|
album.barcode,
|
||||||
album.albumsort,
|
album.albumsort,
|
||||||
@ -583,7 +586,7 @@ class Database:
|
|||||||
label=album_result['label'],
|
label=album_result['label'],
|
||||||
album_status=album_result['album_status'],
|
album_status=album_result['album_status'],
|
||||||
language=language,
|
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'],
|
country=album_result['country'],
|
||||||
barcode=album_result['barcode'],
|
barcode=album_result['barcode'],
|
||||||
is_split=album_result['is_split'],
|
is_split=album_result['is_split'],
|
||||||
|
@ -142,7 +142,7 @@ class ID3Timestamp:
|
|||||||
second=second
|
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
|
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:
|
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:
|
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:
|
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:
|
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:
|
if self.has_year and self.has_month:
|
||||||
return self.date_obj.strftime("%Y-%m")
|
return "%Y-%m"
|
||||||
if self.has_year:
|
if self.has_year:
|
||||||
return self.date_obj.strftime("%Y")
|
return "%Y"
|
||||||
return ""
|
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
|
@classmethod
|
||||||
def strptime(cls, time_stamp: str, format: str):
|
def strptime(cls, time_stamp: str, format: str):
|
||||||
"""
|
"""
|
||||||
|
@ -269,6 +269,8 @@ class Album(DatabaseObject, SourceAttribute, MetadataAttribute):
|
|||||||
self.label = label
|
self.label = label
|
||||||
self.language: pycountry.Languages = language
|
self.language: pycountry.Languages = language
|
||||||
self.date: ID3Timestamp = date
|
self.date: ID3Timestamp = date
|
||||||
|
if date is None:
|
||||||
|
self.date = ID3Timestamp()
|
||||||
self.country: str = country
|
self.country: str = country
|
||||||
"""
|
"""
|
||||||
TODO
|
TODO
|
||||||
|
@ -32,6 +32,7 @@ CREATE TABLE Album
|
|||||||
album_status TEXT,
|
album_status TEXT,
|
||||||
language TEXT,
|
language TEXT,
|
||||||
date TEXT,
|
date TEXT,
|
||||||
|
date_format TEXT,
|
||||||
country TEXT,
|
country TEXT,
|
||||||
barcode TEXT,
|
barcode TEXT,
|
||||||
albumsort INT,
|
albumsort INT,
|
||||||
|
Loading…
Reference in New Issue
Block a user