Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add episode title promotion rule #778

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion guessit/rules/properties/episode_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Episode title
"""
from collections import defaultdict
from copy import copy

from rebulk import Rebulk, Rule, AppendMatch, RemoveMatch, RenameMatch, POST_PROCESS

Expand Down Expand Up @@ -34,7 +35,8 @@ def episode_title(config): # pylint:disable=unused-argument
TitleToEpisodeTitle,
Filepart3EpisodeTitle,
Filepart2EpisodeTitle,
RenameEpisodeTitleWhenMovieType)
RenameEpisodeTitleWhenMovieType,
EpisodeTitlePromotion)
return rebulk


Expand Down Expand Up @@ -298,3 +300,33 @@ def when(self, matches, context): # pylint:disable=inconsistent-return-statemen
if hole:
hole.tags.append('filepart-title')
return hole

class EpisodeTitlePromotion(Rule):
"""
Promote "episode_title" to "episode" when the title is in fact the episode number

See https://github.com/guessit-io/guessit/issues/667
"""

priority = POST_PROCESS
consequence = [RemoveMatch, AppendMatch]

def when(self, matches, context):
ep_title = matches.named("episode_title")
if not ep_title:
return

# Do not promote an episode title if there is already a know episode number
ep_nbr = matches.named("episode")
if ep_nbr:
return

to_remove = [match for match in ep_title if str(match.value).isdecimal()]
to_add = []
for tmatch in to_remove:
match = copy(tmatch)
match.name = "episode"
match.value = int(str(tmatch.value))
to_add.append(match)
return [to_remove, to_add]

6 changes: 6 additions & 0 deletions guessit/test/episodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4770,3 +4770,9 @@
video_codec: H.264
release_group: NOGRP
type: episode

? '[Erai-raws] Youkoso Jitsuryoku Shijou Shugi no Kyoushitsu e S3 - 05 [1080p][Multiple Subtitle][0DDEAFCD].mkv'
: release_group: "Erai-raws"
title: "Youkoso Jitsuryoku Shijou Shugi no Kyoushitsu e"
season: 3
episode: 5