Fixed blacklisting of embedded subtitles on failed extraction.

This commit is contained in:
morpheus65535 2023-11-18 10:16:45 -05:00
parent 3da0445dc3
commit 7e650c2bab
3 changed files with 47 additions and 16 deletions

View File

@ -12,6 +12,7 @@ import requests
import traceback
import re
from subzero.language import Language
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \
MustGetBlacklisted, SearchLimitReached
from subliminal.providers.opensubtitles import DownloadLimitReached
@ -310,18 +311,25 @@ 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 get_blacklist
if exception.media_type == "series":
blacklist_log("", "", name, exception.id, "")
def _handle_mgb(name, exception, ids, language):
if language.forced:
language_str = f'{language.basename}:forced'
elif language.hi:
language_str = f'{language.basename}:hi'
else:
blacklist_log_movie("", name, exception.id, "")
language_str = language.basename
if ids:
if exception.media_type == "series":
if 'sonarrSeriesId' in ids and 'sonarrEpsiodeId' in ids:
blacklist_log(ids['sonarrSeriesId'], ids['sonarrEpisodeId'], name, exception.id, language_str)
else:
blacklist_log_movie(ids['radarrId'], name, exception.id, language_str)
def provider_throttle(name, exception):
if isinstance(exception, MustGetBlacklisted):
return _handle_mgb(name, exception)
def provider_throttle(name, exception, ids=None, language=None):
if isinstance(exception, MustGetBlacklisted) and isinstance(ids, dict) and isinstance(language, Language):
return _handle_mgb(name, exception, ids, language)
cls = getattr(exception, "__class__")
cls_name = getattr(cls, "__name__")

View File

@ -30,7 +30,9 @@ def refine_from_db(path, video):
TableEpisodes.video_codec,
TableEpisodes.audio_codec,
TableEpisodes.path,
TableShows.imdbId)
TableShows.imdbId,
TableEpisodes.sonarrSeriesId,
TableEpisodes.sonarrEpisodeId)
.select_from(TableEpisodes)
.join(TableShows)
.where((TableEpisodes.path == path_mappings.path_replace_reverse(path)))) \
@ -63,6 +65,9 @@ def refine_from_db(path, video):
if not video.audio_codec:
if data.audio_codec:
video.audio_codec = convert_to_guessit('audio_codec', data.audio_codec)
video.sonarrSeriesId = data.sonarrSeriesId
video.sonarrEpisodeId = data.sonarrEpisodeId
elif isinstance(video, Movie):
data = database.execute(
select(TableMovies.title,
@ -72,7 +77,8 @@ def refine_from_db(path, video):
TableMovies.resolution,
TableMovies.video_codec,
TableMovies.audio_codec,
TableMovies.imdbId)
TableMovies.imdbId,
TableMovies.radarrId)
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path))) \
.first()
@ -100,4 +106,6 @@ def refine_from_db(path, video):
if data.audio_codec:
video.audio_codec = convert_to_guessit('audio_codec', data.audio_codec)
video.radarrId = data.radarrId
return video

View File

@ -227,7 +227,7 @@ class SZProviderPool(ProviderPool):
self._born = time.time()
if not self.throttle_callback:
self.throttle_callback = lambda x, y: x
self.throttle_callback = lambda x, y, ids=None, language=None: x
#: Provider configuration
self.provider_configs = _ProviderConfigs(self)
@ -378,6 +378,10 @@ class SZProviderPool(ProviderPool):
if s.id in seen:
continue
s.radarrId = video.radarrId if hasattr(video, 'radarrId') else None
s.sonarrSeriesId = video.sonarrSeriesId if hasattr(video, 'sonarrSeriesId') else None
s.sonarrEpisodeId = video.sonarrEpisodeId if hasattr(video, 'sonarrEpisodeId') else None
s.plex_media_fps = float(video.fps) if video.fps else None
out.append(s)
seen.append(s.id)
@ -385,8 +389,13 @@ class SZProviderPool(ProviderPool):
return out
except Exception as e:
ids = {
'radarrId': video.radarrId if hasattr(video, 'radarrId') else None,
'sonarrSeriesId': video.sonarrSeriesId if hasattr(video, 'sonarrSeriesId') else None,
'sonarrEpisodeId': video.sonarrEpisodeId if hasattr(video, 'sonarrEpisodeId') else None,
}
logger.exception('Unexpected error in provider %r: %s', provider, traceback.format_exc())
self.throttle_callback(provider, e)
self.throttle_callback(provider, e, ids=ids, language=list(languages)[0] if len(languages) else None)
def list_subtitles(self, video, languages):
"""List subtitles.
@ -445,6 +454,12 @@ class SZProviderPool(ProviderPool):
logger.info('Downloading subtitle %r', subtitle)
tries = 0
ids = {
'radarrId': subtitle.radarrId if hasattr(subtitle, 'radarrId') else None,
'sonarrSeriesId': subtitle.sonarrSeriesId if hasattr(subtitle, 'sonarrSeriesId') else None,
'sonarrEpisodeId': subtitle.sonarrEpisodeId if hasattr(subtitle, 'sonarrEpisodeId') else None,
}
# retry downloading on failure until settings' download retry limit hit
while True:
tries += 1
@ -463,16 +478,16 @@ class SZProviderPool(ProviderPool):
requests.Timeout,
socket.timeout) as e:
logger.error('Provider %r connection error', subtitle.provider_name)
self.throttle_callback(subtitle.provider_name, e)
self.throttle_callback(subtitle.provider_name, e, ids=ids, language=subtitle.language)
except (rarfile.BadRarFile, MustGetBlacklisted) as e:
self.throttle_callback(subtitle.provider_name, e)
self.throttle_callback(subtitle.provider_name, e, ids=ids, language=subtitle.language)
return False
except Exception as e:
logger.exception('Unexpected error in provider %r, Traceback: %s', subtitle.provider_name,
traceback.format_exc())
self.throttle_callback(subtitle.provider_name, e)
self.throttle_callback(subtitle.provider_name, e, ids=ids, language=subtitle.language)
self.discarded_providers.add(subtitle.provider_name)
return False