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 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:

View File

@ -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:

View File

@ -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
"""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