diff --git a/components/DebugWindow.py b/components/DebugWindow.py new file mode 100644 index 0000000..a57af9b --- /dev/null +++ b/components/DebugWindow.py @@ -0,0 +1,26 @@ +from PyQt5.QtWidgets import ( + QDialog, + QPlainTextEdit, + QVBoxLayout, + QLabel, + QPushButton, +) +from PyQt5.QtGui import QFont +from components.ErrorDialog import ErrorDialog +from utils import set_id3_tag + + +class DebugWindow(QDialog): + def __init__(self, song_filepath: str, text: str): + super(DebugWindow, self).__init__() + self.setWindowTitle("debug") + self.setMinimumSize(400, 400) + self.text: str = text + self.song_filepath: str = song_filepath + layout = QVBoxLayout() + + # Labels & input fields + self.input_field = QPlainTextEdit(self.text) + layout.addWidget(self.input_field) + + self.setLayout(layout) diff --git a/components/MusicTable.py b/components/MusicTable.py index 21cd099..ce6d071 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -17,6 +17,7 @@ from PyQt5.QtWidgets import ( QAbstractItemView, ) from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt, pyqtSignal, QTimer +from components.DebugWindow import DebugWindow from components.ErrorDialog import ErrorDialog from components.LyricsWindow import LyricsWindow from components.AddToPlaylistWindow import AddToPlaylistWindow @@ -112,6 +113,10 @@ class MusicTable(QTableView): open_containing_folder_action = QAction("Open in system file manager", self) open_containing_folder_action.triggered.connect(self.open_directory) menu.addAction(open_containing_folder_action) + # view id3 tags (debug) + view_id3_tags_debug = QAction("View ID3 tags (debug)", self) + view_id3_tags_debug.triggered.connect(self.show_id3_tags_debug_menu) + menu.addAction(view_id3_tags_debug) # delete song delete_action = QAction("Delete", self) delete_action.triggered.connect(self.delete_songs) @@ -120,6 +125,15 @@ class MusicTable(QTableView): self.set_selected_song_filepath() menu.exec_(event.globalPos()) + def show_id3_tags_debug_menu(self): + """Shows ID3 tags for a specific .mp3 file""" + selected_song_filepath = self.get_selected_song_filepath() + if selected_song_filepath is None: + return + current_song = self.get_selected_song_metadata() + lyrics_window = DebugWindow(selected_song_filepath, str(current_song)) + lyrics_window.exec_() + def delete_songs(self): """Deletes the currently selected songs from the db and music table (not the filesystem)""" reply = QMessageBox.question( diff --git a/components/__init__.py b/components/__init__.py index 0735531..57ba057 100644 --- a/components/__init__.py +++ b/components/__init__.py @@ -4,6 +4,7 @@ from .AudioVisualizer import AudioVisualizer from .PreferencesWindow import PreferencesWindow from .ErrorDialog import ErrorDialog from .LyricsWindow import LyricsWindow +from .DebugWindow import DebugWindow from .AddToPlaylistWindow import AddToPlaylistWindow from .CreatePlaylistWindow import CreatePlaylistWindow from .PlaylistsPane import PlaylistsPane diff --git a/utils/set_id3_tag.py b/utils/set_id3_tag.py index c88e38b..56415e1 100644 --- a/utils/set_id3_tag.py +++ b/utils/set_id3_tag.py @@ -1,5 +1,6 @@ import logging from components import ErrorDialog +from utils.id3_tag_mapping import id3_tag_mapping from utils.convert_date_str_to_tyer_tdat_id3_tag import ( convert_date_str_to_tyer_tdat_id3_tag, ) @@ -122,8 +123,12 @@ def set_id3_tag(filepath: str, tag_name: str, value: str): audio.add(frame) audio.save() return True - # Other - elif tag_name in mutagen_id3_tag_mapping: # Tag accounted for + # Convert any tag (as string or name, or whatever) into the Mutagen Frame object + if tag_name in id3_tag_mapping: + tag_name = id3_tag_mapping[tag_name] + # Other + if tag_name in mutagen_id3_tag_mapping: # Tag accounted for + print(f"set_id3_tag.py | tag_name = {tag_name}") tag_class = mutagen_id3_tag_mapping[tag_name] if issubclass(tag_class, Frame): frame = tag_class(encoding=3, text=[value])