From 1261e91870a6e08b1942c7a2fbcb74b19d0da4c9 Mon Sep 17 00:00:00 2001 From: Vitiko Date: Sat, 1 Jan 2022 19:18:40 -0400 Subject: [PATCH] Add MustGetBlacklisted exception for redundant download_subtitle calls --- bazarr/get_providers.py | 16 ++++++++++++++-- libs/subliminal_patch/core.py | 6 +++--- libs/subliminal_patch/exceptions.py | 18 ++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py index a7c99dbe2..48e7948f9 100644 --- a/bazarr/get_providers.py +++ b/bazarr/get_providers.py @@ -12,8 +12,8 @@ import requests from get_args import args from config import settings, get_array_from from event_handler import event_stream -from utils import get_binary -from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked +from utils import get_binary, blacklist_log, blacklist_log_movie +from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, MustGetBlacklisted from subliminal.providers.opensubtitles import DownloadLimitReached from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable 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): + if isinstance(exception, MustGetBlacklisted): + return _handle_mgb(name, exception) + cls = getattr(exception, "__class__") cls_name = getattr(cls, "__name__") if cls not in VALID_THROTTLE_EXCEPTIONS: diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index 9ed698c09..08415a3c5 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -25,6 +25,7 @@ from subliminal import ProviderError, refiner_manager from concurrent.futures import as_completed from .extensions import provider_registry +from .exceptions import MustGetBlacklisted from subliminal.exceptions import ServiceUnavailable, DownloadLimitExceeded from subliminal.score import compute_score as default_compute_score 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) self.throttle_callback(subtitle.provider_name, e) - except rarfile.BadRarFile: - logger.error('Malformed RAR file from provider %r, skipping subtitle.', subtitle.provider_name) - logger.debug("RAR Traceback: %s", traceback.format_exc()) + except (rarfile.BadRarFile, MustGetBlacklisted) as e: + self.throttle_callback(subtitle.provider_name, e) return False except Exception as e: diff --git a/libs/subliminal_patch/exceptions.py b/libs/subliminal_patch/exceptions.py index 6cd73e769..8b931425a 100644 --- a/libs/subliminal_patch/exceptions.py +++ b/libs/subliminal_patch/exceptions.py @@ -5,15 +5,29 @@ from subliminal import ProviderError class TooManyRequests(ProviderError): """Exception raised by providers when too many requests are made.""" + pass + class APIThrottled(ProviderError): pass + class ParseResponseError(ProviderError): """Exception raised by providers when they are not able to parse the response.""" + pass + class IPAddressBlocked(ProviderError): - """Exception raised when providers block requests from IP Address.""" - pass \ No newline at end of file + """Exception raised when providers block requests from IP Address.""" + + pass + + +class MustGetBlacklisted(ProviderError): + def __init__(self, id: str, media_type: str): + super().__init__() + + self.id = id + self.media_type = media_type