Skip to content

Commit

Permalink
Add support for an additional pattern episode, season parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mhdzumair authored and dreulavelle committed Dec 6, 2024
1 parent f4dec25 commit 877585b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions PTT/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def add_defaults(parser: Parser):
"""
# Torrent extension
parser.add_handler("torrent", regex.compile(r"\.torrent$"), boolean, {"remove": True})

# Adult
parser.add_handler("adult", regex.compile(r"\b(?:xxx|xx)\b", regex.IGNORECASE), boolean, {"remove": True, "skipFromTitle": True})
parser.add_handler("adult", create_adult_pattern(), boolean, {"remove": True, "skipFromTitle": True, "skipIfAlreadyFound": True})

# Anime
# Anime
# anime_handler(parser) # adds too much time to overall parsing

# Scene
Expand Down Expand Up @@ -332,6 +332,7 @@ def handle_volumes(context):
parser.add_handler("seasons", regex.compile(r"(?<!\bEp?(?:isode)? ?\d+\b.*)\b(\d{2})[ ._]\d{2}(?:.F)?\.\w{2,4}$"), array(integer))
parser.add_handler("seasons", regex.compile(r"\bEp(?:isode)?\W+(\d{1,2})\.\d{1,3}\b", regex.IGNORECASE), array(integer))
parser.add_handler("seasons", regex.compile(r"\bSeasons?\b.*\b(\d{1,2}-\d{1,2})\b", regex.IGNORECASE), range_func)
parser.add_handler("seasons", regex.compile(r"(?:\W|^)(\d{1,2})(?:e|ep)\d{1,3}(?:\W|$)", regex.IGNORECASE), array(integer))

# Episodes
parser.add_handler("episodes", regex.compile(r"(?:[\W\d]|^)e[ .]?[([]?(\d{1,3}(?:[ .-]*(?:[&+]|e){1,2}[ .]?\d{1,3})+)(?:\W|$)", regex.IGNORECASE), range_func)
Expand Down Expand Up @@ -364,6 +365,7 @@ def handle_volumes(context):
parser.add_handler("episodes", regex.compile(r"(\d+)(?=.?\[([A-Z0-9]{8})])", regex.IGNORECASE), array(integer))
parser.add_handler("episodes", regex.compile(r"(?<![xh])\b264\b|\b265\b", regex.IGNORECASE), array(integer), {"remove": True})
parser.add_handler("episodes", regex.compile(r"(?<!\bMovie\s-\s)(?<=\s-\s)\d+(?=\s[-(\s])"), array(integer), {"remove": True, "skipIfAlreadyFound": True})
parser.add_handler("episodes", regex.compile(r"(?:\W|^)(?:\d+)?(?:e|ep)(\d{1,3})(?:\W|$)", regex.IGNORECASE), array(integer))

def handle_episodes(context):
title = context["title"]
Expand Down Expand Up @@ -564,7 +566,7 @@ def handle_group(context):

# Size
parser.add_handler("size", regex.compile(r"\b(\d+(\.\d+)?\s?(MB|GB|TB))\b", regex.IGNORECASE), none, {"remove": True})

# Site
parser.add_handler("site", regex.compile(r"\[([^\]]+\.[^\]]+)\](?=\.\w{2,4}$|\s)", regex.IGNORECASE), value("$1"), {"remove": True})
parser.add_handler("site", regex.compile(r"\bwww\.\w*\.\w+\b", regex.IGNORECASE), value("$1"), {"remove": True})
Expand Down Expand Up @@ -594,7 +596,7 @@ def handle_group(context):

# Group
parser.add_handler("group", regex.compile(r"\(([\w-]+)\)(?:$|\.\w{2,4}$)"))
parser.add_handler("group", regex.compile(r"\b(INFLATE|DEFLATE)\b", ), value("$1"), {"remove": True})
parser.add_handler("group", regex.compile(r"\b(INFLATE|DEFLATE)\b"), value("$1"), {"remove": True})
parser.add_handler("group", regex.compile(r"\b(?:Erai-raws|Erai-raws\.com)\b", regex.IGNORECASE), value("Erai-raws"), {"remove": True})
parser.add_handler("group", regex.compile(r"^\[([^[\]]+)]"))

Expand All @@ -609,5 +611,5 @@ def handle_group_exclusion(context):
parser.add_handler("trash", regex.compile(r"acesse o original", regex.IGNORECASE), boolean, {"remove": True})

# Title (hardcoded cleanup)
parser.add_handler("title", regex.compile(r"\b100[ .-]*years?[ .-]*quest\b", regex.IGNORECASE), none, {"remove": True}) # episode title
parser.add_handler("title", regex.compile(r"\b100[ .-]*years?[ .-]*quest\b", regex.IGNORECASE), none, {"remove": True}) # episode title
parser.add_handler("title", regex.compile(r"\b(?:INTEGRALE?|INTÉGRALE?|INTERNAL|HFR)\b", regex.IGNORECASE), none, {"remove": True})
1 change: 1 addition & 0 deletions tests/test_episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def parser():
("Anatomia De Grey - Temporada 19 [HDTV][Cap.1905][Castellano][www.AtomoHD.nu].avi", [1905]),
("[SubsPlease] Fairy Tail - 100 Years Quest - 05 (1080p) [1107F3A9].mkv", [5]),
("Mad.Max.Fury.Road.2015.1080p.BluRay.DDP5.1.x265.10bit-GalaxyRG265[TGx]", []),
("Vikkatakavi 01E06.mkv", [6]),
])
def test_episode_parser(release_name, expected_episode, parser):
result = parser.parse(release_name)
Expand Down
1 change: 1 addition & 0 deletions tests/test_season.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def parser():
("Проклятие острова ОУК_ 5-й сезон 09-я серия_ Прорыв Дэна.avi", [5]),
("Разрушители легенд. MythBusters. Сезон 15. Эпизод 09. Скрытая угроза (2015).avi", [15]),
("Сезон 5/Серия 11.mkv", [5]),
("Vikkatakavi 01E06.mkv", [1]),
])
def test_season_detection(parser, release_name, expected_seasons):
result = parser.parse(release_name)
Expand Down

0 comments on commit 877585b

Please sign in to comment.