def _validate(self, extra):
        """Determine whether the candidate artwork is valid based on
        its dimensions (width and ratio).

        Return `CANDIDATE_BAD` if the file is unusable.
        Return `CANDIDATE_EXACT` if the file is usable as-is.
        Return `CANDIDATE_DOWNSCALE` if the file must be resized.
        """
        if not self.path:
            return self.CANDIDATE_BAD

        if not (extra['enforce_ratio'] or
                extra['minwidth'] or
                extra['maxwidth']):
            return self.CANDIDATE_EXACT

        # get_size returns None if no local imaging backend is available
        if not self.size:
            self.size = ArtResizer.shared.get_size(self.path)
        self._log.debug(u'image size: {}', self.size)

        if not self.size:
            self._log.warning(u'Could not get size of image (please see '
                              u'documentation for dependencies). '
                              u'The configuration options `minwidth` and '
                              u'`enforce_ratio` may be violated.')
            return self.CANDIDATE_EXACT

        short_edge = min(self.size)
        long_edge = max(self.size)

        # Check minimum size.
        if extra['minwidth'] and self.size[0] < extra['minwidth']:
            self._log.debug(u'image too small ({} < {})',
                            self.size[0], extra['minwidth'])
            return self.CANDIDATE_BAD

        # Check aspect ratio.
        edge_diff = long_edge - short_edge
        if extra['enforce_ratio']:
            if extra['margin_px']:
                if edge_diff > extra['margin_px']:
                    self._log.debug(u'image is not close enough to being '
                                    u'square, ({} - {} > {})',
                                    long_edge, short_edge, extra['margin_px'])
                    return self.CANDIDATE_BAD
            elif extra['margin_percent']:
                margin_px = extra['margin_percent'] * long_edge
                if edge_diff > margin_px:
                    self._log.debug(u'image is not close enough to being '
                                    u'square, ({} - {} > {})',
                                    long_edge, short_edge, margin_px)
                    return self.CANDIDATE_BAD
            elif edge_diff:
                # also reached for margin_px == 0 and margin_percent == 0.0
                self._log.debug(u'image is not square ({} != {})',
                                self.size[0], self.size[1])
                return self.CANDIDATE_BAD

        # Check maximum size.
        if extra['maxwidth'] and self.size[0] > extra['maxwidth']:
            self._log.debug(u'image needs resizing ({} > {})',
                            self.size[0], extra['maxwidth'])
            return self.CANDIDATE_DOWNSCALE

        return self.CANDIDATE_EXACT
dataset/ETHPy150Open beetbox/beets/beetsplug/fetchart.py/Candidate._validate/original