25 lines
772 B
Python
25 lines
772 B
Python
from mutagen.id3 import ID3
|
|
import logging
|
|
|
|
|
|
def get_album_art(file: str) -> bytes:
|
|
"""Get the album art for an audio file
|
|
# Parameters
|
|
`file` | str | Fully qualified path to file
|
|
# Returns
|
|
bytes for album art or placeholder artwork
|
|
"""
|
|
default_image_path = "./assets/default_album_art.jpg"
|
|
try:
|
|
audio = ID3(file)
|
|
for tag in audio.getall("APIC"):
|
|
if tag.type == 3: # 3 is the type for front cover
|
|
return tag.data
|
|
if audio.getall("APIC"):
|
|
return audio.getall("APIC")[0].data
|
|
except Exception as e:
|
|
print(f"Error retrieving album art: {e}")
|
|
with open(default_image_path, "rb") as f:
|
|
logging.info("loading placeholder album art")
|
|
return f.read()
|