From da3bbf414ff7bee80daea73c9996a64af6f0b403 Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Thu, 9 Feb 2017 19:32:40 +0100 Subject: [PATCH] Use picard.util.imageinfo.py::identify to guess the mimetype of dropped image data Replace the hack to identify the image format of the dropped octet-stream with a call to imageinfo.identify which is used in other parts of picard. --- picard/ui/coverartbox.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/picard/ui/coverartbox.py b/picard/ui/coverartbox.py index 54c92fdd5..cf2409966 100644 --- a/picard/ui/coverartbox.py +++ b/picard/ui/coverartbox.py @@ -25,7 +25,7 @@ from picard.album import Album from picard.coverart.image import CoverArtImage, CoverArtImageError from picard.track import Track from picard.file import File -from picard.util import encode_filename +from picard.util import encode_filename, imageinfo class ActiveLabel(QtGui.QLabel): @@ -189,16 +189,13 @@ class CoverArtBox(QtGui.QGroupBox): log.warning("Can't load remote image with MIME-Type %s", mime) if fallback_data: # Tests for image format obtained from file-magic - if fallback_data[:2]=='\xff\xd8': - mime = 'image/jpeg' - elif fallback_data[:8]=='\x89PNG\x0d\x0a\x1a\x0a': - mime = 'image/png' - else: - mime = None - - if mime: - log.debug("Trying the dropped %s data", mime) + try: + mime = imageinfo.identify(fallback_data)[2] + log.warning("Trying the dropped %s data", mime) self.load_remote_image(url, mime, fallback_data) + except: + log.error("Unable to identify dropped data format") + def load_remote_image(self, url, mime, data):