Function for idv3 and bugfix

This commit is contained in:
2025-01-08 11:34:40 +01:00
parent 0f596cbdba
commit 85d276f2d4
2 changed files with 43 additions and 0 deletions
+36
View File
@@ -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"