From 716ebfa021b2835aea87ed51e8fb3c19e9e7d410 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Thu, 26 Jun 2025 22:06:07 +0200 Subject: [PATCH] Fix sound length metadata having no formatting. --- menus/main.py | 4 ++-- utils/utils.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/menus/main.py b/menus/main.py index aff6a21..e7081e8 100644 --- a/menus/main.py +++ b/menus/main.py @@ -3,7 +3,7 @@ import arcade, pyglet from utils.preload import * from utils.constants import button_style, slider_style, audio_extensions, discord_presence_id -from utils.utils import FakePyPresence, UIFocusTextureButton, MusicItem, extract_metadata_and_thumbnail, truncate_end, adjust_volume +from utils.utils import FakePyPresence, UIFocusTextureButton, MusicItem, extract_metadata_and_thumbnail, truncate_end, adjust_volume, convert_seconds_to_date from thefuzz import process, fuzz @@ -264,7 +264,7 @@ class Main(arcade.gui.UIView): def open_metadata(self, file_path): metadata = self.file_metadata[file_path] - metadata_text = f"File path: {file_path}\nArtist: {metadata['artist']}\nTitle: {metadata['title']}\nSound length: {int(metadata['sound_length'])}\nBitrate: {metadata['bit_rate']}Kbps" + metadata_text = f"File path: {file_path}\nArtist: {metadata['artist']}\nTitle: {metadata['title']}\nSound length: {convert_seconds_to_date(int(metadata['sound_length']))}\nBitrate: {metadata['bit_rate']}Kbps" msgbox = arcade.gui.UIMessageBox(title=f"{metadata['artist']} - {metadata['title']} Metadata", buttons=("Uploader", "Source", "Close"), message_text=metadata_text, width=self.window.width / 2, height=self.window.height / 2) msgbox.on_action = lambda event, metadata=metadata: self.metadata_button_action(event.action, metadata) diff --git a/utils/utils.py b/utils/utils.py index 912f79a..29c3dc7 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -301,4 +301,21 @@ def adjust_volume(input_path, volume): change = volume - audio.dBFS audio.apply_gain(change) - audio.export(input_path, **export_args) \ No newline at end of file + audio.export(input_path, **export_args) + +def convert_seconds_to_date(seconds): + days, remainder = divmod(seconds, 86400) + hours, remainder = divmod(remainder, 3600) + minutes, seconds = divmod(remainder, 60) + + result = "" + if days > 0: + result += "{} days ".format(int(days)) + if hours > 0: + result += "{} hours ".format(int(hours)) + if minutes > 0: + result += "{} minutes ".format(int(minutes)) + if seconds > 0 or not any([days, hours, minutes]): + result += "{} seconds".format(int(seconds)) + + return result.strip() \ No newline at end of file