mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 17:49:11 +01:00
fetchart: do not hardcode the downloaded extension to jpg, fixes #2053
This commit is contained in:
parent
08c9bd84d8
commit
c4617c2c1f
1 changed files with 8 additions and 6 deletions
|
|
@ -39,9 +39,11 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAVE_ITUNES = False
|
HAVE_ITUNES = False
|
||||||
|
|
||||||
IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg']
|
CONTENT_TYPES = {
|
||||||
CONTENT_TYPES = ('image/jpeg', 'image/png')
|
'image/jpeg': [b'jpg', b'jpeg'],
|
||||||
DOWNLOAD_EXTENSION = '.jpg'
|
'image/png': [b'png']
|
||||||
|
}
|
||||||
|
IMAGE_EXTENSIONS = [ext for exts in CONTENT_TYPES.values() for ext in exts]
|
||||||
|
|
||||||
|
|
||||||
class Candidate(object):
|
class Candidate(object):
|
||||||
|
|
@ -227,8 +229,8 @@ class RemoteArtSource(ArtSource):
|
||||||
try:
|
try:
|
||||||
with closing(self.request(candidate.url, stream=True,
|
with closing(self.request(candidate.url, stream=True,
|
||||||
message=u'downloading image')) as resp:
|
message=u'downloading image')) as resp:
|
||||||
if 'Content-Type' not in resp.headers \
|
ct = resp.headers.get('Content-Type', None)
|
||||||
or resp.headers['Content-Type'] not in CONTENT_TYPES:
|
if ct not in CONTENT_TYPES:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
u'not a supported image: {}',
|
u'not a supported image: {}',
|
||||||
resp.headers.get('Content-Type') or u'no content type',
|
resp.headers.get('Content-Type') or u'no content type',
|
||||||
|
|
@ -237,7 +239,7 @@ class RemoteArtSource(ArtSource):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Generate a temporary file with the correct extension.
|
# Generate a temporary file with the correct extension.
|
||||||
with NamedTemporaryFile(suffix=DOWNLOAD_EXTENSION,
|
with NamedTemporaryFile(suffix=b'.' + CONTENT_TYPES[ct][0],
|
||||||
delete=False) as fh:
|
delete=False) as fh:
|
||||||
for chunk in resp.iter_content(chunk_size=1024):
|
for chunk in resp.iter_content(chunk_size=1024):
|
||||||
fh.write(chunk)
|
fh.write(chunk)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue