From 4d1fa797af53da5fafddc8b808b905917e32df6c Mon Sep 17 00:00:00 2001 From: kasparovabi <104397842+kasparovabi@users.noreply.github.com> Date: Mon, 21 Sep 2026 18:16:56 +0300 Subject: [PATCH] Replace imghdr in utils.py so it imports on Python 3.13 Python 3.13 removed imghdr (PEP 594). Pillow is already pinned in requirements.txt, so the album art MIME type now comes from PIL.Image.MIME keyed on the format Pillow detects. --- utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utils.py b/utils.py index 0899a15..43adee8 100644 --- a/utils.py +++ b/utils.py @@ -3,7 +3,8 @@ import os import re import requests -import imghdr +from io import BytesIO +from PIL import Image, UnidentifiedImageError from mutagen.id3 import ID3, COMM, APIC, TPE1, TALB, TIT2, TDRC, TXXX, UFID, error as ID3Error from mutagen import File, MutagenError from mutagen.mp3 import MP3 @@ -139,13 +140,15 @@ def _embed_album_art(self, file_path, album_art_url): response.raise_for_status() image_data = response.content - image_type = imghdr.what(None, h=image_data) - if not image_type: + try: + with Image.open(BytesIO(image_data)) as image: + mime_type = Image.MIME.get(image.format) + except UnidentifiedImageError: + mime_type = None + if not mime_type: print(f"Could not determine image type for {album_art_url}. Skipping embedding.") return - mime_type = f"image/{image_type}" - if file_path.lower().endswith('.mp3'): audio = MP3(file_path, ID3=ID3) audio.tags.add(