Skip to content

Commit

Permalink
fix(tests): cleaned up tests and started normalizing handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Aug 4, 2024
1 parent cee5f43 commit 009f67e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
35 changes: 24 additions & 11 deletions PTT/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def add_defaults(parser: Parser):
# parser.add_handler("resolution", regex.compile(r"21600?[pi]", regex.IGNORECASE), value("4k"), {"skipIfAlreadyFound": False, "remove": True})
parser.add_handler("resolution", regex.compile(r"(?:^|\D)(\d{3,4})[pi]", regex.IGNORECASE), value("$1p"), {"remove": True})
parser.add_handler("resolution", regex.compile(r"(240|360|480|576|720|1080|2160|3840)[pi]", regex.IGNORECASE), lowercase, {"remove": True})

# Classify unknown resolutions with their quality counterpart. (normalize qualities to resolution) - DO NOT REMOVE HERE!
parser.add_handler("resolution", regex.compile(r"\bDVD(.*Rip|.*Mux)?\b", regex.IGNORECASE), value("480p"), {"remove": False})

# Date
parser.add_handler("date", regex.compile(r"(?:\W|^)([[(]?(?:19[6-9]|20[012])[0-9]([. \-/\\])(?:0[1-9]|1[012])\2(?:0[1-9]|[12][0-9]|3[01])[])]?)(?:\W|$)"), date("YYYY MM DD"), {"remove": True})
Expand Down Expand Up @@ -128,11 +131,11 @@ def add_defaults(parser: Parser):
parser.add_handler("quality", regex.compile(r"\b(?:BR|Blu[ .-]*Ray)[ .-]*Rip\b", regex.IGNORECASE), value("BRRip"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bBD[ .-]*Rip\b|\bBDR\b|\bBD-RM\b|[[(]BD[\]) .,-]", regex.IGNORECASE), value("BDRip"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\b(?:HD[ .-]*)?DVD[ .-]*Rip\b", regex.IGNORECASE), value("DVDRip"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bVHS[ .-]*Rip\b", regex.IGNORECASE), value("DVDRip"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bVHS[ .-]*Rip?\b", regex.IGNORECASE), value("VHSRip"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\b(?:DVD?|BD|BR)?[ .-]*Scr(?:eener)?\b", regex.IGNORECASE), value("SCR"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bP(?:re)?DVD(?:Rip)?\b", regex.IGNORECASE), value("SCR"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bDVD(?:R\d?)?\b", regex.IGNORECASE), value("DVD"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bVHS\b", regex.IGNORECASE), value("DVD"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bDVD(?:R\d?|.*Mux)?\b", regex.IGNORECASE), value("DVD"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bVHS\b", regex.IGNORECASE), value("VHS"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bPPVRip\b", regex.IGNORECASE), value("PPVRip"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bHD[ .-]*TV(?:Rip)?\b", regex.IGNORECASE), value("HDTV"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bDVB[ .-]*(?:Rip)?\b", regex.IGNORECASE), value("HDTV"), {"remove": True})
Expand Down Expand Up @@ -287,6 +290,8 @@ def handle_volumes(context):
parser.add_handler("episodes", regex.compile(r"\b\d{2}[ ._-](\d{2})(?:.F)?\.\w{2,4}$"), array(integer))
parser.add_handler("episodes", regex.compile(r"(?<!^)\[(\d{2,3})](?!(?:\.\w{2,4})?$)"), array(integer))
parser.add_handler("episodes", regex.compile(r"(\d+)(?=.?\[([A-Z0-9]{8})])", regex.IGNORECASE), array(integer))
parser.add_handler("episodes", regex.compile(r"\b264|265\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})

def handle_episodes(context):
title = context["title"]
Expand Down Expand Up @@ -324,7 +329,7 @@ def handle_episodes(context):
parser.add_handler("languages", regex.compile(r"\beng?sub[A-Z]*\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bing(?:l[eéê]s)?\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\benglish\W+(?:subs?|sdh|hi)\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bEN\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\beng?\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\benglish?\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipIfFirst": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b(?:JP|JAP|JPN)\b", regex.IGNORECASE), uniq_concat(value("japanese")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b(japanese|japon[eê]s)\b", regex.IGNORECASE), uniq_concat(value("japanese")), {"skipIfFirst": True, "skipIfAlreadyFound": False})
Expand Down Expand Up @@ -356,7 +361,7 @@ def handle_episodes(context):
parser.add_handler("languages", regex.compile(r"\bPT[. -]*(?:PT|ENG?|sub(?:s|titles?))\b", regex.IGNORECASE), uniq_concat(value("portuguese")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bpt(?=\.(?:ass|ssa|srt|sub|idx)$)", regex.IGNORECASE), uniq_concat(value("portuguese")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bpor\b", regex.IGNORECASE), uniq_concat(value("portuguese")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bITA\b", regex.IGNORECASE), uniq_concat(value("italian")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b-?ITA\b", regex.IGNORECASE), uniq_concat(value("italian")), {"remove": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b(?<!w{3}\.\w+\.)IT(?=[ .,/-]+(?:[a-zA-Z]{2}[ .,/-]+){2,})\b"), uniq_concat(value("italian")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bit(?=\.(?:ass|ssa|srt|sub|idx)$)", regex.IGNORECASE), uniq_concat(value("italian")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bitaliano?\b", regex.IGNORECASE), uniq_concat(value("italian")), {"skipIfFirst": True, "skipIfAlreadyFound": False})
Expand Down Expand Up @@ -436,7 +441,7 @@ def infer_language_based_on_naming(context):
parser.add_handler("languages", infer_language_based_on_naming)

# Subbed
parser.add_handler("subbed", regex.compile(r"\bsub(s|bed)?\b", regex.IGNORECASE), boolean)
parser.add_handler("subbed", regex.compile(r"\b(?:Official.*?|Dual-?)?sub(s|bed)?\b", regex.IGNORECASE), boolean, {"remove": True})

# Dubbed
parser.add_handler("dubbed", regex.compile(r"\b(fan\s?dub)\b", regex.IGNORECASE), boolean, {"remove": True, "skipFromTitle": True})
Expand Down Expand Up @@ -471,11 +476,6 @@ def handle_group(context):
# Site
parser.add_handler("site", regex.compile(r"\[([^\]]+\.[^\]]+)\](?=\.\w{2,4}$|\s)", regex.IGNORECASE), value("$1"), {"remove": True})

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

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

Expand All @@ -500,3 +500,16 @@ def handle_group(context):

# Extension
parser.add_handler("extension", regex.compile(r"\.(3g2|3gp|avi|flv|mkv|mk3d|mov|mp2|mp4|m4v|mpe|mpeg|mpg|mpv|webm|wmv|ogm|divx|ts|m2ts|iso|vob|sub|idx|ttxt|txt|smi|srt|ssa|ass|vtt|nfo|html)$", regex.IGNORECASE), lowercase)

# Group
parser.add_handler("group", regex.compile(r"\(([\w-]+)\)(?:$|\.\w{2,4}$)"))
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"^\[([^[\]]+)]"))

def handle_group_exclusion(context):
result = context["result"]
if "group" in result and result["group"] in ["-", ""]:
del result["group"]
return None

parser.add_handler("group", handle_group_exclusion)
2 changes: 1 addition & 1 deletion tests/test_episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def parser():
("Проклятие острова ОУК_ 5-й сезон 09-я серия_ Прорыв Дэна.avi", [9]),
("Разрушители легенд. MythBusters. Сезон 15. Эпизод 09. Скрытая угроза (2015).avi", [9]),
("Серия 11.mkv", [11]),
("Anatomia De Grey - Temporada 19 [HDTV][Cap.1905][Castellano][www.AtomoHD.nu].avi", [19]),
("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]),
])
def test_episode_parser(release_name, expected_episode, parser):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ def parser():
("[H3] Hunter x Hunter - 38 [1280x720] [x264]", "H3"),
("[KNK E MMS Fansubs] Nisekoi - 20 Final [PT-BR].mkv", "KNK E MMS Fansubs"),
("[ToonsHub] JUJUTSU KAISEN - S02E01 (Japanese 2160p x264 AAC) [Multi-Subs].mkv", "ToonsHub"),
("[HD-ELITE.NET] - The.Art.Of.The.Steal.2014.DVDRip.XviD.Dual.Aud", "HD-ELITE.NET"), # Should not be detected as group
("[HD-ELITE.NET] - The.Art.Of.The.Steal.2014.DVDRip.XviD.Dual.Aud", None), # Should not be detected as group, site instead
("[Russ]Lords.Of.London.2014.XviD.H264.AC3-BladeBDP", "BladeBDP"),
("Jujutsu Kaisen S02E01 2160p WEB H.265 AAC -Tsundere-Raws (B-Global).mkv", "B-Global"),
("[DVD-RIP] Kaavalan (2011) Sruthi XVID [700Mb] [TCHellRaiser]", None),
("[DvdMux - XviD - Ita Mp3 Eng Ac3 - Sub Ita Eng] Sanctuary S01e01", None),
("the-x-files-502.mkv", None),
("[ Torrent9.cz ] The.InBetween.S01E10.FiNAL.HDTV.XviD-EXTREME.avi", "EXTREME"), # Should not be detected as group
("[ Torrent9.cz ] The.InBetween.S01E10.FiNAL.HDTV.XviD-EXTREME.avi", "EXTREME"),
])
def test_group_detection(parser, release_name, expected_group):
result = parser.parse(release_name)
Expand Down
1 change: 1 addition & 0 deletions tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def parser():
("www.1TamilMV.cz - Mirzapur (2020) S02 EP (01-10) - HQ HDRip - [Tam+ Tel] - x264 - AAC - 1GB - ESub", ["telugu", "tamil"]),
("www.1TamilMV.cz - The Game of Chathurangam (2023) WEB-DL - 1080p - AVC - (AAC 2.0) [Tamil + Malayalam] - 1.2GB.mkv", ["tamil", "malayalam"]),
("www.1TamilMV.yt - Anchakkallakokkan (2024) Malayalam HQ HDRip - 720p - HEVC - (DD+5.1 - 192Kbps & AAC) - 750MB - ESub.mkv", ["malayalam"]),
("Anatomia De Grey - Temporada 19 [HDTV][Cap.1905][Castellano][www.AtomoHD.nu].avi", ["spanish"]),
])
def test_languages_detection(release_name, expected_languages, parser):
result = parser.parse(release_name)
Expand Down
12 changes: 9 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def parser():
("Da Vinci Code DVDRip", {
"title": "Da Vinci Code",
"quality": "DVDRip",
"resolution": "480p",
"languages": [],
"seasons": [],
"episodes": []
}),
("Some.girls.1998.DVDRip", {
"title": "Some girls",
"quality": "DVDRip",
"resolution": "480p",
"year": 1998,
"languages": [],
"seasons": [],
Expand All @@ -49,6 +51,7 @@ def parser():
("Ecrit.Dans.Le.Ciel.1954.MULTI.DVDRIP.x264.AC3-gismo65", {
"title": "Ecrit Dans Le Ciel",
"quality": "DVDRip",
"resolution": "480p",
"year": 1954,
"languages": ["multi audio"],
"dubbed": True,
Expand Down Expand Up @@ -239,6 +242,7 @@ def parser():
("[DVDRip-ITA]The Fast and the Furious: Tokyo Drift [CR-Bt]", {
"title": "The Fast and the Furious: Tokyo Drift",
"quality": "DVDRip",
"resolution": "480p",
"languages": ["italian"],
"seasons": [],
"episodes": []
Expand Down Expand Up @@ -275,6 +279,7 @@ def parser():
"title": "Heidi",
"episodes": [3],
"quality": "DVDRip",
"resolution": "480p",
"languages": ["latino"],
"seasons": [],
}),
Expand Down Expand Up @@ -304,7 +309,7 @@ def parser():
"year": 2024,
"quality": "BluRay REMUX",
"resolution": "2160p",
"audio": ["hd"],
"audio": ["atmos"],
"codec": "x265",
"languages": [],
"seasons": [],
Expand Down Expand Up @@ -444,8 +449,9 @@ def parser():
"resolution": "1896x1048p", # this needs to be 1080p instead probably
"audio": ["truehd", "ac3"],
"channels": ["5.1"],
"group": "sxales",
# "group": "sxales",
"dubbed": True,
"container": "mkv",
"extension": "mkv"
}),
("[www.1TamilMV.pics]_The.Great.Indian.Suicide.2023.Tamil.TRUE.WEB-DL.4K.SDR.HEVC.(DD+5.1.384Kbps.&.AAC).3.2GB.ESub.mkv", {
Expand All @@ -463,7 +469,7 @@ def parser():
"container": "mkv",
"extension": "mkv",
"bitrate": "384kbps",
"audio": ["true"],
"audio": ["truehd", "dd5.1", "aac"],
"channels": ["5.1"],
})
])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def parser():
("Peter Rabbit 2 [4K UHDremux][2160p][HDR10][DTS-HD 5.1 Castellano-TrueHD 7.1-Ingles+Subs][ES-EN]", "BluRay REMUX"),
("Snatch cerdos y diamantes [4KUHDremux 2160p][Castellano AC3 5.1-Ingles TrueHD 7.1+Subs]", "BluRay REMUX"),
("Троя / Troy [2004 HDDVDRip-AVC] Dub + Original + Sub]", "DVDRip"),
("Структура момента (Расим Исмайлов) [1980, Драма, VHSRip]", "DVDRip"),
("Мужчины без женщин (Альгимантас Видугирис) [1981, Драма, VHS]", "DVD"),
("Структура момента (Расим Исмайлов) [1980, Драма, VHSRip]", "VHSRip"),
("Мужчины без женщин (Альгимантас Видугирис) [1981, Драма, VHS]", "VHS"),
("Преферанс по пятницам (Игорь Шешуков) [1984, Детектив, DVB]", "HDTV"),
("Соперницы (Алексей Дмитриев) [1929, драма, WEB-DLRip]", "WEB-DLRip"),
("Dragon Blade (2015) HDTSRip Exclusive", "TeleSync"),
Expand Down

0 comments on commit 009f67e

Please sign in to comment.