def test_sanitize_choices(self): self.assertEqual(plugins.sanitize_choices(['A', 'Z'], ('A', 'B')), ['A']) self.assertEqual(plugins.sanitize_choices(['A', 'A'], ('A')), ['A']) self.assertEqual( plugins.sanitize_choices(['D', '*', 'A'], ('A', 'B', 'C', 'D')), ['D', 'B', 'C', 'A'])
def test_sanitize_choices(self): self.assertEqual(plugins.sanitize_choices([u'A', u'Z'], (u'A', u'B')), [u'A']) self.assertEqual(plugins.sanitize_choices([u'A', u'A'], (u'A')), [u'A']) self.assertEqual( plugins.sanitize_choices([u'D', u'*', u'A'], (u'A', u'B', u'C', u'D')), [u'D', u'B', u'C', u'A'])
def test_sanitize_choices(self): self.assertEqual( plugins.sanitize_choices([u'A', u'Z'], (u'A', u'B')), [u'A']) self.assertEqual( plugins.sanitize_choices([u'A', u'A'], (u'A')), [u'A']) self.assertEqual( plugins.sanitize_choices([u'D', u'*', u'A'], (u'A', u'B', u'C', u'D')), [u'D', u'B', u'C', u'A'])
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add({ 'auto': True, 'google_API_key': None, 'google_engine_ID': u'009217259823014548361:lndtuqkycfu', 'fallback': None, 'force': False, 'sources': self.SOURCES, }) self.config['google_API_key'].redact = True self.config['google_engine_ID'].redact = True available_sources = list(self.SOURCES) if not self.config['google_API_key'].get() and \ 'google' in self.SOURCES: available_sources.remove('google') self.config['sources'] = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.backends = [ self.SOURCE_BACKENDS[key](self.config, self._log) for key in self.config['sources'].as_str_seq() ]
def __init__(self): super(FetchArtPlugin, self).__init__() self.config.add({ 'auto': True, 'minwidth': 0, 'maxwidth': 0, 'enforce_ratio': False, 'remote_priority': False, 'cautious': False, 'cover_names': ['cover', 'front', 'art', 'album', 'folder'], 'sources': ['coverart', 'itunes', 'amazon', 'albumart'], }) # Holds paths to downloaded images between fetching them and # placing them in the filesystem. self.art_paths = {} self.minwidth = self.config['minwidth'].get(int) self.maxwidth = self.config['maxwidth'].get(int) self.enforce_ratio = self.config['enforce_ratio'].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') sources_name = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.sources = [ART_SOURCES[s](self._log) for s in sources_name] self.fs_source = FileSystem(self._log)
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add({ 'auto': True, 'google_API_key': None, 'google_engine_ID': u'009217259823014548361:lndtuqkycfu', 'genius_api_key': "Ryq93pUGm8bM6eUWwD_M3NOFFDAtp2yEE7W" "76V-uFL5jks5dNvcGCdarqFjDhP9c", 'fallback': None, 'force': False, 'sources': self.SOURCES, }) self.config['google_API_key'].redact = True self.config['google_engine_ID'].redact = True self.config['genius_api_key'].redact = True available_sources = list(self.SOURCES) if not self.config['google_API_key'].get() and \ 'google' in self.SOURCES: available_sources.remove('google') self.config['sources'] = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.backends = [self.SOURCE_BACKENDS[key](self.config, self._log) for key in self.config['sources'].as_str_seq()]
def __init__(self): super(FetchArtPlugin, self).__init__() self.config.add({ 'auto': True, 'maxwidth': 0, 'remote_priority': False, 'cautious': False, 'google_search': False, 'cover_names': ['cover', 'front', 'art', 'album', 'folder'], 'sources': SOURCES_ALL, }) # Holds paths to downloaded images between fetching them and # placing them in the filesystem. self.art_paths = {} self.maxwidth = self.config['maxwidth'].get(int) 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') sources_name = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.sources = [ART_FUNCS[s](self._log) for s in sources_name] self.fs_source = FileSystem(self._log)
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add({ 'auto': True, 'bing_client_secret': None, 'bing_lang_from': [], 'bing_lang_to': None, 'google_API_key': None, 'google_engine_ID': u'009217259823014548361:lndtuqkycfu', 'genius_api_key': "Ryq93pUGm8bM6eUWwD_M3NOFFDAtp2yEE7W" "76V-uFL5jks5dNvcGCdarqFjDhP9c", 'fallback': None, 'force': False, 'local': False, 'sources': self.SOURCES, }) self.config['bing_client_secret'].redact = True self.config['google_API_key'].redact = True self.config['google_engine_ID'].redact = True self.config['genius_api_key'].redact = True # State information for the ReST writer. # First, the current artist we're writing. self.artist = u'Unknown artist' # The current album: False means no album yet. self.album = False # The current rest file content. None means the file is not # open yet. self.rest = None available_sources = list(self.SOURCES) sources = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) if not HAS_BEAUTIFUL_SOUP: sources = self.sanitize_bs_sources(sources) if 'google' in sources: if not self.config['google_API_key'].get(): # We log a *debug* message here because the default # configuration includes `google`. This way, the source # is silent by default but can be enabled just by # setting an API key. self._log.debug(u'Disabling google source: ' u'no API key configured.') sources.remove('google') self.config['bing_lang_from'] = [ x.lower() for x in self.config['bing_lang_from'].as_str_seq()] self.bing_auth_token = None if not HAS_LANGDETECT and self.config['bing_client_secret'].get(): self._log.warning(u'To use bing translations, you need to ' u'install the langdetect module. See the ' u'documentation for further details.') self.backends = [self.SOURCE_BACKENDS[source](self.config, self._log) for source in sources]
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add({ 'auto': True, 'bing_client_secret': None, 'bing_lang_from': [], 'bing_lang_to': None, 'google_API_key': None, 'google_engine_ID': u'009217259823014548361:lndtuqkycfu', 'genius_api_key': "Ryq93pUGm8bM6eUWwD_M3NOFFDAtp2yEE7W" "76V-uFL5jks5dNvcGCdarqFjDhP9c", 'fallback': None, 'force': False, 'sources': self.SOURCES, }) self.config['bing_client_secret'].redact = True self.config['google_API_key'].redact = True self.config['google_engine_ID'].redact = True self.config['genius_api_key'].redact = True available_sources = list(self.SOURCES) sources = plugins.sanitize_choices(self.config['sources'].as_str_seq(), available_sources) if 'google' in sources: if not self.config['google_API_key'].get(): self._log.warn(u'To use the google lyrics source, you must ' u'provide an API key in the configuration. ' u'See the documentation for further details.') sources.remove('google') if not HAS_BEAUTIFUL_SOUP: self._log.warn(u'To use the google lyrics source, you must ' u'install the beautifulsoup4 module. See the ' u'documentation for further details.') sources.remove('google') self.config['bing_lang_from'] = [ x.lower() for x in self.config['bing_lang_from'].as_str_seq() ] self.bing_auth_token = None if not HAS_LANGDETECT and self.config['bing_client_secret'].get(): self._log.warn(u'To use bing translations, you need to ' u'install the langdetect module. See the ' u'documentation for further details.') self.backends = [ self.SOURCE_BACKENDS[source](self.config, self._log) for source in sources ]
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add( { "auto": True, "bing_client_secret": None, "bing_lang_from": [], "bing_lang_to": None, "google_API_key": None, "google_engine_ID": u"009217259823014548361:lndtuqkycfu", "genius_api_key": "Ryq93pUGm8bM6eUWwD_M3NOFFDAtp2yEE7W" "76V-uFL5jks5dNvcGCdarqFjDhP9c", "fallback": None, "force": False, "sources": self.SOURCES, } ) self.config["bing_client_secret"].redact = True self.config["google_API_key"].redact = True self.config["google_engine_ID"].redact = True self.config["genius_api_key"].redact = True available_sources = list(self.SOURCES) sources = plugins.sanitize_choices(self.config["sources"].as_str_seq(), available_sources) if "google" in sources: if not self.config["google_API_key"].get(): # We log a *debug* message here because the default # configuration includes `google`. This way, the source # is silent by default but can be enabled just by # setting an API key. self._log.debug(u"Disabling google source: " u"no API key configured.") sources.remove("google") elif not HAS_BEAUTIFUL_SOUP: self._log.warning( u"To use the google lyrics source, you must " u"install the beautifulsoup4 module. See " u"the documentation for further details." ) sources.remove("google") self.config["bing_lang_from"] = [x.lower() for x in self.config["bing_lang_from"].as_str_seq()] self.bing_auth_token = None if not HAS_LANGDETECT and self.config["bing_client_secret"].get(): self._log.warning( u"To use bing translations, you need to " u"install the langdetect module. See the " u"documentation for further details." ) self.backends = [self.SOURCE_BACKENDS[source](self.config, self._log) for source in sources]
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add({ 'auto': True, 'bing_client_secret': None, 'bing_lang_from': [], 'bing_lang_to': None, 'google_API_key': None, 'google_engine_ID': u'009217259823014548361:lndtuqkycfu', 'genius_api_key': "Ryq93pUGm8bM6eUWwD_M3NOFFDAtp2yEE7W" "76V-uFL5jks5dNvcGCdarqFjDhP9c", 'fallback': None, 'force': False, 'sources': self.SOURCES, }) self.config['bing_client_secret'].redact = True self.config['google_API_key'].redact = True self.config['google_engine_ID'].redact = True self.config['genius_api_key'].redact = True available_sources = list(self.SOURCES) sources = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) if 'google' in sources: if not self.config['google_API_key'].get(): # We log a *debug* message here because the default # configuration includes `google`. This way, the source # is silent by default but can be enabled just by # setting an API key. self._log.debug(u'Disabling google source: ' u'no API key configured.') sources.remove('google') elif not HAS_BEAUTIFUL_SOUP: self._log.warning(u'To use the google lyrics source, you must ' u'install the beautifulsoup4 module. See ' u'the documentation for further details.') sources.remove('google') self.config['bing_lang_from'] = [ x.lower() for x in self.config['bing_lang_from'].as_str_seq()] self.bing_auth_token = None if not HAS_LANGDETECT and self.config['bing_client_secret'].get(): self._log.warning(u'To use bing translations, you need to ' u'install the langdetect module. See the ' u'documentation for further details.') self.backends = [self.SOURCE_BACKENDS[source](self.config, self._log) for source in sources]
def __init__(self): super(FetchArtPlugin, self).__init__() self.config.add({ 'auto': True, 'minwidth': 0, 'maxwidth': 0, 'enforce_ratio': False, 'remote_priority': False, 'cautious': False, 'cover_names': ['cover', 'front', 'art', 'album', 'folder'], 'sources': ['coverart', 'itunes', 'amazon', 'albumart'], 'google_key': None, 'google_engine': u'001442825323518660753:hrh5ch1gjzm', }) self.config['google_key'].redact = True # Holds paths to downloaded images between fetching them and # placing them in the filesystem. self.art_paths = {} self.minwidth = self.config['minwidth'].get(int) self.maxwidth = self.config['maxwidth'].get(int) self.enforce_ratio = self.config['enforce_ratio'].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') sources_name = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.sources = [ ART_SOURCES[s](self._log, self.config) for s in sources_name ] self.fs_source = FileSystem(self._log, self.config)
def __init__(self): super(FetchArtPlugin, self).__init__() self.config.add({ 'auto': True, 'minwidth': 0, 'maxwidth': 0, 'enforce_ratio': False, 'remote_priority': False, 'cautious': False, 'cover_names': ['cover', 'front', 'art', 'album', 'folder'], 'sources': ['coverart', 'itunes', 'amazon', 'albumart'], 'google_key': None, 'google_engine': u'001442825323518660753:hrh5ch1gjzm', 'fanarttv_key': None }) self.config['google_key'].redact = True self.config['fanarttv_key'].redact = True # Holds paths to downloaded images between fetching them and # placing them in the filesystem. self.art_paths = {} self.minwidth = self.config['minwidth'].get(int) self.maxwidth = self.config['maxwidth'].get(int) self.enforce_ratio = self.config['enforce_ratio'].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') if not self.config['fanarttv_key'].get() and \ u'fanarttv' in available_sources: self._log.warn( u'fanart.tv source enabled, but no personal API given. This ' u'works as of now, however, fanart.tv prefers users to ' u'register a personal key. Additionaly this makes new art ' u'available shorter after its upload. See the documentation.') sources_name = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.sources = [ART_SOURCES[s](self._log, self.config) for s in sources_name] self.fs_source = FileSystem(self._log, self.config)
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add({ 'auto': True, 'bing_client_secret': None, 'bing_lang_from': [], 'bing_lang_to': None, 'google_API_key': None, 'google_engine_ID': u'009217259823014548361:lndtuqkycfu', 'genius_api_key': "Ryq93pUGm8bM6eUWwD_M3NOFFDAtp2yEE7W" "76V-uFL5jks5dNvcGCdarqFjDhP9c", 'fallback': None, 'force': False, 'sources': self.SOURCES, }) self.config['bing_client_secret'].redact = True self.config['google_API_key'].redact = True self.config['google_engine_ID'].redact = True self.config['genius_api_key'].redact = True available_sources = list(self.SOURCES) if not self.config['google_API_key'].get() and \ 'google' in self.SOURCES: available_sources.remove('google') self.config['sources'] = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.backends = [ self.SOURCE_BACKENDS[key](self.config, self._log) for key in self.config['sources'].as_str_seq() ] self.config['bing_lang_from'] = [ x.lower() for x in self.config['bing_lang_from'].as_str_seq() ] self.bing_auth_token = None
def __init__(self): super(LyricsPlugin, self).__init__() self.import_stages = [self.imported] self.config.add({ 'auto': True, 'google_API_key': None, 'google_engine_ID': u'009217259823014548361:lndtuqkycfu', 'fallback': None, 'force': False, 'sources': self.SOURCES, }) available_sources = list(self.SOURCES) if not self.config['google_API_key'].get() and \ 'google' in self.SOURCES: available_sources.remove('google') self.config['sources'] = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) self.backends = [self.SOURCE_BACKENDS[key](self.config, self._log) for key in self.config['sources'].as_str_seq()]
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') sources_name = plugins.sanitize_choices( self.config['sources'].as_str_seq(), 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): try: sources_name.remove(u'filesystem') sources_name.append(u'filesystem') except ValueError: pass self.sources = [ART_SOURCES[s](self._log, self.config) for s in sources_name]
def test_sanitize_choices(self): self.assertEqual(plugins.sanitize_choices(['A', 'Z'], ('A', 'B')), ['A']) self.assertEqual(plugins.sanitize_choices(['A', 'A'], ('A')), ['A']) self.assertEqual(plugins.sanitize_choices(['D', '*', 'A'], ('A', 'B', 'C', 'D')), ['D', 'B', 'C', 'A'])