mirror of
https://github.com/zoriya/guessit.git
synced 2026-06-09 12:51:24 +00:00
Add more episode tests along with small fixes
This commit is contained in:
@@ -10,7 +10,18 @@ def marker_comparator_predicate(match):
|
||||
"""
|
||||
Match predicate used in comparator
|
||||
"""
|
||||
return not match.private and match.name not in ['extension', 'properCount']
|
||||
return not match.private and \
|
||||
match.name not in ['extension', 'properCount', 'title', 'episodeTitle', 'alternativeTitle']
|
||||
|
||||
|
||||
def marker_weight(matches, marker):
|
||||
"""
|
||||
Compute the comparator weight of a marker
|
||||
:param matches:
|
||||
:param marker:
|
||||
:return:
|
||||
"""
|
||||
return len(set(match.name for match in matches.range(*marker.span, predicate=marker_comparator_predicate)))
|
||||
|
||||
|
||||
def marker_comparator(matches, markers):
|
||||
@@ -28,8 +39,7 @@ def marker_comparator(matches, markers):
|
||||
"""
|
||||
The actual comparator function.
|
||||
"""
|
||||
matches_count = len(matches.range(*marker2.span, predicate=marker_comparator_predicate)) - \
|
||||
len(matches.range(*marker1.span, predicate=marker_comparator_predicate))
|
||||
matches_count = marker_weight(matches, marker2) - marker_weight(matches, marker1)
|
||||
if matches_count:
|
||||
return matches_count
|
||||
len_diff = len(marker2) - len(marker1)
|
||||
|
||||
@@ -75,10 +75,10 @@ class EpisodeTitleFromPosition(TitleBaseRule):
|
||||
return True
|
||||
return super(EpisodeTitleFromPosition, self).is_ignored(match)
|
||||
|
||||
def should_keep(self, match, to_keep, matches, filepart, hole):
|
||||
def should_keep(self, match, to_keep, matches, filepart, hole, starting):
|
||||
if match.name == 'episodeDetails' and not matches.previous(match, lambda match: match.name == 'season'):
|
||||
return True, False # Keep episodeDetails, but don't crop title.
|
||||
return super(EpisodeTitleFromPosition, self).should_keep(match, to_keep, matches, filepart, hole)
|
||||
return super(EpisodeTitleFromPosition, self).should_keep(match, to_keep, matches, filepart, hole, starting)
|
||||
|
||||
def __init__(self):
|
||||
super(EpisodeTitleFromPosition, self).__init__('episodeTitle', ['title'])
|
||||
|
||||
@@ -73,26 +73,26 @@ EPISODES.defaults(validate_all=True, validator={'__parent__': seps_surround}, ch
|
||||
# 12, 13
|
||||
EPISODES.regex(r'(?P<episodeNumber>\d{2})' +
|
||||
r'(?:v(?P<version>\d+))?' +
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])(<?P<episodeNumber>\d{2}))*',
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])(?P<episodeNumber>\d{2}))*',
|
||||
tags=['bonus-conflict', 'weak-movie'], formatter={'episodeNumber': int, 'version': int})
|
||||
|
||||
# 012, 013
|
||||
EPISODES.regex(r'0(?P<episodeNumber>\d{1,2})' +
|
||||
r'(?:v(?P<version>\d+))?' +
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])0(<?P<episodeNumber>\d{1,2}))*',
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])0(?P<episodeNumber>\d{1,2}))*',
|
||||
tags=['bonus-conflict', 'weak-movie'], formatter={'episodeNumber': int, 'version': int})
|
||||
|
||||
# 112, 113
|
||||
EPISODES.regex(r'(?P<episodeNumber>\d{3,4})' +
|
||||
r'(?:v(?P<version>\d+))?' +
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])(<?P<episodeNumber>\d{3,4}))*',
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])(?P<episodeNumber>\d{3,4}))*',
|
||||
tags=['bonus-conflict', 'weak-movie'], formatter={'episodeNumber': int, 'version': int},
|
||||
disabled=lambda context: not context.get('episode_prefer_number', False))
|
||||
|
||||
# 1, 2, 3
|
||||
EPISODES.regex(r'(?P<episodeNumber>\d)' +
|
||||
r'(?:v(?P<version>\d+))?' +
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])(<?P<episodeNumber>\d{1,2}))*',
|
||||
r'(?:(?P<episodeNumberSeparator>[x-])(?P<episodeNumber>\d{1,2}))*',
|
||||
tags=['bonus-conflict', 'weak-movie'], formatter={'episodeNumber': int, 'version': int},
|
||||
disabled=lambda context: not context.get('episode_prefer_number', False))
|
||||
|
||||
@@ -269,6 +269,37 @@ class EpisodeDetailValidator(Rule):
|
||||
return ret
|
||||
|
||||
|
||||
class RemoveDetachedEpisodeNumber(Rule):
|
||||
"""
|
||||
If multiple episodeNumber are found, remove those that are not detached from a range and less than 10.
|
||||
|
||||
Fairy Tail 2 - 16-20, 2 should be removed.
|
||||
"""
|
||||
priority = 64
|
||||
consequence = RemoveMatch
|
||||
dependency = [RemoveWeakIfSxxExx, RemoveWeakDuplicate]
|
||||
|
||||
def when(self, matches, context):
|
||||
ret = []
|
||||
|
||||
episode_numbers = []
|
||||
episode_values = set()
|
||||
for match in matches.named('episodeNumber', lambda match: not match.private and 'weak-movie' in match.tags):
|
||||
if match.value not in episode_values:
|
||||
episode_numbers.append(match)
|
||||
episode_values.add(match.value)
|
||||
|
||||
episode_numbers = list(sorted(episode_numbers, key=lambda match: match.value))
|
||||
if len(episode_numbers) > 1 and \
|
||||
episode_numbers[0].value < 10 and \
|
||||
episode_numbers[1].value - episode_numbers[0].value != 1:
|
||||
parent = episode_numbers[0]
|
||||
while parent: # TODO: Add a feature in rebulk to avoid this ...
|
||||
ret.append(parent)
|
||||
parent = parent.parent
|
||||
return ret
|
||||
|
||||
|
||||
class VersionValidator(Rule):
|
||||
"""
|
||||
Validate version if previous match is episodeNumber or if surrounded by separators.
|
||||
@@ -285,5 +316,5 @@ class VersionValidator(Rule):
|
||||
ret.append(version)
|
||||
return ret
|
||||
|
||||
EPISODES.rules(RemoveWeakIfMovie, RemoveWeakIfSxxExx, RemoveWeakDuplicate, EpisodeDetailValidator, VersionValidator,
|
||||
CountValidator)
|
||||
EPISODES.rules(RemoveWeakIfMovie, RemoveWeakIfSxxExx, RemoveWeakDuplicate, EpisodeDetailValidator,
|
||||
RemoveDetachedEpisodeNumber, VersionValidator, CountValidator)
|
||||
|
||||
@@ -74,7 +74,7 @@ class TitleBaseRule(Rule):
|
||||
"""
|
||||
return match.name in ['language', 'country']
|
||||
|
||||
def should_keep(self, match, to_keep, matches, filepart, hole):
|
||||
def should_keep(self, match, to_keep, matches, filepart, hole, starting):
|
||||
"""
|
||||
Check if this match should be accepted when ending or starting a hole.
|
||||
:param match:
|
||||
@@ -87,13 +87,12 @@ class TitleBaseRule(Rule):
|
||||
:type hole: Match
|
||||
:param hole: the hole match
|
||||
:type hole: Match
|
||||
:param starting: true if match is starting the hole
|
||||
:type starting: bool
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
# Keep language if other languages exists in the filepart and if not a code.
|
||||
if match.name == 'language' and len(match) <= 3:
|
||||
return True
|
||||
|
||||
# Keep language if other languages exists in the filepart.
|
||||
outside_matches = filepart.crop(hole)
|
||||
other_languages = []
|
||||
for outside in outside_matches:
|
||||
@@ -133,7 +132,7 @@ class TitleBaseRule(Rule):
|
||||
# pylint:disable=undefined-loop-variable
|
||||
trailing = matches.chain_before(hole.end, seps, predicate=lambda match: match == ignored_match)
|
||||
if trailing:
|
||||
should_keep = self.should_keep(ignored_match, to_keep, matches, filepart, hole)
|
||||
should_keep = self.should_keep(ignored_match, to_keep, matches, filepart, hole, False)
|
||||
if should_keep:
|
||||
# pylint:disable=unpacking-non-sequence
|
||||
try:
|
||||
@@ -149,7 +148,7 @@ class TitleBaseRule(Rule):
|
||||
if ignored_match not in to_keep:
|
||||
starting = matches.chain_after(hole.start, seps, predicate=lambda match: match == ignored_match)
|
||||
if starting:
|
||||
should_keep = self.should_keep(ignored_match, to_keep, matches, filepart, hole)
|
||||
should_keep = self.should_keep(ignored_match, to_keep, matches, filepart, hole, True)
|
||||
if should_keep:
|
||||
# pylint:disable=unpacking-non-sequence
|
||||
try:
|
||||
|
||||
@@ -1536,3 +1536,118 @@
|
||||
screenSize: 720p
|
||||
title: Oniichan no Koto Nanka Zenzen Suki Janain Dakara ne
|
||||
videoCodec: h264
|
||||
|
||||
# TODO: Add support for absolute episodes
|
||||
? Bleach - s16e03-04 - 313-314
|
||||
? Bleach.s16e03-04.313-314
|
||||
? Bleach.s16e03-04.313-314
|
||||
? Bleach - s16e03-04 - 313-314
|
||||
? Bleach.s16e03-04.313-314
|
||||
? Bleach s16e03e04 313-314
|
||||
: episodeNumber: [3, 4]
|
||||
season: 16
|
||||
title: Bleach
|
||||
|
||||
? Bleach - 313-314
|
||||
: options: -E
|
||||
episodeNumber: [313, 314]
|
||||
title: Bleach
|
||||
|
||||
? '[ShinBunBu-Subs] Bleach - 02-03 (CX 1280x720 x264 AAC)'
|
||||
: audioCodec: AAC
|
||||
episodeNumber: [2, 3]
|
||||
releaseGroup: ShinBunBu-Subs
|
||||
screenSize: 720p
|
||||
title: Bleach
|
||||
videoCodec: h264
|
||||
|
||||
? 003. Show Name - Ep Name.avi
|
||||
: episodeNumber: 3
|
||||
title: Show Name
|
||||
episodeTitle: Ep Name
|
||||
|
||||
? 003-004. Show Name - Ep Name.avi
|
||||
: episodeNumber: [3, 4]
|
||||
title: Show Name
|
||||
episodeTitle: Ep Name
|
||||
|
||||
? One Piece - 102
|
||||
: episodeNumber: 2
|
||||
season: 1
|
||||
title: One Piece
|
||||
|
||||
? "[ACX]_Wolf's_Spirit_001.mkv"
|
||||
: episodeNumber: 1
|
||||
releaseGroup: ACX
|
||||
title: "Wolf's Spirit"
|
||||
|
||||
? Project.Runway.S14E00.and.S14E01.(Eng.Subs).SDTV.x264-[2Maverick].mp4
|
||||
: episodeNumber: [0, 1]
|
||||
format: TV
|
||||
releaseGroup: 2Maverick
|
||||
season: 14
|
||||
title: Project Runway
|
||||
subtitleLanguage: en
|
||||
videoCodec: h264
|
||||
|
||||
? '[Hatsuyuki-Kaitou]_Fairy_Tail_2_-_16-20_[720p][10bit].torrent'
|
||||
: episodeNumber: [16, 17, 18, 19, 20]
|
||||
releaseGroup: Hatsuyuki-Kaitou
|
||||
screenSize: 720p
|
||||
title: Fairy Tail 2
|
||||
videoProfile: 10bit
|
||||
|
||||
? '[Hatsuyuki-Kaitou]_Fairy_Tail_2_-_16-20_(191-195)_[720p][10bit].torrent'
|
||||
: options: -E
|
||||
episodeNumber: [16, 17, 18, 19, 20, 191, 192, 193, 194, 195]
|
||||
releaseGroup: Hatsuyuki-Kaitou
|
||||
screenSize: 720p
|
||||
title: Fairy Tail 2
|
||||
|
||||
? "Looney Tunes 1940x01 Porky's Last Stand.mkv"
|
||||
: episodeNumber: 1
|
||||
season: 1940
|
||||
title: Looney Tunes
|
||||
episodeTitle: Porky's Last Stand
|
||||
year: 1940
|
||||
|
||||
? The.Good.Wife.S06E01.E10.720p.WEB-DL.DD5.1.H.264-CtrlHD/The.Good.Wife.S06E09.Trust.Issues.720p.WEB-DL.DD5.1.H.264-CtrlHD.mkv
|
||||
: audioChannels: '5.1'
|
||||
audioCodec: DolbyDigital
|
||||
episodeNumber: 9
|
||||
format: WEB-DL
|
||||
releaseGroup: CtrlHD
|
||||
screenSize: 720p
|
||||
season: 6
|
||||
title: The Good Wife
|
||||
episodeTitle: Trust Issues
|
||||
videoCodec: h264
|
||||
|
||||
? Fear the Walking Dead - 01x02 - So Close, Yet So Far.REPACK-KILLERS.French.C.updated.Addic7ed.com.mkv
|
||||
: episodeNumber: 2
|
||||
language: fr
|
||||
other: Proper
|
||||
properCount: 1
|
||||
season: 1
|
||||
title: Fear the Walking Dead
|
||||
episodeTitle: So Close, Yet So Far
|
||||
|
||||
? Fear the Walking Dead - 01x02 - En Close, Yet En Far.REPACK-KILLERS.French.C.updated.Addic7ed.com.mkv
|
||||
: episodeNumber: 2
|
||||
language: fr
|
||||
other: Proper
|
||||
properCount: 1
|
||||
season: 1
|
||||
title: Fear the Walking Dead
|
||||
episodeTitle: En Close, Yet En Far
|
||||
|
||||
? /av/unsorted/The.Daily.Show.2015.07.22.Jake.Gyllenhaal.720p.HDTV.x264-BATV.mkv
|
||||
: date: 2015-07-22
|
||||
format: HDTV
|
||||
releaseGroup: BATV
|
||||
screenSize: 720p
|
||||
title: The Daily Show
|
||||
episodeTitle: Jake Gyllenhaal
|
||||
videoCodec: h264
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user