From 85d276f2d4e4bede78193a81262210a84afbe1ed Mon Sep 17 00:00:00 2001 From: Michal Tuszowski Date: Wed, 8 Jan 2025 11:34:40 +0100 Subject: [PATCH] Function for idv3 and bugfix --- conjurer_musician/music_utils.py | 36 ++++++++++++++++++++++++++++++++ other_functions.py | 7 +++++++ 2 files changed, 43 insertions(+) diff --git a/conjurer_musician/music_utils.py b/conjurer_musician/music_utils.py index 817b880..8e7af7f 100644 --- a/conjurer_musician/music_utils.py +++ b/conjurer_musician/music_utils.py @@ -2,6 +2,42 @@ """This module contains utility scripts used by musi radiostation Conjurer""" import time import re +import os +from mutagen.easyid3 import EasyID3 +from mutagen.mp3 import MP3 + +def update_metadata(base_folder): + for root, _, files in os.walk(base_folder): + for file in files: + if file.endswith('.mp3'): + full_path = os.path.join(root, file) + try: + print(f"Processing {full_path}") + # Parse metadata from the filename or path + # For example, assume filenames are in the format "Artist - Title.mp3" + filename = os.path.splitext(file)[0] + parts = filename.split(' - ') + if len(parts) == 2: + artist, title = parts + else: + artist = 'Unknown Artist' + title = filename + + # Load the MP3 file + audio = MP3(full_path, ID3=EasyID3) + + # Update metadata + audio['title'] = title + audio['artist'] = artist + + # Save changes + audio.save() + print(f"Updated metadata: Artist = {artist}, Title = {title}") + except Exception as e: + print(f"Error processing {file}: {e}") + +base_folder = 'path/to/your/folder' # Update with the path to your folder +#update_metadata(base_folder) NAME = "/home/pi/Conjurer/persistence.log" diff --git a/other_functions.py b/other_functions.py index 263217e..be80980 100644 --- a/other_functions.py +++ b/other_functions.py @@ -1,4 +1,7 @@ +import logging # define an asynchronous generator +LOGGER = logging.getLogger("discord") + async def async_iterator_generator(range_of_iterable): """ Generate asynchronouse iterator. @@ -87,8 +90,10 @@ async def get_stats(client, ctx, history_limit): async def discord_friendly_reply(ctx, message_content, file=None): if len(message_content) < 999: + LOGGER.info("Wiadomosci ponizej 999 znakow") await ctx.reply(message_content) else: + LOGGER.info("Wiadomosci powyzej 999 znakow") while len(message_content) > 999: await ctx.reply(message_content[:999]) message_content = message_content[999:] @@ -97,8 +102,10 @@ async def discord_friendly_reply(ctx, message_content, file=None): async def discord_friendly_send(ctx, message_content, file=None): if len(message_content) < 999: + LOGGER.info("Wiadomosci ponizej 999 znakow") await ctx.send(message_content) else: + LOGGER.info("Wiadomosci powyzej 999 znakow") while len(message_content) > 999: await ctx.send(message_content[:999]) message_content = message_content[999:]