mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fix TitleNumberFixupRule to prevent over extending or bugging on duplicated multi episodes values
This commit is contained in:
parent
8303df35cc
commit
c07d5ca5b9
@ -157,7 +157,7 @@ class TitleNumberFixup(Rule):
|
||||
def when(self, matches: Matches, context) -> Any:
|
||||
episodes: List[Match] = matches.named("episode") # type: ignore
|
||||
|
||||
if len(episodes) < 2:
|
||||
if len(episodes) < 2 or all(x.value == episodes[0].value for x in episodes):
|
||||
return
|
||||
|
||||
to_remove = []
|
||||
@ -169,24 +169,25 @@ class TitleNumberFixup(Rule):
|
||||
continue
|
||||
|
||||
# do not fixup if there was a - or any separator between the title and the episode number
|
||||
holes = matches.holes(title.end, episode.start)
|
||||
holes: List[Match] = matches.holes(title.end, episode.start) # type: ignore
|
||||
if holes:
|
||||
continue
|
||||
|
||||
to_remove.extend([title, episode])
|
||||
new_title = copy(title)
|
||||
new_title.end = episode.end
|
||||
new_title.value = f"{title.value} {episode.value}"
|
||||
|
||||
# If an hole was created to parse the episode at the current pos, merge it back into the title
|
||||
holes = matches.holes(episode.end)
|
||||
if holes and holes[0].start == episode.end:
|
||||
val: str = holes[0].value
|
||||
if "-" in val:
|
||||
val, *_ = val.split("-")
|
||||
val = val.rstrip()
|
||||
new_title.value = f"{new_title.value}{val}"
|
||||
new_title.end += len(val)
|
||||
nmatch: List[Match] = matches.next(episode) # type: ignore
|
||||
if nmatch:
|
||||
end = (
|
||||
nmatch[0].initiator.start
|
||||
if isinstance(nmatch[0].initiator, Match)
|
||||
else nmatch[0].start
|
||||
)
|
||||
# If an hole was created to parse the episode at the current pos, merge it back into the title
|
||||
holes: List[Match] = matches.holes(start=episode.end, end=end) # type: ignore
|
||||
if holes and holes[0].start == episode.end:
|
||||
new_title.end = holes[0].end
|
||||
|
||||
to_add.append(new_title)
|
||||
return [to_remove, to_add]
|
||||
|
Loading…
x
Reference in New Issue
Block a user