Add additional error handling

This commit is contained in:
Alok Saboo 2023-03-27 11:56:26 -04:00
parent 2060e047d2
commit 2e2a3bf223

View file

@ -112,8 +112,15 @@ class EmbedCoverArtPlugin(BeetsPlugin):
quality=quality)
elif opts.url:
from PIL import Image
response = requests.get(opts.url)
img = Image.open(BytesIO(response.content))
try:
response = requests.get(opts.url, timeout=5)
response.raise_for_status()
except requests.exceptions.RequestException as e:
self._log.error("Error: {}".format(e))
try:
img = Image.open(BytesIO(response.content))
except OSError as e:
self._log.error("Error: {}".format(e))
if img.format:
with open('temp.jpg', 'wb') as f:
f.write(response.content)