From 1325f9546fbbaf6f596096e1e7e06d8e4163f232 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Mon, 21 Jul 2025 17:33:56 +0200 Subject: [PATCH] Fix crashing due to Discord RPC error and fix metadata handling crashing if there are no id3 headers --- menus/main.py | 2 +- utils/music_handling.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/menus/main.py b/menus/main.py index 652d1af..a1ec17a 100644 --- a/menus/main.py +++ b/menus/main.py @@ -621,7 +621,7 @@ class Main(arcade.gui.UIView): else: state = "Paused" else: - details = "" + details = "No songs playing" state = "No songs playing" self.pypresence_client.update(state=state, details=details, start=self.pypresence_client.start_time) diff --git a/utils/music_handling.py b/utils/music_handling.py index da6dbc3..6f31362 100644 --- a/utils/music_handling.py +++ b/utils/music_handling.py @@ -55,14 +55,14 @@ def extract_metadata_and_thumbnail(file_path: str, thumb_resolution: tuple): last_played = float(frame.text[0]) elif desc == "play_count": play_count = int(frame.text[0]) + + if hasattr(easyid3, "info"): + sound_length = round(easyid3.info.length, 2) + bitrate = int((easyid3.info.bitrate or 0) / 1000) + sample_rate = int(easyid3.info.sample_rate / 1000) except ID3NoHeaderError: pass - if hasattr(easyid3, "info"): - sound_length = round(easyid3.info.length, 2) - bitrate = int((easyid3.info.bitrate or 0) / 1000) - sample_rate = int(easyid3.info.sample_rate / 1000) - apic = id3.getall("APIC") thumb_image_data = apic[0].data if apic else None