Skip to content

Commit

Permalink
fix: fixed 3D and country code tests. added more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Aug 17, 2024
1 parent c9b85e2 commit eb47577
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 31 deletions.
15 changes: 9 additions & 6 deletions PTT/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def add_defaults(parser: Parser):
# Complete
parser.add_handler("complete", regex.compile(r"\b((?:19\d|20[012])\d[ .]?-[ .]?(?:19\d|20[012])\d)\b"), boolean, {"remove": True}) # year range
parser.add_handler("complete", regex.compile(r"[([][ .]?((?:19\d|20[012])\d[ .]?-[ .]?\d{2})[ .]?[)\]]"), boolean, {"remove": True}) # year range
parser.add_handler("complete", regex.compile(r"Completa", regex.IGNORECASE), boolean, {"remove": True}) # year range

# Bit Rate
parser.add_handler("bitrate", regex.compile(r"\b\d+[kmg]bps\b", regex.IGNORECASE), lowercase, {"remove": True})
Expand Down Expand Up @@ -132,6 +131,8 @@ def add_defaults(parser: Parser):
# Quality
parser.add_handler("quality", regex.compile(r"\b(?:HD[ .-]*)?T(?:ELE)?S(?:YNC)?(?:Rip)?\b", regex.IGNORECASE), value("TeleSync"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\b(?:HD[ .-]*)?T(?:ELE)?C(?:INE)?(?:Rip)?\b"), value("TeleCine"), {"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)?-?(HD|DVD)(?:Rip)?\b", regex.IGNORECASE), value("SCR"), {"remove": True})
parser.add_handler("quality", regex.compile(r"\bBlu[ .-]*Ray\b(?=.*remux)", regex.IGNORECASE), value("BluRay REMUX"), {"remove": True})
parser.add_handler("quality", regex.compile(r"(?:BD|BR|UHD)[- ]?remux", regex.IGNORECASE), value("BluRay REMUX"), {"remove": True})
parser.add_handler("quality", regex.compile(r"(?<=remux.*)\bBlu[ .-]*Ray\b", regex.IGNORECASE), value("BluRay REMUX"), {"remove": True})
Expand All @@ -143,8 +144,6 @@ def add_defaults(parser: Parser):
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("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?|.*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})
Expand Down Expand Up @@ -208,7 +207,6 @@ def handle_space_in_codec(context):
parser.add_handler("audio", regex.compile(r"\b(?:DTS(?:-HD)?|True(HD)?)\b", regex.IGNORECASE), uniq_concat(value("truehd")), {"remove": True})
parser.add_handler("audio", regex.compile(r"\bFLAC(?:\+?2\.0)?(?:x[2-4])?\b", regex.IGNORECASE), uniq_concat(value("flac")), {"remove": True})
parser.add_handler("audio", regex.compile(r"\bEAC-?3(?:[. -]?[256]\.[01])?", regex.IGNORECASE), uniq_concat(value("eac3")), {"remove": True})
#parser.add_handler("audio", regex.compile(r"\bAC-?3(?:[.-]5\.1|[x ]2\.?0?)?\b", regex.IGNORECASE), uniq_concat(value("ac3")), {"remove": True, "skipIfAlreadyFound": False})
parser.add_handler("audio", regex.compile(r"\bAC-?3(x2)?(?:[ .-](5\.1)?[x+]2\.?0?x?3?)?\b", regex.IGNORECASE), uniq_concat(value("ac3")), {"remove": True, "skipIfAlreadyFound": False})
parser.add_handler("audio", regex.compile(r"\b5\.1ch\b", regex.IGNORECASE), uniq_concat(value("ac3")), {"remove": True})
parser.add_handler("audio", regex.compile(r"\bDD[\+P]?5.?1\b", regex.IGNORECASE), uniq_concat(value("dd5.1")), {"remove": True, "skipIfAlreadyFound": False})
Expand Down Expand Up @@ -249,6 +247,7 @@ def handle_volumes(context):
parser.add_handler("complete", regex.compile(r"\bcollection\b.*\b(?:set|pack|movies)\b", regex.IGNORECASE), boolean)
parser.add_handler("complete", regex.compile(r"\bcollection\b", regex.IGNORECASE), boolean, {"skipFromTitle": True})
parser.add_handler("complete", regex.compile(r"duology|trilogy|quadr[oi]logy|tetralogy|pentalogy|hexalogy|heptalogy|anthology|saga", regex.IGNORECASE), boolean, {"skipIfAlreadyFound": False})
parser.add_handler("complete", regex.compile(r"Completa", regex.IGNORECASE), boolean, {"remove": True})

# Seasons
parser.add_handler("seasons", regex.compile(r"(?:complete\W|seasons?\W|\W|^)((?:s\d{1,2}[., +/\\&-]+)+s\d{1,2}\b)", regex.IGNORECASE), range_func, {"remove": True})
Expand Down Expand Up @@ -332,13 +331,16 @@ def handle_episodes(context):

parser.add_handler("episodes", handle_episodes)

# Country Code
parser.add_handler("country", regex.compile(r"\b(US|UK)\b"), value("$1"))

# Languages
parser.add_handler("languages", regex.compile(r"\bmulti(?:ple)?[ .-]*(?:su?$|sub\w*|dub\w*)\b|msub", regex.IGNORECASE), uniq_concat(value("multi subs")), {"skipIfAlreadyFound": False, "remove": True})
parser.add_handler("languages", regex.compile(r"\bmulti(?:ple)?[ .-]*(?:lang(?:uages?)?|audio|VF2)?\b", regex.IGNORECASE), uniq_concat(value("multi audio")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\btri(?:ple)?[ .-]*(?:audio|dub\w*)\b", regex.IGNORECASE), uniq_concat(value("multi audio")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bdual[ .-]*(?:au?$|[aá]udio|line)\b", regex.IGNORECASE), uniq_concat(value("dual audio")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bdual\b(?![ .-]*sub)", regex.IGNORECASE), uniq_concat(value("dual audio")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b([\.\[\(]US[\.\]\)]\b|engl?(?:sub[A-Z]*)?)\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bengl?(?:sub[A-Z]*)?\b", regex.IGNORECASE), uniq_concat(value("english")), {"skipIfAlreadyFound": False})
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})
Expand Down Expand Up @@ -484,7 +486,8 @@ def handle_group(context):
parser.add_handler("group", handle_group)

