Add MustGetBlacklisted exception for redundant download_subtitle calls

This commit is contained in:
Vitiko 2022-01-01 19:18:40 -04:00
parent b90dab03e8
commit 1261e91870
3 changed files with 33 additions and 7 deletions

View file

@ -12,8 +12,8 @@ import requests
from get_args import args from get_args import args
from config import settings, get_array_from from config import settings, get_array_from
from event_handler import event_stream from event_handler import event_stream
from utils import get_binary from utils import get_binary, blacklist_log, blacklist_log_movie
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, MustGetBlacklisted
from subliminal.providers.opensubtitles import DownloadLimitReached from subliminal.providers.opensubtitles import DownloadLimitReached
from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable
from subliminal import region as subliminal_cache_region from subliminal import region as subliminal_cache_region
@ -210,7 +210,19 @@ def get_providers_auth():
} }
def _handle_mgb(name, exception):
# There's no way to get Radarr/Sonarr IDs from subliminal_patch. Blacklisted subtitles
# will not appear on fronted but they will work with utils.get_blacklist
if exception.media_type == "series":
blacklist_log("", "", name, exception.id, "")
else:
blacklist_log_movie("", name, exception.id, "")
def provider_throttle(name, exception): def provider_throttle(name, exception):
if isinstance(exception, MustGetBlacklisted):
return _handle_mgb(name, exception)
cls = getattr(exception, "__class__") cls = getattr(exception, "__class__")
cls_name = getattr(cls, "__name__") cls_name = getattr(cls, "__name__")
if cls not in VALID_THROTTLE_EXCEPTIONS: if cls not in VALID_THROTTLE_EXCEPTIONS:

View file

@ -25,6 +25,7 @@ from subliminal import ProviderError, refiner_manager
from concurrent.futures import as_completed from concurrent.futures import as_completed
from .extensions import provider_registry from .extensions import provider_registry
from .exceptions import MustGetBlacklisted
from subliminal.exceptions import ServiceUnavailable, DownloadLimitExceeded from subliminal.exceptions import ServiceUnavailable, DownloadLimitExceeded
from subliminal.score import compute_score as default_compute_score from subliminal.score import compute_score as default_compute_score
from subliminal.utils import hash_napiprojekt, hash_opensubtitles, hash_shooter, hash_thesubdb from subliminal.utils import hash_napiprojekt, hash_opensubtitles, hash_shooter, hash_thesubdb
@ -339,9 +340,8 @@ class SZProviderPool(ProviderPool):
logger.error('Provider %r connection error', subtitle.provider_name) logger.error('Provider %r connection error', subtitle.provider_name)
self.throttle_callback(subtitle.provider_name, e) self.throttle_callback(subtitle.provider_name, e)
except rarfile.BadRarFile: except (rarfile.BadRarFile, MustGetBlacklisted) as e:
logger.error('Malformed RAR file from provider %r, skipping subtitle.', subtitle.provider_name) self.throttle_callback(subtitle.provider_name, e)
logger.debug("RAR Traceback: %s", traceback.format_exc())
return False return False
except Exception as e: except Exception as e:

View file

@ -5,15 +5,29 @@ from subliminal import ProviderError
class TooManyRequests(ProviderError): class TooManyRequests(ProviderError):
"""Exception raised by providers when too many requests are made.""" """Exception raised by providers when too many requests are made."""
pass pass
class APIThrottled(ProviderError): class APIThrottled(ProviderError):
pass pass
class ParseResponseError(ProviderError): class ParseResponseError(ProviderError):
"""Exception raised by providers when they are not able to parse the response.""" """Exception raised by providers when they are not able to parse the response."""
pass pass
class IPAddressBlocked(ProviderError): class IPAddressBlocked(ProviderError):
"""Exception raised when providers block requests from IP Address.""" """Exception raised when providers block requests from IP Address."""
pass pass
class MustGetBlacklisted(ProviderError):
def __init__(self, id: str, media_type: str):
super().__init__()
self.id = id
self.media_type = media_type