From 9f401cbb673f17a2f3aef7abff2fda3bb070e3bd Mon Sep 17 00:00:00 2001 From: Vitiko <59455966+vitiko98@users.noreply.github.com> Date: Sat, 15 May 2021 08:11:03 -0400 Subject: [PATCH] Fixed support for lists in audio_codec match guessing --- libs/subliminal_patch/subtitle.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libs/subliminal_patch/subtitle.py b/libs/subliminal_patch/subtitle.py index 7e1bbda91..f9a496029 100644 --- a/libs/subliminal_patch/subtitle.py +++ b/libs/subliminal_patch/subtitle.py @@ -410,6 +410,17 @@ MERGED_FORMATS = { MERGED_FORMATS_REV = dict((v.lower(), k.lower()) for k in MERGED_FORMATS for v in MERGED_FORMATS[k]) +def _has_match(video, guess, key) -> bool: + value = getattr(video, key) + if value is None: + return False + + guess_value = guess.get(key) + if isinstance(guess_value, list): + return any(value == item for item in guess_value) + + return value == guess_value + def guess_matches(video, guess, partial=False): """Get matches between a `video` and a `guess`. @@ -514,12 +525,11 @@ def guess_matches(video, guess, partial=False): logger.info("Release group matched but source didn't. Remnoving release group match.") matches.remove("release_group") - # video_codec - if video.video_codec and 'video_codec' in guess and guess['video_codec'] == video.video_codec: - matches.add('video_codec') - # audio_codec - if video.audio_codec and 'audio_codec' in guess and guess['audio_codec'] == video.audio_codec: - matches.add('audio_codec') + if _has_match(video, guess, "video_codec"): + matches.add("video_codec") + + if _has_match(video, guess, "audio_codec"): + matches.add("audio_codec") return matches