Skip to content

Commit

Permalink
Add MustGetBlacklisted exception for redundant download_subtitle calls
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko98 committed Jan 1, 2022
1 parent b90dab0 commit 1261e91
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
16 changes: 14 additions & 2 deletions bazarr/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions libs/subliminal_patch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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
Expand Down Expand Up @@ -339,9 +340,8 @@ def download_subtitle(self, subtitle):
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:
Expand Down
18 changes: 16 additions & 2 deletions libs/subliminal_patch/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@

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

0 comments on commit 1261e91

Please sign in to comment.