'Downloads an image from a URL and checks whether it seems to
actually be an image. If so, returns a path to the downloaded image.
Otherwise, returns None.'

def fetch_image(self, candidate, plugin):

    if plugin.maxwidth:
        candidate.url = ArtResizer.shared.proxy_url(plugin.maxwidth, candidate.url)
    try:
        with closing(self.request(candidate.url, stream=True, message=u'downloading    image')) as resp:
            ct = resp.headers.get('Content-Type', None)
            data = resp.iter_content(chunk_size=1024)
            header = ''
            for chunk in data:
                header += chunk
                if (len(header) >= 32):
                    break
            else:
                return
            real_ct = image_mime_type(header)
            if (real_ct is None):
                real_ct = ct
            if (real_ct not in CONTENT_TYPES):
                self._log.debug(u'not    a    supported    image:    {}', (real_ct or u'unknown    content    type'))
                return
            ext = ('.' + CONTENT_TYPES[real_ct][0])
            if (real_ct != ct):
                self._log.warning(u'Server    specified    {},    but    returned    a    {}    image.    Correcting    the    extension    to    {}', ct, real_ct, ext)
            suffix = py3_path(ext)
            with NamedTemporaryFile(suffix=suffix, delete=False) as fh:
                fh.write(header)
                for chunk in data:
                    fh.write(chunk)
            self._log.debug(u'downloaded    art    to:    {0}', util.displayable_path(fh.name))
            candidate.path = util.bytestring_path(fh.name)
            return
    except (IOError, requests.RequestException, TypeError) as exc:
        self._log.debug(u'error    fetching    art:    {}', exc)
        return
