diff options
author | morpheus65535 <[email protected]> | 2021-03-11 10:23:00 -0500 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2021-03-11 10:23:00 -0500 |
commit | da5b74516c98ae646d78a4fa37bb60c4a2054868 (patch) | |
tree | 63b33a39d897b0d0438df56f00474f6df891b39c /libs | |
parent | 91062335bcb92f252ac82bcf0c1f18c38e5c85b4 (diff) | |
download | bazarr-da5b74516c98ae646d78a4fa37bb60c4a2054868.tar.gz bazarr-da5b74516c98ae646d78a4fa37bb60c4a2054868.zip |
Fixed both Opensubtitles providers when searching for Superman & Lois (amp character issue)
Diffstat (limited to 'libs')
-rw-r--r-- | libs/subliminal_patch/providers/opensubtitles.py | 27 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/opensubtitlescom.py | 20 |
2 files changed, 41 insertions, 6 deletions
diff --git a/libs/subliminal_patch/providers/opensubtitles.py b/libs/subliminal_patch/providers/opensubtitles.py index a2be069f1..6973f845c 100644 --- a/libs/subliminal_patch/providers/opensubtitles.py +++ b/libs/subliminal_patch/providers/opensubtitles.py @@ -18,7 +18,7 @@ from subliminal.providers.opensubtitles import OpenSubtitlesProvider as _OpenSub from .mixins import ProviderRetryMixin from subliminal.subtitle import fix_line_ending from subliminal_patch.http import SubZeroRequestsTransport -from subliminal_patch.utils import sanitize +from subliminal_patch.utils import sanitize, fix_inconsistent_naming from subliminal.cache import region from subliminal_patch.score import framerate_equal from subzero.language import Language @@ -28,6 +28,23 @@ from ..exceptions import TooManyRequests, APIThrottled logger = logging.getLogger(__name__) +def fix_tv_naming(title): + """Fix TV show titles with inconsistent naming using dictionary, but do not sanitize them. + + :param str title: original title. + :return: new title. + :rtype: str + + """ + return fix_inconsistent_naming(title, {"Superman & Lois": "Superman and Lois", + }, True) + + +def fix_movie_naming(title): + return fix_inconsistent_naming(title, { + }, True) + + class OpenSubtitlesSubtitle(_OpenSubtitlesSubtitle): hash_verifiable = True hearing_impaired_verifiable = True @@ -58,14 +75,14 @@ class OpenSubtitlesSubtitle(_OpenSubtitlesSubtitle): # episode if isinstance(video, Episode) and self.movie_kind == 'episode': # series - if video.series and (sanitize(self.series_name) in ( - sanitize(name) for name in [video.series] + video.alternative_series)): + if fix_tv_naming(video.series) and (sanitize(self.series_name) in ( + sanitize(name) for name in [fix_tv_naming(video.series)] + video.alternative_series)): matches.add('series') # movie elif isinstance(video, Movie) and self.movie_kind == 'movie': # title - if video.title and (sanitize(self.movie_name) in ( - sanitize(name) for name in [video.title] + video.alternative_titles)): + if fix_movie_naming(video.title) and (sanitize(self.movie_name) in ( + sanitize(name) for name in [fix_movie_naming(video.title)] + video.alternative_titles)): matches.add('title') sub_fps = None diff --git a/libs/subliminal_patch/providers/opensubtitlescom.py b/libs/subliminal_patch/providers/opensubtitlescom.py index 0ca62eed0..c3d6a5b8d 100644 --- a/libs/subliminal_patch/providers/opensubtitlescom.py +++ b/libs/subliminal_patch/providers/opensubtitlescom.py @@ -17,6 +17,7 @@ from .mixins import ProviderRetryMixin from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS from subliminal_patch.providers import Provider +from subliminal_patch.utils import fix_inconsistent_naming from subliminal.cache import region from guessit import guessit @@ -25,6 +26,23 @@ logger = logging.getLogger(__name__) SHOW_EXPIRATION_TIME = datetime.timedelta(weeks=1).total_seconds() +def fix_tv_naming(title): + """Fix TV show titles with inconsistent naming using dictionary, but do not sanitize them. + + :param str title: original title. + :return: new title. + :rtype: str + + """ + return fix_inconsistent_naming(title, {"Superman & Lois": "Superman and Lois", + }, True) + + +def fix_movie_naming(title): + return fix_inconsistent_naming(title, { + }, True) + + class OpenSubtitlesComSubtitle(Subtitle): provider_name = 'opensubtitlescom' hash_verifiable = False @@ -203,7 +221,7 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider): else: # loop over results for result in results_dict: - if title.lower() == result['attributes']['title'].lower() and \ + if fix_tv_naming(title).lower() == result['attributes']['title'].lower() and \ (not self.video.year or self.video.year == int(result['attributes']['year'])): title_id = result['id'] break |