mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -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:
|
def when(self, matches: Matches, context) -> Any:
|
||||||
episodes: List[Match] = matches.named("episode") # type: ignore
|
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
|
return
|
||||||
|
|
||||||
to_remove = []
|
to_remove = []
|
||||||
@ -169,24 +169,25 @@ class TitleNumberFixup(Rule):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# do not fixup if there was a - or any separator between the title and the episode number
|
# 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:
|
if holes:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
to_remove.extend([title, episode])
|
to_remove.extend([title, episode])
|
||||||
new_title = copy(title)
|
new_title = copy(title)
|
||||||
new_title.end = episode.end
|
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
|
nmatch: List[Match] = matches.next(episode) # type: ignore
|
||||||
holes = matches.holes(episode.end)
|
if nmatch:
|
||||||
if holes and holes[0].start == episode.end:
|
end = (
|
||||||
val: str = holes[0].value
|
nmatch[0].initiator.start
|
||||||
if "-" in val:
|
if isinstance(nmatch[0].initiator, Match)
|
||||||
val, *_ = val.split("-")
|
else nmatch[0].start
|
||||||
val = val.rstrip()
|
)
|
||||||
new_title.value = f"{new_title.value}{val}"
|
# If an hole was created to parse the episode at the current pos, merge it back into the title
|
||||||
new_title.end += len(val)
|
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)
|
to_add.append(new_title)
|
||||||
return [to_remove, to_add]
|
return [to_remove, to_add]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user