mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-03-06 11:49:29 +08:00
no log: small subliminal_patch's core refactor
Try to make some methods more readable
This commit is contained in:
parent
23a5ab9b0e
commit
4edc2b756b
1 changed files with 39 additions and 15 deletions
|
@ -111,6 +111,36 @@ class _ProviderConfigs(dict):
|
||||||
return super().update(items)
|
return super().update(items)
|
||||||
|
|
||||||
|
|
||||||
|
class _Banlist:
|
||||||
|
def __init__(self, must_not_contain, must_contain):
|
||||||
|
self.must_not_contain = must_not_contain
|
||||||
|
self.must_contain = must_contain
|
||||||
|
|
||||||
|
def is_valid(self, subtitle):
|
||||||
|
if subtitle.release_info is None:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if any([x for x in self.must_not_contain
|
||||||
|
if re.search(x, subtitle.release_info, flags=re.IGNORECASE) is not None]):
|
||||||
|
logger.info("Skipping subtitle because release name contains prohibited string: %s", subtitle)
|
||||||
|
return False
|
||||||
|
if any([x for x in self.must_contain
|
||||||
|
if re.search(x, subtitle.release_info, flags=re.IGNORECASE) is None]):
|
||||||
|
logger.info("Skipping subtitle because release name does not contains required string: %s", subtitle)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class _Blacklist(list):
|
||||||
|
def is_valid(self, provider, subtitle):
|
||||||
|
blacklisted = not (str(provider), str(subtitle.id)) in self
|
||||||
|
if blacklisted:
|
||||||
|
logger.debug("Skipping blacklisted subtitle: %s", subtitle)
|
||||||
|
|
||||||
|
return blacklisted
|
||||||
|
|
||||||
|
|
||||||
class SZProviderPool(ProviderPool):
|
class SZProviderPool(ProviderPool):
|
||||||
def __init__(self, providers=None, provider_configs=None, blacklist=None, ban_list=None, throttle_callback=None,
|
def __init__(self, providers=None, provider_configs=None, blacklist=None, ban_list=None, throttle_callback=None,
|
||||||
pre_download_hook=None, post_download_hook=None, language_hook=None):
|
pre_download_hook=None, post_download_hook=None, language_hook=None):
|
||||||
|
@ -123,10 +153,10 @@ class SZProviderPool(ProviderPool):
|
||||||
#: Discarded providers
|
#: Discarded providers
|
||||||
self.discarded_providers = set()
|
self.discarded_providers = set()
|
||||||
|
|
||||||
self.blacklist = blacklist or []
|
self.blacklist = _Blacklist(blacklist or [])
|
||||||
|
|
||||||
#: Should be a dict of 2 lists of strings
|
#: Should be a dict of 2 lists of strings
|
||||||
self.ban_list = ban_list or {'must_contain': [], 'must_not_contain': []}
|
self.ban_list = _Banlist(**(ban_list or {'must_contain': [], 'must_not_contain': []}))
|
||||||
|
|
||||||
self.throttle_callback = throttle_callback
|
self.throttle_callback = throttle_callback
|
||||||
|
|
||||||
|
@ -175,8 +205,8 @@ class SZProviderPool(ProviderPool):
|
||||||
# self.provider_configs = provider_configs
|
# self.provider_configs = provider_configs
|
||||||
self.provider_configs.update(provider_configs)
|
self.provider_configs.update(provider_configs)
|
||||||
|
|
||||||
self.blacklist = blacklist or []
|
self.blacklist = _Blacklist(blacklist or [])
|
||||||
self.ban_list = ban_list or {'must_contain': [], 'must_not_contain': []}
|
self.ban_list = _Banlist(**ban_list or {'must_contain': [], 'must_not_contain': []})
|
||||||
|
|
||||||
return updated
|
return updated
|
||||||
|
|
||||||
|
@ -267,18 +297,12 @@ class SZProviderPool(ProviderPool):
|
||||||
seen = []
|
seen = []
|
||||||
out = []
|
out = []
|
||||||
for s in results:
|
for s in results:
|
||||||
if (str(provider), str(s.id)) in self.blacklist:
|
if not self.blacklist.is_valid(provider, s):
|
||||||
logger.info("Skipping blacklisted subtitle: %s", s)
|
|
||||||
continue
|
continue
|
||||||
if s.release_info is not None:
|
|
||||||
if any([x for x in self.ban_list["must_not_contain"]
|
if not self.ban_list.is_valid(s):
|
||||||
if re.search(x, s.release_info, flags=re.IGNORECASE) is not None]):
|
continue
|
||||||
logger.info("Skipping subtitle because release name contains prohibited string: %s", s)
|
|
||||||
continue
|
|
||||||
if any([x for x in self.ban_list["must_contain"]
|
|
||||||
if re.search(x, s.release_info, flags=re.IGNORECASE) is None]):
|
|
||||||
logger.info("Skipping subtitle because release name does not contains required string: %s", s)
|
|
||||||
continue
|
|
||||||
if s.id in seen:
|
if s.id in seen:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue