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 traceback
import re import re
from subzero.language import Language
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \ from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \
MustGetBlacklisted, SearchLimitReached MustGetBlacklisted, SearchLimitReached
from subliminal.providers.opensubtitles import DownloadLimitReached from subliminal.providers.opensubtitles import DownloadLimitReached
@ -310,18 +311,25 @@ def get_providers_auth():
} }
def _handle_mgb(name, exception): def _handle_mgb(name, exception, ids, language):
# There's no way to get Radarr/Sonarr IDs from subliminal_patch. Blacklisted subtitles if language.forced:
# will not appear on fronted but they will work with get_blacklist language_str = f'{language.basename}:forced'
if exception.media_type == "series": elif language.hi:
blacklist_log("", "", name, exception.id, "") language_str = f'{language.basename}:hi'
else: 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): def provider_throttle(name, exception, ids=None, language=None):
if isinstance(exception, MustGetBlacklisted): if isinstance(exception, MustGetBlacklisted) and isinstance(ids, dict) and isinstance(language, Language):
return _handle_mgb(name, exception) return _handle_mgb(name, exception, ids, language)
cls = getattr(exception, "__class__") cls = getattr(exception, "__class__")
cls_name = getattr(cls, "__name__") cls_name = getattr(cls, "__name__")

View File

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

View File

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