В настоящее время я использую Mutagen из-за его простоты и это помогает, за исключением того, что встраивание изображений не работает

Приведенный ниже код пытается создать кадр APIC:< /p>
Код: Выделить всё
def embed_artwork(file_path, image_data):
try:
# Open the audio file
audio = ID3(file_path)
if not image_data:
print(f"[ERROR] No image data provided for {file_path}.")
return
# Detect MIME type from image data
with Image.open(BytesIO(image_data)) as img:
detected_format = img.format.lower()
if detected_format == "jpeg":
mime_type = "image/jpeg"
elif detected_format == "png":
mime_type = "image/png"
else:
print(f"[ERROR] Unsupported image format: {detected_format}. Only JPEG and PNG are supported.")
return
# Clear existing APIC frames
audio.delall("APIC")
print("[INFO] Cleared existing APIC frames.")
# Create and add the APIC frame
apic_frame = APIC(
encoding=3, # UTF-8 encoding
mime=mime_type, # MIME type
type=3, # Type 3 indicates front cover artwork
desc="Cover", # Description
data=image_data # Image data
)
audio.add(apic_frame)
print("[INFO] Added APIC frame with cover image.")
# Save the changes
audio.save(v2_version=3)
print("[INFO] Saved MP3 file with embedded cover image.")
except Exception as e:
print(f"[ERROR] Failed to embed cover image in {file_path}: {e}")
Подробнее здесь: https://stackoverflow.com/questions/793 ... ng-mutagen