コード例 #1
0
    def __init__(self):
        super(FetchArtPlugin, self).__init__()

        # Holds candidates corresponding to downloaded images between
        # fetching them and placing them in the filesystem.
        self.art_candidates = {}

        self.config.add({
            'auto':
            True,
            'minwidth':
            0,
            'maxwidth':
            0,
            'enforce_ratio':
            False,
            'cautious':
            False,
            'cover_names': ['cover', 'front', 'art', 'album', 'folder'],
            'sources':
            ['filesystem', 'coverart', 'itunes', 'amazon', 'albumart'],
            'google_key':
            None,
            'google_engine':
            u'001442825323518660753:hrh5ch1gjzm',
            'fanarttv_key':
            None,
            'store_source':
            False,
        })
        self.config['google_key'].redact = True
        self.config['fanarttv_key'].redact = True

        self.minwidth = self.config['minwidth'].get(int)
        self.maxwidth = self.config['maxwidth'].get(int)

        # allow both pixel and percentage-based margin specifications
        self.enforce_ratio = self.config['enforce_ratio'].get(
            confuse.OneOf([
                bool,
                confuse.String(pattern=self.PAT_PX),
                confuse.String(pattern=self.PAT_PERCENT)
            ]))
        self.margin_px = None
        self.margin_percent = None
        if type(self.enforce_ratio) is six.text_type:
            if self.enforce_ratio[-1] == u'%':
                self.margin_percent = float(self.enforce_ratio[:-1]) / 100
            elif self.enforce_ratio[-2:] == u'px':
                self.margin_px = int(self.enforce_ratio[:-2])
            else:
                # shouldn't happen
                raise confuse.ConfigValueError()
            self.enforce_ratio = True

        cover_names = self.config['cover_names'].as_str_seq()
        self.cover_names = list(map(util.bytestring_path, cover_names))
        self.cautious = self.config['cautious'].get(bool)
        self.store_source = self.config['store_source'].get(bool)

        self.src_removed = (config['import']['delete'].get(bool)
                            or config['import']['move'].get(bool))

        if self.config['auto']:
            # Enable two import hooks when fetching is enabled.
            self.import_stages = [self.fetch_art]
            self.register_listener('import_task_files', self.assign_art)

        available_sources = list(SOURCES_ALL)
        if not self.config['google_key'].get() and \
                u'google' in available_sources:
            available_sources.remove(u'google')
        available_sources = [(s, c) for s in available_sources
                             for c in ART_SOURCES[s].VALID_MATCHING_CRITERIA]
        sources = plugins.sanitize_pairs(
            self.config['sources'].as_pairs(default_value='*'),
            available_sources)

        if 'remote_priority' in self.config:
            self._log.warning(
                u'The `fetch_art.remote_priority` configuration option has '
                u'been deprecated. Instead, place `filesystem` at the end of '
                u'your `sources` list.')
            if self.config['remote_priority'].get(bool):
                fs = []
                others = []
                for s, c in sources:
                    if s == 'filesystem':
                        fs.append((s, c))
                    else:
                        others.append((s, c))
                sources = others + fs

        self.sources = [
            ART_SOURCES[s](self._log, self.config, match_by=[c])
            for s, c in sources
        ]
コード例 #2
0
ファイル: fetchart.py プロジェクト: SerhatG/nzbToMedia
    def __init__(self):
        super(FetchArtPlugin, self).__init__()

        # Holds candidates corresponding to downloaded images between
        # fetching them and placing them in the filesystem.
        self.art_candidates = {}

        self.config.add({
            'auto': True,
            'minwidth': 0,
            'maxwidth': 0,
            'enforce_ratio': False,
            'cautious': False,
            'cover_names': ['cover', 'front', 'art', 'album', 'folder'],
            'sources': ['filesystem',
                        'coverart', 'itunes', 'amazon', 'albumart'],
            'google_key': None,
            'google_engine': u'001442825323518660753:hrh5ch1gjzm',
            'fanarttv_key': None,
            'store_source': False,
        })
        self.config['google_key'].redact = True
        self.config['fanarttv_key'].redact = True

        self.minwidth = self.config['minwidth'].get(int)
        self.maxwidth = self.config['maxwidth'].get(int)

        # allow both pixel and percentage-based margin specifications
        self.enforce_ratio = self.config['enforce_ratio'].get(
            confit.OneOf([bool,
                          confit.String(pattern=self.PAT_PX),
                          confit.String(pattern=self.PAT_PERCENT)]))
        self.margin_px = None
        self.margin_percent = None
        if type(self.enforce_ratio) is six.text_type:
            if self.enforce_ratio[-1] == u'%':
                self.margin_percent = float(self.enforce_ratio[:-1]) / 100
            elif self.enforce_ratio[-2:] == u'px':
                self.margin_px = int(self.enforce_ratio[:-2])
            else:
                # shouldn't happen
                raise confit.ConfigValueError()
            self.enforce_ratio = True

        cover_names = self.config['cover_names'].as_str_seq()
        self.cover_names = list(map(util.bytestring_path, cover_names))
        self.cautious = self.config['cautious'].get(bool)
        self.store_source = self.config['store_source'].get(bool)

        self.src_removed = (config['import']['delete'].get(bool) or
                            config['import']['move'].get(bool))

        if self.config['auto']:
            # Enable two import hooks when fetching is enabled.
            self.import_stages = [self.fetch_art]
            self.register_listener('import_task_files', self.assign_art)

        available_sources = list(SOURCES_ALL)
        if not HAVE_ITUNES and u'itunes' in available_sources:
            available_sources.remove(u'itunes')
        if not self.config['google_key'].get() and \
                u'google' in available_sources:
            available_sources.remove(u'google')
        available_sources = [(s, c)
                             for s in available_sources
                             for c in ART_SOURCES[s].VALID_MATCHING_CRITERIA]
        sources = plugins.sanitize_pairs(
            self.config['sources'].as_pairs(default_value='*'),
            available_sources)

        if 'remote_priority' in self.config:
            self._log.warning(
                u'The `fetch_art.remote_priority` configuration option has '
                u'been deprecated. Instead, place `filesystem` at the end of '
                u'your `sources` list.')
            if self.config['remote_priority'].get(bool):
                fs = []
                others = []
                for s, c in sources:
                    if s == 'filesystem':
                        fs.append((s, c))
                    else:
                        others.append((s, c))
                sources = others + fs

        self.sources = [ART_SOURCES[s](self._log, self.config, match_by=[c])
                        for s, c in sources]