Skip to content

Commit

Permalink
Fix edge case when Pillow is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
bbye98 committed Mar 11, 2024
1 parent 01280e4 commit 8752acf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/minim/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import subprocess
from typing import Any, Union
import urllib
import warnings

from mutagen import id3, flac, mp3, mp4, oggflac, oggopus, oggvorbis, wave

Expand Down Expand Up @@ -831,11 +832,18 @@ def set_metadata_using_itunes(
with urllib.request.urlopen(self.artwork) as r:
self.artwork = r.read()
if self._artwork_format == "tif":
with Image.open(BytesIO(self.artwork)) as a:
with BytesIO() as b:
a.save(b, format="png")
self.artwork = b.getvalue()
self._artwork_format = "png"
if FOUND_PILLOW:
with Image.open(BytesIO(self.artwork)) as a:
with BytesIO() as b:
a.save(b, format="png")
self.artwork = b.getvalue()
self._artwork_format = "png"
else:
wmsg = ("The Pillow library is required to process "
"TIFF images, but was not found. No artwork "
"will be embedded for the current track.")
warnings.warn(wmsg)
self.artwork = self._artwork_format = None
if self.compilation is None or overwrite:
self.compilation = self.album_artist == "Various Artists"
if "releaseDate" in data and (self.date is None or overwrite):
Expand Down

0 comments on commit 8752acf

Please sign in to comment.