Skip to content

Commit

Permalink
fix: tidied up networks and site handlers. added more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Aug 17, 2024
1 parent 8d0be22 commit c9b85e2
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 3 deletions.
8 changes: 6 additions & 2 deletions PTT/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ 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 @@ -487,18 +488,19 @@ def handle_group(context):

# 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})

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

# Networks
parser.add_handler("network", regex.compile(r"\bATVP?\b", regex.IGNORECASE), value("Apple TV"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bAMZN|Amazon\b", regex.IGNORECASE), value("Amazon Studios"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bAMZN\b", regex.IGNORECASE), value("Amazon"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bNF|Netflix\b", regex.IGNORECASE), value("Netflix"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bNICK(elodeon)?\b", regex.IGNORECASE), value("Nickelodeon"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bDSNY?P?\b", regex.IGNORECASE), value("Disney"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bH(MAX|BO)\b", regex.IGNORECASE), value("HBO"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bHULU\b", regex.IGNORECASE), value("Hulu Networks"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bHULU\b", regex.IGNORECASE), value("Hulu"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bCBS\b", regex.IGNORECASE), value("CBS"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bNBC\b", regex.IGNORECASE), value("NBC"), {"remove": True})
parser.add_handler("network", regex.compile(r"\bAMC\b", regex.IGNORECASE), value("AMC"), {"remove": True})
Expand All @@ -525,3 +527,5 @@ def handle_group_exclusion(context):
return None

parser.add_handler("group", handle_group_exclusion)

