1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

implement context-manager to blacklist extractors

This commit is contained in:
Mike Fährmann 2017-05-24 12:32:44 +02:00
parent 30eef527d8
commit d2dceb35b7
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -78,7 +78,7 @@ def find(url):
"""Find suitable extractor for the given url"""
for pattern, klass in _list_patterns():
match = pattern.match(url)
if match:
if match and klass.category not in _blacklist:
return klass(match)
return None
@ -91,10 +91,23 @@ def extractors():
)
class blacklist():
"""Context Manager to blacklist extractor modules"""
def __init__(self, *categories):
self.categories = categories
def __enter__(self):
_blacklist.extend(self.categories)
def __exit__(self, etype, value, traceback):
_blacklist.clear()
# --------------------------------------------------------------------
# internals
_cache = []
_blacklist = []
_module_iter = iter(modules)