# 3D
parser.add_handler("3d", regex.compile(r"\b((Half.)?SBS|3D)\b", regex.IGNORECASE), boolean, {"remove": True})
parser.add_handler("3d", regex.compile(r"\b((Half.)?SBS|HSBS)\b", regex.IGNORECASE), boolean, {"remove": False, "skipIfFirst": True})
parser.add_handler("3d", regex.compile(r"\b3D\b", regex.IGNORECASE), boolean, {"remove": False, "skipIfFirst": True})

# Site
parser.add_handler("site", regex.compile(r"\[([^\]]+\.[^\]]+)\](?=\.\w{2,4}$|\s)", regex.IGNORECASE), value("$1"), {"remove": True})
Expand Down
126 changes: 102 additions & 24 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def parser():
("Skins Season S01-S07 COMPLETE UK Soundtrack 720p WEB-DL", {
"seasons": [1, 2, 3, 4, 5, 6, 7],
"title": "Skins",
"country": "UK",
"resolution": "720p",
"quality": "WEB-DL",
"languages": [],
Expand Down Expand Up @@ -317,35 +318,13 @@ def parser():
"title": "The Witcher",
"seasons": [1],
"episodes": [],
"languages": ["english"],
"languages": [],
"country": "US",
"quality": "WEB",
"resolution": "1080p",
"codec": "x264",
"group": "STRiFE"
}),
("The.Office.US.S01.1080P.BLURAY.REMUX.AVC.DD5.1-NOGRP", {
"title": "The Office",
"seasons": [1],
"episodes": [],
"languages": ["english"],
"quality": "BluRay REMUX",
"resolution": "1080p",
"audio": ["dd5.1"],
"channels": ["5.1"],
"codec": "avc",
"group": "NOGRP"
}),
("The.Office.US.S01-09.COMPLETE.SERIES.1080P.BLURAY.X265-HIQVE", {
"title": "The Office",
"seasons": [1, 2, 3, 4, 5, 6, 7, 8, 9],
"episodes": [],
"languages": ["english"],
"quality": "BluRay",
"resolution": "1080p",
"codec": "x265",
"complete": True,
"group": "HIQVE"
}),
("Madame Web (2024) 1080p HINDI ENGLISH 10bit AMZN WEBRip DDP5 1 x265 HEVC - PSA Shadow", {
"title": "Madame Web",
"year": 2024,
Expand Down Expand Up @@ -639,6 +618,105 @@ def parser():
"languages": [],
"episodes": [],
"seasons": []
}),
("Dune.Part.Two.2024.2160p.WEB-DL.DDP5.1.Atmos.DV.HDR.H.265-FLUX[TGx]", {
"title": "Dune Part Two",
"year": 2024,
"resolution": "2160p",
"quality": "WEB-DL",
"codec": "x265",
"audio": ["atmos", "dd5.1"],
"channels": ["5.1"],
"group": "FLUX",
"episodes": [],
"hdr": ["DV", "HDR"],
"languages": [],
"seasons": []
}),
("Saw.3D.2010.1080p.ITA-ENG.BluRay.x265.AAC-V3SP4EV3R.mkv", {
"title": "Saw 3D",
"year": 2010,
"seasons": [],
"episodes": [],
"languages": ["english", "italian"],
"resolution": "1080p",
"quality": "BluRay",
"codec": "x265",
"audio": ["aac"],
"container": "mkv",
"extension": "mkv",
"group": "V3SP4EV3R"
}),
("Dead Before Dawn 3D (2012) [3D.BLU-RAY] [1080p 3D] [BluRay] [HSBS] [YTS.MX]", {
"title": "Dead Before Dawn 3D",
"year": 2012,
"languages": [],
"seasons": [],
"episodes": [],
"resolution": "1080p",
"quality": "BluRay",
"3d": True
}),
("Wonder.Woman.1984.2020.3D.1080p.BluRay.x264-SURCODE[rarbg]", {
"title": "Wonder Woman 1984",
"year": 2020,
"seasons": [],
"episodes": [],
"languages": [],
"resolution": "1080p",
"quality": "BluRay",
"codec": "x264",
"group": "SURCODE",
"3d": True
}),
("The.Last.of.Us.S01E08.1080p.WEB.H264-CAKES[TGx]", {
"title": "The Last of Us",
"seasons": [1],
"episodes": [8],
"languages": [],
"resolution": "1080p",
"quality": "WEB",
"codec": "h264",
"group": "CAKES"
}),
("The.Office.UK.S01.1080P.BLURAY.REMUX.AVC.DD5.1-NOGRP", {
"title": "The Office",
"seasons": [1],
"episodes": [],
"languages": [],
"country": "UK",
"quality": "BluRay REMUX",
"resolution": "1080p",
"audio": ["dd5.1"],
"channels": ["5.1"],
"codec": "avc",
"group": "NOGRP"
}),
("The.Office.US.S01-09.COMPLETE.SERIES.1080P.BLURAY.X265-HIQVE", {
"title": "The Office",
"seasons": [1, 2, 3, 4, 5, 6, 7, 8, 9],
"episodes": [],
"country": "US",
"languages": [],
"quality": "BluRay",
"resolution": "1080p",
"codec": "x265",
"complete": True,
"group": "HIQVE"
}),
("Hard Knocks 2001 S23E01 1080p MAX WEB-DL DDP2 0 x264-NTb[EZTVx.to].mkv", {
"title": "Hard Knocks",
"year": 2001,
"seasons": [23],
"episodes": [1],
"languages": [],
"quality": "WEB-DL",
"resolution": "1080p",
"codec": "x264",
"group": "NTb",
"extension": "mkv",
"container": "mkv",
"site": "EZTVx.to"
})
])
def test_random_releases_parse(parser, release_name, expected):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def parser():
("Соперницы (Алексей Дмитриев) [1929, драма, WEB-DLRip]", "WEB-DLRip"),
("Dragon Blade (2015) HDTSRip Exclusive", "TeleSync"),
("Criminal (2016) Hindi Dubbed HDTCRip", "TeleCine"),
("Avatar La Voie de l'eau.FRENCH.CAMHD.H264.AAC", "CAM")
("Avatar La Voie de l'eau.FRENCH.CAMHD.H264.AAC", "CAM"),
("www.1TamilBlasters.link - Indian 2 (2024) [Tamil - 1080p Proper HQ PRE-HDRip - x264 - AAC - 6.3GB - HQ Real Audio].mkv", "SCR")
])
def test_source_detection(parser, release_name, expected_quality):
result = parser.parse(release_name)
Expand Down

0 comments on commit eb47577

Please sign in to comment.