From 0f459d3216d7d546e5df249f0a83bdd5a543c403 Mon Sep 17 00:00:00 2001 From: tsi-billypom Date: Thu, 17 Apr 2025 16:41:55 -0400 Subject: [PATCH] auto --- components/MusicTable.py | 77 ++++++++++++++++++++++------------------ utils/get_id3_tags.py | 29 ++++++++------- utils/set_id3_tag.py | 2 +- 3 files changed, 61 insertions(+), 47 deletions(-) diff --git a/components/MusicTable.py b/components/MusicTable.py index 1e76a6a..11b3cc0 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -62,6 +62,43 @@ from appdirs import user_config_dir from configparser import ConfigParser +class TableHeader: + def __init__(self): + self.db = { + "title": "title", + "artist": "artist", + "album": "album", + "track_number": "track_number", + "genre": "genre", + "codec": "codec", + "length_seconds": "length_seconds", + "album_date": "album_date", + "filepath": "filepath", + } + self.gui = { + "title": "Title", + "artist": "Artist", + "album": "Album", + "track_number": "Track", + "genre": "Genre", + "codec": "Codec", + "length_seconds": "Length", + "album_date": "Year", + "filepath": "Path", + } + self.id3 = { + "title": "TIT2", + "artist": "TPE1", + "album": "TALB", + "track_number": "TRCK", + "genre": "content_type", + "codec": None, + "length_seconds": "TLEN", + "album_date": "TDRC", + "filepath": None, + } + + class MusicTable(QTableView): playlistStatsSignal = pyqtSignal(str) playPauseSignal = pyqtSignal() @@ -103,28 +140,9 @@ class MusicTable(QTableView): # Threads self.threadpool = QThreadPool - # gui names of headers - self.table_headers = [ - "title", - "artist", - "album", - "track", - "genre", - "codec", - "year", - "path", - ] - # id3 names of headers - self.id3_headers = [ - "TIT2", - "TPE1", - "TALB", - "TRCK", - "content_type", - None, - "TDRC", - None, - ] + # headers class thing + self.headers = TableHeader() + # db names of headers self.database_columns = str(self.config["table"]["columns"]).split(",") self.vertical_scroll_position = 0 @@ -582,17 +600,8 @@ class MusicTable(QTableView): selected_song_filepath = self.get_selected_song_filepath() if selected_song_filepath is None: return - # current_song = self.get_selected_song_metadata() - current_song = get_id3_tags(selected_song_filepath)[0] - try: - uslt_tags = [tag for tag in current_song.keys() if tag.startswith("USLT::")] - if uslt_tags: - lyrics = next((current_song[tag].text for tag in uslt_tags), "") - else: - raise RuntimeError("No USLT tags found in song metadata") - except Exception as e: - error(f"show_lyrics_menu() | could not retrieve lyrics | {e}") - lyrics = "" + dic = id3_remap(get_id3_tags(selected_song_filepath)[0]) + lyrics = dic["lyrics"] lyrics_window = LyricsWindow(selected_song_filepath, lyrics) lyrics_window.exec_() @@ -687,7 +696,7 @@ class MusicTable(QTableView): self.disconnect_layout_changed() self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore self.model2.clear() - self.model2.setHorizontalHeaderLabels(self.table_headers) + self.model2.setHorizontalHeaderLabels(self.headers.gui.values()) if playlist_id: # Load a playlist # Fetch playlist data selected_playlist_id = playlist_id[0] diff --git a/utils/get_id3_tags.py b/utils/get_id3_tags.py index 7dabc03..59e04f2 100644 --- a/utils/get_id3_tags.py +++ b/utils/get_id3_tags.py @@ -37,20 +37,25 @@ def get_mp3_tags(filename: str) -> tuple[MP3 | ID3 | FLAC, str]: def id3_remap(audio: MP3 | ID3 | FLAC) -> dict: """ Turns an ID3 dict into a normal dict that I, the human, can use. - Add extra fields as well + Add extra fields too :D yahooo """ - remap = { - "title": audio.get("TIT2"), - "artist": audio.get("TPE1"), - "album": audio.get("TALB"), - "track_number": audio.get("TRCK"), - "genre": audio.get("TCON"), - "date": convert_id3_timestamp_to_datetime(audio.get("TDRC")), - "bitrate": audio.get("TBIT"), - "lyrics": audio.get("USLT"), - } + remap = {} if isinstance(audio, MP3): - remap["length"] = int(round(audio.info.length, 0)) + # so ugly + uslt_tags = [tag for tag in audio.keys() if tag.startswith("USLT::")] + lyrics = next((audio[tag].text for tag in uslt_tags), "") + # so ugly + remap = { + "title": audio.get("TIT2"), + "artist": audio.get("TPE1"), + "album": audio.get("TALB"), + "track_number": audio.get("TRCK"), + "genre": audio.get("TCON"), + "date": convert_id3_timestamp_to_datetime(audio.get("TDRC")), + "bitrate": audio.get("TBIT"), + "lyrics": lyrics, + "length": int(round(audio.info.length, 0)), + } return remap diff --git a/utils/set_id3_tag.py b/utils/set_id3_tag.py index 49fafa0..96f7df3 100644 --- a/utils/set_id3_tag.py +++ b/utils/set_id3_tag.py @@ -54,7 +54,7 @@ mutagen_id3_tag_mapping = { # "year": TYER, # Year of recording # "date": TDAT, # Date "lyrics": USLT, # Unsynchronized lyric/text transcription - "track_number": TRCK, # Track number/Position in set + "track": TRCK, # Track number/Position in set "album_cover": APIC, # Attached picture "composer": TCOM, # Composer "conductor": TPE3, # Conductor/performer refinement