parser.add_handler("trash", regex.compile(r"acesse o original", regex.IGNORECASE), boolean, {"remove": True})
158 changes: 157 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def parser():
"codec": "x265",
"seasons": [],
"episodes": [],
"network": "Amazon Studios"
"network": "Amazon"
}),
("The Simpsons S01E01 1080p BluRay x265 HEVC 10bit AAC 5.1 Tigole", {
"title": "The Simpsons",
Expand Down Expand Up @@ -483,6 +483,162 @@ def parser():
"size": "2.3GB",
"site": "www.5MovieRulz.show",
"trash": True
}),
("超能警探.Memorist.S01E01.2160p.WEB-DL.H265.AAC-FLTTH.mkv", {
"title": "Memorist",
"languages": [],
"seasons": [1],
"episodes": [1],
"quality": "WEB-DL",
"codec": "x265",
"audio": ["aac"],
"resolution": "2160p",
"container": "mkv",
"extension": "mkv",
"group": "FLTTH",
}),
("Futurama.S08E03.How.the.West.Was.1010001.1080p.HULU.WEB-DL.DDP5.1.H.264-FLUX.mkv", {
"title": "Futurama",
"seasons": [8],
"episodes": [3],
"languages": [],
"network": "Hulu",
"codec": "h264",
"container": "mkv",
"extension": "mkv",
"audio": ["dd5.1"],
"channels": ["5.1"],
"quality": "WEB-DL",
"resolution": "1080p",
"group": "FLUX"
}),
("V.H.S.2 [2013] 1080p BDRip x265 DTS-HD MA 5.1 Kira [SEV].mkv", {
"title": "V H S 2",
"year": 2013,
"languages": [],
"seasons": [],
"episodes": [],
"quality": "BDRip",
"codec": "x265",
"audio": ["truehd"],
"channels": ["5.1"],
"container": "mkv",
"extension": "mkv",
"resolution": "1080p"
}),
("Бриджертоны.S02.WEB-DL.1080.HDR", {
"title": "Бриджертоны",
"seasons": [2],
"episodes": [],
"languages": [],
"quality": "WEB-DL",
"hdr": ["HDR"],
}),
("{WWW.BLUDV.TV} Love, Death & Robots - 1ª Temporada Completa 2019 (1080p) Acesse o ORIGINAL WWW.BLUDV.TV", {
"title": "Love, Death & Robots",
"seasons": [1],
"episodes": [],
"languages": [],
"resolution": "1080p",
"year": 2019,
"complete": True,
"site": "WWW.BLUDV.TV",
"trash": True
}),
("www.MovCr.to - Bikram Yogi, Guru, Predator (2019) 720p WEB_DL x264 ESubs [Dual Audio]-[Hindi + Eng] - 950MB - MovCr.mkv", {
"title": "Bikram Yogi, Guru, Predator",
"year": 2019,
"languages": ["dual audio", "english", "hindi"],
"quality": "WEB-DL",
"resolution": "720p",
"codec": "x264",
"container": "mkv",
"extension": "mkv",
"site": "www.MovCr.to",
"dubbed": True,
"episodes": [],
"group": "MovCr",
"seasons": [],
"size": "950MB"
}),
("28.days.2000.1080p.bluray.x264-mimic.mkv", {
"title": "28 days",
"year": 2000,
"resolution": "1080p",
"quality": "BluRay",
"codec": "x264",
"container": "mkv",
"extension": "mkv",
"group": "mimic",
"episodes": [],
"languages": [],
"seasons": []
}),
("4.20.Massacre.2018.1080p.BluRay.x264.AAC-[YTS.MX].mp4", {
"title": "4 20 Massacre",
"year": 2018,
"resolution": "1080p",
"quality": "BluRay",
"codec": "x264",
"audio": ["aac"],
"container": "mp4",
"extension": "mp4",
"languages": [],
"episodes": [],
"seasons": [],
"site": "YTS.MX"
}),
("inside.out.2.2024.d.ru.ua.ts.1o8op.mkv", {
"title": "inside out 2",
"year": 2024,
# "resolution": "1080p", - this is correct. we dont want it to parse the resolution here.
"quality": "TeleSync",
"container": "mkv",
"extension": "mkv",
"languages": ["russian"],
"episodes": [],
"seasons": [],
"trash": True
}),
("I.S.S.2023.P.WEB-DL.1O8Op.mkv", {
"title": "I S S",
"year": 2023,
"quality": "WEB-DL",
"container": "mkv",
"extension": "mkv",
"languages": [],
"episodes": [],
"seasons": []
}),
("Skazka.2022.Pa.WEB-DL.1O8Op.mkv", {
"title": "Skazka",
"year": 2022,
"quality": "WEB-DL",
"container": "mkv",
"extension": "mkv",
"languages": [],
"episodes": [],
"seasons": []
}),
("Spider-Man.Across.the.Spider-Verse.2023.Dt.WEBRip.1O8Op.mkv", {
"title": "Spider-Man Across the Spider-Verse",
"year": 2023,
"quality": "WEBRip",
"container": "mkv",
"extension": "mkv",
"languages": [],
"episodes": [],
"seasons": []
}),
("Civil.War.2024.D.WEB-DL.1O8Op.mkv", {
"title": "Civil War",
"year": 2024,
"quality": "WEB-DL",
"container": "mkv",
"extension": "mkv",
"languages": [],
"episodes": [],
"seasons": []
})
])
def test_random_releases_parse(parser, release_name, expected):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def parser():
("Jimmy Kimmel 2017 05 03 720p HDTV DD5 1 MPEG2-CTL", None, "Jimmy Kimmel"),
("[Anime Time] Re Zero kara Hajimeru Isekai Seikatsu (Season 2 Part 1) [1080p][HEVC10bit x265][Multi Sub]", None, "Re Zero kara Hajimeru Isekai Seikatsu"),
("[naiyas] Fate Stay Night - Unlimited Blade Works Movie [BD 1080P HEVC10 QAACx2 Dual Audio]", None, "Fate Stay Night - Unlimited Blade Works Movie"),
("Extraction.2020.720p.NF.WEB-DL.Dual.Atmos.5.1.x264-BonsaiHD", "Netflix", "Extraction"),
("Guilty (2020) NF Original 720p WEBRip [Hindi + English] AAC DD-5.1 ESub x264 - Shadow.mkv", "Netflix", "Guilty"),
("The.Bear.S03.COMPLETE.1080p.HULU.WEB.H264-SuccessfulCrab[TGx]", "Hulu", "The Bear"),
("Futurama.S08E03.How.the.West.Was.1010001.1080p.HULU.WEB-DL.DDP5.1.H.264-FLUX.mkv", "Hulu", "Futurama"),
("Amazon.Queen.2021.720p.AMZN.WEBRip.800MB.x264-GalaxyRG", "Amazon", "Amazon Queen"),
("The.Mummy.2017.1080p.AMZN.WEBRip.DD5.1.H.264-GalaxyRG", "Amazon", "The Mummy"),
])
def test_codec_detection(parser, release_name, expected_network, expected_title):
result = parser.parse(release_name)
Expand Down

0 comments on commit c9b85e2

Please sign in to comment.