datetime fix for yyyymmdd format

This commit is contained in:
billypom on debian 2024-12-13 19:26:27 -05:00
parent 773b4a8a46
commit 5d6c85387d
3 changed files with 9 additions and 5 deletions

View File

@ -287,9 +287,10 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
self.permanent_status_label.setText(message) self.permanent_status_label.setText(message)
def play_audio_file(self) -> None: def play_audio_file(self) -> None:
"""Start playback of tableView.current_song_filepath track & moves playback slider""" """Start playback of `tableView.current_song_filepath` & moves playback slider"""
# get metadata # get metadata
self.current_song_metadata = self.tableView.get_current_song_metadata() self.current_song_metadata = self.tableView.get_current_song_metadata()
print(f'current_song_metadata: {self.current_song_metadata}')
# read the file # read the file
url = QUrl.fromLocalFile(self.tableView.get_current_song_filepath()) url = QUrl.fromLocalFile(self.tableView.get_current_song_filepath())
# load the audio content # load the audio content
@ -300,7 +301,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
self.move_slider() # mover self.move_slider() # mover
# self.player.setPlaybackRate(1.5) # self.player.setPlaybackRate(1.5)
# assign metadata # assign "now playing" labels & album artwork
if self.current_song_metadata is not None: if self.current_song_metadata is not None:
artist = ( artist = (
self.current_song_metadata["TPE1"][0] self.current_song_metadata["TPE1"][0]
@ -313,7 +314,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
else None else None
) )
title = self.current_song_metadata["TIT2"][0] title = self.current_song_metadata["TIT2"][0]
# edit labels
self.artistLabel.setText(artist) self.artistLabel.setText(artist)
self.albumLabel.setText(album) self.albumLabel.setText(album)
self.titleLabel.setText(title) self.titleLabel.setText(title)

View File

@ -7,5 +7,8 @@ def id3_timestamp_to_datetime(timestamp: ID3TimeStamp):
if len(timestamp.text) == 4: # If only year is provided if len(timestamp.text) == 4: # If only year is provided
datetime_obj = datetime.datetime.strptime(timestamp.text, '%Y') datetime_obj = datetime.datetime.strptime(timestamp.text, '%Y')
else: else:
try:
datetime_obj = datetime.datetime.strptime(timestamp.text, '%Y-%m-%d') datetime_obj = datetime.datetime.strptime(timestamp.text, '%Y-%m-%d')
except ValueError:
datetime_obj = datetime.datetime.strptime(timestamp.text, '%Y%m%d')
return datetime_obj.strftime('%Y-%m-%d') return datetime_obj.strftime('%Y-%m-%d')

View File

@ -136,6 +136,6 @@ def set_id3_tag(filepath: str, tag_name: str, value: str):
audio_file.save(filepath) audio_file.save(filepath)
return True return True
except Exception as e: except Exception as e:
dialog = ErrorDialog(f"An unhandled exception occurred:\n{e}") dialog = ErrorDialog(f"set_id3_tag.py | An unhandled exception occurred:\n{e}")
dialog.exec_() dialog.exec_()
return False return False