legendasdivx: using guessit to pick up the right sub in archive

This commit is contained in:
German Gutierrez 2020-02-24 11:06:48 +01:00
parent fafeffcfe5
commit c72366d883
1 changed files with 11 additions and 2 deletions

View File

@ -274,7 +274,7 @@ class LegendasdivxProvider(Provider):
archive = self._get_archive(res.content)
# extract the subtitle
subtitle_content = self._get_subtitle_from_archive(archive)
subtitle_content = self._get_subtitle_from_archive(archive, subtitle)
subtitle.content = fix_line_ending(subtitle_content)
subtitle.normalize()
@ -297,7 +297,7 @@ class LegendasdivxProvider(Provider):
return archive
def _get_subtitle_from_archive(self, archive):
def _get_subtitle_from_archive(self, archive, subtitle):
# some files have a non subtitle with .txt extension
_tmp = list(SUBTITLE_EXTENSIONS)
_tmp.remove('.txt')
@ -312,6 +312,15 @@ class LegendasdivxProvider(Provider):
if not name.lower().endswith(_subtitle_extensions):
continue
if isinstance(subtitle.video, Episode):
logger.debug ("guessing %s" % name)
guess = guessit(name)
logger.debug("subtitle S{}E{} video S{}E{}".format(guess['season'],guess['episode'],subtitle.video.season,subtitle.video.episode))
if subtitle.video.episode != guess['episode'] or subtitle.video.season != guess['season']:
logger.debug('subtitle does not match video, skipping')
continue
logger.debug("returning from archive: %s" % name)
return archive.read(name)