Skip to content

Commit 34cdf0f

Browse files
author
wordofglass
committed
fetchart: complain about unsupported images only after validating the Content-Type
1 parent d47182a commit 34cdf0f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

beetsplug/fetchart.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ def fetch_image(self, candidate, extra):
231231
with closing(self.request(candidate.url, stream=True,
232232
message=u'downloading image')) as resp:
233233
ct = resp.headers.get('Content-Type', None)
234-
if ct not in CONTENT_TYPES:
235-
self._log.debug(u'not a supported image: {}',
236-
ct or u'no content type')
237-
candidate.path = None
238-
return
239234

240235
# Generate a temporary file and guess the extension based on
241236
# the Content-Type header. This may be wrong for badly
@@ -251,12 +246,19 @@ def fetch_image(self, candidate, extra):
251246
pass
252247
else:
253248
real_ct = _image_mime_type(chunk)
249+
if real_ct not in CONTENT_TYPES:
250+
self._log.debug(u'not a supported image: {}',
251+
real_ct or u'unknown content type')
252+
candidate.path = None
253+
return
254+
254255
ext = b'.' + CONTENT_TYPES[real_ct][0]
255256
if real_ct != ct:
256257
self._log.warn(u'Server specified {}, but returned a '
257258
u'{} image. Correcting the extension '
258259
u'to {}',
259260
ct, real_ct, ext)
261+
260262
with NamedTemporaryFile(suffix=ext, delete=False) as fh:
261263
fh.write(chunk)
262264
for chunk in data:

0 commit comments

Comments
 (0)