From da7d679248487325af61ea87980f9a4eb77dc53c Mon Sep 17 00:00:00 2001 From: tsi-billypom Date: Fri, 28 Mar 2025 16:10:47 -0400 Subject: [PATCH] after delete album artwork, set default in qgraphicsview --- main.py | 5 +++++ utils/get_album_art.py | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 4b814c3..50b3dad 100644 --- a/main.py +++ b/main.py @@ -47,6 +47,7 @@ from components import ( CreatePlaylistWindow, ExportPlaylistWindow, ) +from utils.get_album_art import get_album_art # good help with signals slots in threads # https://stackoverflow.com/questions/52993677/how-do-i-setup-signals-and-slots-in-pyqt-with-qthreads-in-both-directions @@ -389,6 +390,10 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): error( f"delete_album_art_for_current_song() | Error processing this file:\t {file}\n{exctype}\n{value}\n{traceback.format_exc()}" ) + # Load the default album artwork in the qgraphicsview + album_art_data = self.tableView.get_current_song_album_art() + album_art_data = get_album_art(None) + self.albumGraphicsView.load_album_art(album_art_data) def update_audio_visualization(self) -> None: """Handles upading points on the pyqtgraph visual""" diff --git a/utils/get_album_art.py b/utils/get_album_art.py index 7d99c17..d599376 100644 --- a/utils/get_album_art.py +++ b/utils/get_album_art.py @@ -2,7 +2,7 @@ from mutagen.id3 import ID3 from logging import debug, error -def get_album_art(file: str) -> bytes: +def get_album_art(file: str | None) -> bytes: """Get the album art for an audio file # Parameters `file` | str | Fully qualified path to file @@ -10,15 +10,16 @@ def get_album_art(file: str) -> bytes: bytes for album art or placeholder artwork """ default_image_path = "./assets/default_album_art.jpg" - try: - audio = ID3(file) - for tag in audio.getall("APIC"): - if tag.type == 3: # 3 is the type for front cover - return tag.data - if audio.getall("APIC"): - return audio.getall("APIC")[0].data - except Exception as e: - error(f"Error retrieving album art: {e}") + if file: + try: + audio = ID3(file) + for tag in audio.getall("APIC"): + if tag.type == 3: # 3 is the type for front cover + return tag.data + if audio.getall("APIC"): + return audio.getall("APIC")[0].data + except Exception as e: + error(f"Error retrieving album art: {e}") with open(default_image_path, "rb") as f: debug("loading placeholder album art") return f.read()