Fixed both Opensubtitles providers when searching for Superman & Lois (amp character issue)

pull/1315/head
morpheus65535 4 years ago
parent 91062335bc
commit da5b74516c

@ -18,7 +18,7 @@ from subliminal.providers.opensubtitles import OpenSubtitlesProvider as _OpenSub
from .mixins import ProviderRetryMixin from .mixins import ProviderRetryMixin
from subliminal.subtitle import fix_line_ending from subliminal.subtitle import fix_line_ending
from subliminal_patch.http import SubZeroRequestsTransport 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.cache import region
from subliminal_patch.score import framerate_equal from subliminal_patch.score import framerate_equal
from subzero.language import Language from subzero.language import Language
@ -28,6 +28,23 @@ from ..exceptions import TooManyRequests, APIThrottled
logger = logging.getLogger(__name__) 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): class OpenSubtitlesSubtitle(_OpenSubtitlesSubtitle):
hash_verifiable = True hash_verifiable = True
hearing_impaired_verifiable = True hearing_impaired_verifiable = True
@ -58,14 +75,14 @@ class OpenSubtitlesSubtitle(_OpenSubtitlesSubtitle):
# episode # episode
if isinstance(video, Episode) and self.movie_kind == 'episode': if isinstance(video, Episode) and self.movie_kind == 'episode':
# series # series
if video.series and (sanitize(self.series_name) in ( if fix_tv_naming(video.series) and (sanitize(self.series_name) in (
sanitize(name) for name in [video.series] + video.alternative_series)): sanitize(name) for name in [fix_tv_naming(video.series)] + video.alternative_series)):
matches.add('series') matches.add('series')
# movie # movie
elif isinstance(video, Movie) and self.movie_kind == 'movie': elif isinstance(video, Movie) and self.movie_kind == 'movie':
# title # title
if video.title and (sanitize(self.movie_name) in ( if fix_movie_naming(video.title) and (sanitize(self.movie_name) in (
sanitize(name) for name in [video.title] + video.alternative_titles)): sanitize(name) for name in [fix_movie_naming(video.title)] + video.alternative_titles)):
matches.add('title') matches.add('title')
sub_fps = None sub_fps = None

@ -17,6 +17,7 @@ from .mixins import ProviderRetryMixin
from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal_patch.subtitle import Subtitle, guess_matches
from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS
from subliminal_patch.providers import Provider from subliminal_patch.providers import Provider
from subliminal_patch.utils import fix_inconsistent_naming
from subliminal.cache import region from subliminal.cache import region
from guessit import guessit from guessit import guessit
@ -25,6 +26,23 @@ logger = logging.getLogger(__name__)
SHOW_EXPIRATION_TIME = datetime.timedelta(weeks=1).total_seconds() 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): class OpenSubtitlesComSubtitle(Subtitle):
provider_name = 'opensubtitlescom' provider_name = 'opensubtitlescom'
hash_verifiable = False hash_verifiable = False
@ -203,7 +221,7 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
else: else:
# loop over results # loop over results
for result in results_dict: 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'])): (not self.video.year or self.video.year == int(result['attributes']['year'])):
title_id = result['id'] title_id = result['id']
break break

Loading…
Cancel
Save