From 36abccfea9c72940643fe21c029a3886ab3ab9f4 Mon Sep 17 00:00:00 2001 From: Rato Date: Sun, 29 Jan 2017 22:40:10 +0100 Subject: [PATCH 1/2] Detect hardcoded subtitles. Fix for #318 --- docs/properties.rst | 2 +- guessit/rules/properties/other.py | 27 ++++++++++++++++++++++++++- guessit/test/episodes.yml | 12 ++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/properties.rst b/docs/properties.rst index abe0a9e1..38a97a3d 100644 --- a/docs/properties.rst +++ b/docs/properties.rst @@ -256,5 +256,5 @@ Other properties - ``Fansub``, ``HR``, ``HQ``, ``Screener``, ``Unrated``, ``HD``, ``3D``, ``SyncFix``, ``Bonus``, ``WideScreen``, ``Fastsub``, ``R5``, ``AudioFix``, ``DDC``, ``Trailer``, ``Complete``, ``Limited``, ``Classic``, ``Proper``, ``DualAudio``, ``LiNE``, ``LD``, ``MD``, ``XXX``, ``Remastered``, ``Extended``, ``Extended Cut``, - ``Uncut``, ``Retail``, ``ReEncoded``, ``Mux`` + ``Uncut``, ``Retail``, ``ReEncoded``, ``Mux``, ``Hardcoded Subtitles`` diff --git a/guessit/rules/properties/other.py b/guessit/rules/properties/other.py index bd7620cb..f23a234d 100644 --- a/guessit/rules/properties/other.py +++ b/guessit/rules/properties/other.py @@ -78,9 +78,10 @@ def validate_complete(match): tags=['other.validate.screener', 'format-prefix', 'format-suffix']) rebulk.string('Mux', value='Mux', validator=seps_after, tags=['other.validate.mux', 'video-codec-prefix', 'format-suffix']) + rebulk.string('HC', value='Hardcoded Subtitles') rebulk.rules(ValidateHasNeighbor, ValidateHasNeighborAfter, ValidateHasNeighborBefore, ValidateScreenerRule, - ValidateMuxRule, ProperCountRule) + ValidateMuxRule, ValidateHardcodedSubs, ProperCountRule) return rebulk @@ -200,3 +201,27 @@ def when(self, matches, context): if not format_match: ret.append(mux) return ret + + +class ValidateHardcodedSubs(Rule): + """Validate HC matches.""" + + priority = 32 + consequence = RemoveMatch + + def when(self, matches, context): + to_remove = [] + for hc in matches.named('other', predicate=lambda match: match.value == 'Hardcoded Subtitles'): + next_match = matches.next(hc, predicate=lambda match: match.name == 'subtitle_language', index=0) + if next_match and not matches.holes(hc.end, next_match.start, + predicate=lambda match: match.value.strip(seps)): + continue + + previous_match = matches.previous(hc, predicate=lambda match: match.name == 'subtitle_language', index=0) + if previous_match and not matches.holes(previous_match.end, hc.start, + predicate=lambda match: match.value.strip(seps)): + continue + + to_remove.append(hc) + + return to_remove diff --git a/guessit/test/episodes.yml b/guessit/test/episodes.yml index fc48c64b..3bdec915 100644 --- a/guessit/test/episodes.yml +++ b/guessit/test/episodes.yml @@ -2901,3 +2901,15 @@ video_codec: h264 release_group: CasStudio type: episode + +# Hardcoded subtitles +? Show.Name.S06E16.HC.SWESUB.HDTV.x264 +: title: Show Name + season: 6 + episode: 16 + other: Hardcoded Subtitles + format: HDTV + video_codec: h264 + subtitle_language: sv + type: episode + From d0c845b91f4071e1618f3eebd4cd21b24f25c28c Mon Sep 17 00:00:00 2001 From: Rato Date: Sun, 29 Jan 2017 22:53:50 +0100 Subject: [PATCH 2/2] Pylint fixes --- guessit/rules/properties/other.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/guessit/rules/properties/other.py b/guessit/rules/properties/other.py index f23a234d..9c1a2733 100644 --- a/guessit/rules/properties/other.py +++ b/guessit/rules/properties/other.py @@ -211,17 +211,18 @@ class ValidateHardcodedSubs(Rule): def when(self, matches, context): to_remove = [] - for hc in matches.named('other', predicate=lambda match: match.value == 'Hardcoded Subtitles'): - next_match = matches.next(hc, predicate=lambda match: match.name == 'subtitle_language', index=0) - if next_match and not matches.holes(hc.end, next_match.start, + for hc_match in matches.named('other', predicate=lambda match: match.value == 'Hardcoded Subtitles'): + next_match = matches.next(hc_match, predicate=lambda match: match.name == 'subtitle_language', index=0) + if next_match and not matches.holes(hc_match.end, next_match.start, predicate=lambda match: match.value.strip(seps)): continue - previous_match = matches.previous(hc, predicate=lambda match: match.name == 'subtitle_language', index=0) - if previous_match and not matches.holes(previous_match.end, hc.start, + previous_match = matches.previous(hc_match, + predicate=lambda match: match.name == 'subtitle_language', index=0) + if previous_match and not matches.holes(previous_match.end, hc_match.start, predicate=lambda match: match.value.strip(seps)): continue - to_remove.append(hc) + to_remove.append(hc_match) return to_remove