Skip to content

Commit

Permalink
Improve episode detection from compressed series packs
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko98 committed Apr 16, 2022
1 parent 31e4f83 commit 75f3ac9
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions libs/subliminal_patch/providers/mixins.py
Expand Up @@ -77,8 +77,11 @@ def get_subtitle_from_archive(self, subtitle, archive):
if len(subs_in_archive) == 1:
matching_sub = subs_in_archive[0]
else:
logger.debug("Subtitles in archive: %s", subs_in_archive)

for sub_name in subs_in_archive:
guess = guessit(sub_name)

sub_name_lower = sub_name.lower()

# consider subtitle valid if:
Expand All @@ -94,9 +97,12 @@ def get_subtitle_from_archive(self, subtitle, archive):
continue

episodes = guess.get("episode")
if is_episode and episodes and not isinstance(episodes, list):

if not isinstance(episodes, list):
episodes = [episodes]

episode_matches = episodes is not None and any(subtitle.episode == epi for epi in episodes)

if not is_episode or (
(
subtitle.episode in episodes
Expand Down Expand Up @@ -139,7 +145,11 @@ def get_subtitle_from_archive(self, subtitle, archive):
if asked_for_rlsgrp in sub_name_lower:
release_group_matches = True

if release_group_matches and source_matches:
if not is_episode and release_group_matches and source_matches:
matching_sub = sub_name
break

if is_episode and episode_matches:
matching_sub = sub_name
break

Expand All @@ -148,10 +158,14 @@ def get_subtitle_from_archive(self, subtitle, archive):
else:
subs_fallback.append(sub_name)


if not matching_sub and not subs_unsure and not subs_fallback:
logger.error("None of expected subtitle found in archive")
return

elif matching_sub:
logger.debug("Matched subtitle found: %s", matching_sub)

elif subs_unsure:
matching_sub = subs_unsure[0]

Expand Down

0 comments on commit 75f3ac9

Please sign in to comment.