From c72366d8834abfe4e8a320d264947090e3b8d1ca Mon Sep 17 00:00:00 2001 From: German Gutierrez Date: Mon, 24 Feb 2020 11:06:48 +0100 Subject: [PATCH] legendasdivx: using guessit to pick up the right sub in archive --- libs/subliminal_patch/providers/legendasdivx.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/subliminal_patch/providers/legendasdivx.py b/libs/subliminal_patch/providers/legendasdivx.py index a755fd6e4..36e0b7229 100644 --- a/libs/subliminal_patch/providers/legendasdivx.py +++ b/libs/subliminal_patch/providers/legendasdivx.py @@ -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)