From 49e8c124606f404bdd57746031a8afce10ea7c6d Mon Sep 17 00:00:00 2001 From: billypom on debian Date: Mon, 30 Sep 2024 20:44:52 -0400 Subject: [PATCH] album art not working --- components/AlbumArtGraphicsView.py | 9 +++++---- components/MusicTable.py | 1 - main.py | 16 ++++++++++++---- utils/get_album_art.py | 7 ++++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/components/AlbumArtGraphicsView.py b/components/AlbumArtGraphicsView.py index 68064cf..e45a0a3 100644 --- a/components/AlbumArtGraphicsView.py +++ b/components/AlbumArtGraphicsView.py @@ -7,7 +7,7 @@ from PyQt5.QtWidgets import ( QMenu, QAction, ) -from PyQt5.QtCore import QEvent, Qt, pyqtSignal, QUrl, QPoint +from PyQt5.QtCore import QEvent, QMimeData, Qt, pyqtSignal, QUrl, QPoint from PyQt5.QtGui import ( QDragEnterEvent, QDragMoveEvent, @@ -23,7 +23,7 @@ class AlbumArtGraphicsView(QGraphicsView): """ albumArtDropped = pyqtSignal(str) - albumArtDeleted = pyqtSignal(str) + albumArtDeleted = pyqtSignal() def __init__(self, parent=None): super().__init__(parent) @@ -113,10 +113,11 @@ class AlbumArtGraphicsView(QGraphicsView): """Copies album art to the clipboard""" if not self.scene().items(): return # dont care if no pic - # FIXME: i want types here. what is actually going on... + clipboard = self.qapp.clipboard() pixmap_item = self.scene().items()[0] - clipboard.setPixmap(pixmap_item.pixmap()) + if hasattr(pixmap_item, "pixmap"): + clipboard.setPixmap(pixmap_item.pixmap()) def paste_album_art_from_clipboard(self): """Handles pasting album art into a song via system clipboard""" diff --git a/components/MusicTable.py b/components/MusicTable.py index b35c0a4..6ba8a81 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -670,7 +670,6 @@ class MusicTable(QTableView): self.selected_song_filepath = ( self.currentIndex().siblingAtColumn(self.table_headers.index("path")).data() ) - logging.info(self.selected_song_filepath) def set_current_song_filepath(self) -> None: """Sets the filepath of the currently playing song""" diff --git a/main.py b/main.py index bcad990..dc4755c 100644 --- a/main.py +++ b/main.py @@ -286,7 +286,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): """Start playback of tableView.current_song_filepath track & moves playback slider""" # get metadata self.current_song_metadata = self.tableView.get_current_song_metadata() - logging.info("current song metadata: %s", self.current_song_metadata) # read the file url = QUrl.fromLocalFile(self.tableView.get_current_song_filepath()) # load the audio content @@ -364,12 +363,21 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): # delete APIC data try: audio = ID3(file) + print("AAAAAAAAAAAAAAAAAAAAA") + print(audio) + print("AAAAAAAAAAAAAAAAAAAAA") if "APIC:" in audio: - del audio["APIC"] + del audio["APIC:"] audio.save() - except Exception as e: + else: + logging.warning( + "delete_album_art_for_current_song() | no tag called APIC" + ) + except Exception: + traceback.print_exc() + exctype, value = sys.exc_info()[:2] logging.error( - f"delete_album_art_for_selected_songs() | Error processing {file}: {e}" + f"delete_album_art_for_current_song() | Error processing this file:\t {file}\n{exctype}\n{value}\n{traceback.format_exc()}" ) def update_audio_visualization(self) -> None: diff --git a/utils/get_album_art.py b/utils/get_album_art.py index 27beaea..f88c473 100644 --- a/utils/get_album_art.py +++ b/utils/get_album_art.py @@ -1,4 +1,5 @@ -from mutagen.id3 import ID3, APIC +from mutagen.id3 import ID3 +import logging def get_album_art(file: str) -> bytes: @@ -6,7 +7,7 @@ def get_album_art(file: str) -> bytes: # Parameters `file` | str | Fully qualified path to file # Returns - Data for album art or default file + bytes for album art or placeholder artwork """ default_image_path = "./assets/default_album_art.jpg" try: @@ -19,5 +20,5 @@ def get_album_art(file: str) -> bytes: except Exception as e: print(f"Error retrieving album art: {e}") with open(default_image_path, "rb") as f: - print(f"album art type: {type(f.read())}") + logging.info("loading placeholder album art") return f.read()