diff --git a/PTT/handlers.py b/PTT/handlers.py index e0dfa79..c1fc96c 100644 --- a/PTT/handlers.py +++ b/PTT/handlers.py @@ -117,6 +117,7 @@ def add_defaults(parser: Parser): parser.add_handler("quality", regex.compile(r"\b(?:H[DQ][ .-]*)?CAM(?:H[DQ])?(?:[ .-]*Rip)?\b", regex.IGNORECASE), value("CAM"), {"remove": True}) parser.add_handler("quality", regex.compile(r"\b(?:H[DQ][ .-]*)?S[ \.\-]print", regex.IGNORECASE), value("CAM"), {"remove": True}) 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"\bP(?:RE)?-?(HD|DVD)(?:Rip)?\b", regex.IGNORECASE), value("SCR"), {"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"\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}) @@ -130,7 +131,6 @@ def add_defaults(parser: Parser): 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"\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"\bPPVRip\b", regex.IGNORECASE), value("PPVRip"), {"remove": True}) diff --git a/PTT/parse.py b/PTT/parse.py index 37577ec..e3714cf 100644 --- a/PTT/parse.py +++ b/PTT/parse.py @@ -32,6 +32,7 @@ REMAINING_NOT_ALLOWED_SYMBOLS_AT_START_AND_END = regex.compile(rf"^[^\w{NON_ENGLISH_CHARS}#]+|]$") REDUNDANT_SYMBOLS_AT_END = regex.compile(r"[ \-:./\\]+$") EMPTY_BRACKETS_REGEX = regex.compile(r"\(\s*\)|\[\s*\]|\{\s*\}") +MULTIPLE_SPACES_REGEX = regex.compile(r"\s+") DEBUG_HANDLER = False @@ -134,6 +135,7 @@ def clean_title(raw_title: str) -> str: cleaned_title = regex.sub(r"\.", " ", cleaned_title) cleaned_title = REDUNDANT_SYMBOLS_AT_END.sub("", cleaned_title) + cleaned_title = MULTIPLE_SPACES_REGEX.sub(" ", cleaned_title) cleaned_title = cleaned_title.strip() return cleaned_title diff --git a/tests/test_quality.py b/tests/test_quality.py index 89aae83..37acdac 100644 --- a/tests/test_quality.py +++ b/tests/test_quality.py @@ -11,67 +11,69 @@ def parser(): return p -@pytest.mark.parametrize("release_name, expected_quality", [ - ("Nocturnal Animals 2016 VFF 1080p BluRay DTS HEVC-HD2", "BluRay"), - ("doctor_who_2005.8x12.death_in_heaven.720p_hdtv_x264-fov", "HDTV"), - ("Rebecca.1940.720p.HDTVRip.HDCLUB", "HDTV"), - ("Gossip Girl - 1ª Temporada. (SAT-Rip)", "SATRip"), - ("A Stable Life S01E01 DVDRip x264-Ltu", "DVDRip"), - ("The Vet Life S02E01 Dunk-A-Doctor 1080p ANPL WEB-DL AAC2 0 H 264-RTN", "WEB-DL"), - ("Brown Nation S01E05 1080p WEBRip x264-JAWN", "WEBRip"), - ("Star Wars The Last Jedi 2017 TeleSync AAC x264-MiniMe", "TeleSync"), - ("The.Shape.of.Water.2017.DVDScr.XVID.AC3.HQ.Hive-CM8", "SCR"), - ("Cloudy With A Chance Of Meatballs 2 2013 720p PPVRip x264 AAC-FooKaS", "PPVRip"), - ("The.OA.1x08.L.Io.Invisibile.ITA.WEBMux.x264-UBi.mkv", "WEBMux"), - ("[UsifRenegade] Cardcaptor Sakura [BD][Remastered][1080p][HEVC_10Bit][Dual] + Movies", "BDRip"), - ("[UsifRenegade] Cardcaptor Sakura - 54 [BD-RM][1080p][x265_10Bit][Dual_AAC].mkv", "BDRip"), - ("Elvis & Nixon (MicroHD-1080p)", "HDRip"), - ("Bohemian Rhapsody 2018.2160p.UHDrip.x265.HDR.DD+.5.1-DTOne", "UHDRip"), - ("Blade.Runner.2049.2017.4K.UltraHD.BluRay.2160p.x264.TrueHD.Atmos", "BluRay"), - ("Terminator.Dark.Fate.2019.2160p.UHD.BluRay.X265.10bit.HDR.TrueHD", "BluRay"), - ("When We Were Boys 2013 BD Rip x264 titohmr", "BDRip"), - ("Key.and.Peele.s03e09.720p.web.dl.mrlss.sujaidr (pimprg)", "WEB-DL"), - ("Godzilla 2014 HDTS HC XVID AC3 ACAB", "TeleSync"), - ("Harry Potter And The Half Blood Prince 2009 telesync aac -- king", "TeleSync"), - ("Capitao.America.2.TS.BrunoG", "TeleSync"), - ("Star Trek TS-Screener Spanish Alta-Calidad 2da Version 2009 - Me", "TeleSync"), - ("Solo: A Star Wars Story (2018) English 720p TC x264 900MBTEAM TR", "TeleCine"), - ("Alita Battle Angel 2019 720p HDTC-1XBET", "TeleCine"), - ("My.Super.Ex.Girlfriend.FRENCH.TELECINE.XViD-VCDFRV", "TeleCine"), - ("You're Next (2013) cam XVID", "CAM"), - ("Shes the one_2013(camrip)__TOPSIDER [email protected]", "CAM"), - ("Blair Witch 2016 HDCAM UnKnOwN", "CAM"), - ("Thor : Love and Thunder (2022) Hindi HQCAM x264 AAC - QRips.mkv", "CAM"), - ("Avatar The Way of Water (2022) 1080p HQ S-Print Dual Audio [Hindi English] x264 AAC HC-Esub - CineVood.mkv", - "CAM"), - ( - "Avatar The Way of Water (2022) 1080p S Print Dual Audio [Hindi English] x264 AAC HC-Esub - CineVood.mkv", "CAM"), - ("Good Deeds 2012 SCR XViD-KiNGDOM", "SCR"), - ("Genova DVD-Screener Spanish 2008", "SCR"), - ("El Albergue Rojo BR-Screener Spanish 2007", "SCR"), - ("The.Mysteries.of.Pittsburgh.LIMITED.SCREENER.XviD-COALiTiON [NOR", "SCR"), - ("El.curioso.caso.de.benjamin.button-BRScreener-[EspaDivx.com].rar", "SCR"), - ("Thor- Love and Thunder (2022) Original Hindi Dubbed 1080p HQ PreDVD Rip x264 AAC [1.7 GB]- CineVood.mkv", "SCR"), - ("Black Panther Wakanda Forever 2022 Hindi 1080p PDVDRip x264 AAC CineVood.mkv", "SCR"), - ("Vampire in Vegas (2009) NL Subs DVDR DivXNL-Team", "DVD"), - ("Звонок из прошлого / Kol / The Call (2020) WEB-DLRip | ViruseProject", "WEB-DLRip"), - ("La nube (2020) [BluRay Rip][AC3 5.1 Castellano][www.maxitorrent.com]", "BRRip"), - ("Joker.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT", "BluRay REMUX"), - ("Warcraft 2016 1080p Blu-ray Remux AVC TrueHD Atmos-KRaLiMaRKo", "BluRay REMUX"), - ("Joker.2019.UHD.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX-JAT", "BluRay REMUX"), - ("Spider-Man No Way Home.2022.REMUX.1080p.Bluray.DTS-HD.MA.5.1.AVC-EVO[TGx]", "BluRay REMUX"), - ("Son of God 2014 HDR BDRemux 1080p.mkv", "BluRay REMUX"), - ("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"), - ("Преферанс по пятницам (Игорь Шешуков) [1984, Детектив, DVB]", "HDTV"), - ("Соперницы (Алексей Дмитриев) [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") -]) +@pytest.mark.parametrize( + "release_name, expected_quality", + [ + ("Nocturnal Animals 2016 VFF 1080p BluRay DTS HEVC-HD2", "BluRay"), + ("doctor_who_2005.8x12.death_in_heaven.720p_hdtv_x264-fov", "HDTV"), + ("Rebecca.1940.720p.HDTVRip.HDCLUB", "HDTV"), + ("Gossip Girl - 1ª Temporada. (SAT-Rip)", "SATRip"), + ("A Stable Life S01E01 DVDRip x264-Ltu", "DVDRip"), + ("The Vet Life S02E01 Dunk-A-Doctor 1080p ANPL WEB-DL AAC2 0 H 264-RTN", "WEB-DL"), + ("Brown Nation S01E05 1080p WEBRip x264-JAWN", "WEBRip"), + ("Star Wars The Last Jedi 2017 TeleSync AAC x264-MiniMe", "TeleSync"), + ("The.Shape.of.Water.2017.DVDScr.XVID.AC3.HQ.Hive-CM8", "SCR"), + ("Cloudy With A Chance Of Meatballs 2 2013 720p PPVRip x264 AAC-FooKaS", "PPVRip"), + ("The.OA.1x08.L.Io.Invisibile.ITA.WEBMux.x264-UBi.mkv", "WEBMux"), + ("[UsifRenegade] Cardcaptor Sakura [BD][Remastered][1080p][HEVC_10Bit][Dual] + Movies", "BDRip"), + ("[UsifRenegade] Cardcaptor Sakura - 54 [BD-RM][1080p][x265_10Bit][Dual_AAC].mkv", "BDRip"), + ("Elvis & Nixon (MicroHD-1080p)", "HDRip"), + ("Bohemian Rhapsody 2018.2160p.UHDrip.x265.HDR.DD+.5.1-DTOne", "UHDRip"), + ("Blade.Runner.2049.2017.4K.UltraHD.BluRay.2160p.x264.TrueHD.Atmos", "BluRay"), + ("Terminator.Dark.Fate.2019.2160p.UHD.BluRay.X265.10bit.HDR.TrueHD", "BluRay"), + ("When We Were Boys 2013 BD Rip x264 titohmr", "BDRip"), + ("Key.and.Peele.s03e09.720p.web.dl.mrlss.sujaidr (pimprg)", "WEB-DL"), + ("Godzilla 2014 HDTS HC XVID AC3 ACAB", "TeleSync"), + ("Harry Potter And The Half Blood Prince 2009 telesync aac -- king", "TeleSync"), + ("Capitao.America.2.TS.BrunoG", "TeleSync"), + ("Star Trek TS-Screener Spanish Alta-Calidad 2da Version 2009 - Me", "TeleSync"), + ("Solo: A Star Wars Story (2018) English 720p TC x264 900MBTEAM TR", "TeleCine"), + ("Alita Battle Angel 2019 720p HDTC-1XBET", "TeleCine"), + ("My.Super.Ex.Girlfriend.FRENCH.TELECINE.XViD-VCDFRV", "TeleCine"), + ("You're Next (2013) cam XVID", "CAM"), + ("Shes the one_2013(camrip)__TOPSIDER [email protected]", "CAM"), + ("Blair Witch 2016 HDCAM UnKnOwN", "CAM"), + ("Thor : Love and Thunder (2022) Hindi HQCAM x264 AAC - QRips.mkv", "CAM"), + ("Avatar The Way of Water (2022) 1080p HQ S-Print Dual Audio [Hindi English] x264 AAC HC-Esub - CineVood.mkv", "CAM"), + ("Avatar The Way of Water (2022) 1080p S Print Dual Audio [Hindi English] x264 AAC HC-Esub - CineVood.mkv", "CAM"), + ("Good Deeds 2012 SCR XViD-KiNGDOM", "SCR"), + ("Genova DVD-Screener Spanish 2008", "SCR"), + ("El Albergue Rojo BR-Screener Spanish 2007", "SCR"), + ("The.Mysteries.of.Pittsburgh.LIMITED.SCREENER.XviD-COALiTiON [NOR", "SCR"), + ("El.curioso.caso.de.benjamin.button-BRScreener-[EspaDivx.com].rar", "SCR"), + ("Thor- Love and Thunder (2022) Original Hindi Dubbed 1080p HQ PreDVD Rip x264 AAC [1.7 GB]- CineVood.mkv", "SCR"), + ("Black Panther Wakanda Forever 2022 Hindi 1080p PDVDRip x264 AAC CineVood.mkv", "SCR"), + ("Vampire in Vegas (2009) NL Subs DVDR DivXNL-Team", "DVD"), + ("Звонок из прошлого / Kol / The Call (2020) WEB-DLRip | ViruseProject", "WEB-DLRip"), + ("La nube (2020) [BluRay Rip][AC3 5.1 Castellano][www.maxitorrent.com]", "BRRip"), + ("Joker.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT", "BluRay REMUX"), + ("Warcraft 2016 1080p Blu-ray Remux AVC TrueHD Atmos-KRaLiMaRKo", "BluRay REMUX"), + ("Joker.2019.UHD.BluRay.2160p.TrueHD.Atmos.7.1.HEVC.REMUX-JAT", "BluRay REMUX"), + ("Spider-Man No Way Home.2022.REMUX.1080p.Bluray.DTS-HD.MA.5.1.AVC-EVO[TGx]", "BluRay REMUX"), + ("Son of God 2014 HDR BDRemux 1080p.mkv", "BluRay REMUX"), + ("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"), + ("Преферанс по пятницам (Игорь Шешуков) [1984, Детектив, DVB]", "HDTV"), + ("Соперницы (Алексей Дмитриев) [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"), + ("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) assert result.get("quality") == expected_quality, f"Source detection failed for {release_name}" diff --git a/tests/test_sports.py b/tests/test_sports.py index 80a159d..e2df859 100644 --- a/tests/test_sports.py +++ b/tests/test_sports.py @@ -11,36 +11,48 @@ def parser(): return p -@pytest.mark.parametrize("release_name, expected", [ - ("UFC.239.PPV.Jones.Vs.Santos.HDTV.x264-PUNCH[TGx]", { - "title": "UFC 239 Jones Vs Santos", - "seasons": [], - "episodes": [], - "languages": [], - "quality": "HDTV", - "codec": "x264", - "group": "PUNCH", - "ppv": True, - }), - ("UFC.Fight.Night.158.Cowboy.vs.Gaethje.WEB.x264-PUNCH[TGx]", { - "title": "UFC Fight Night 158 Cowboy vs Gaethje", - "seasons": [], - "episodes": [], - "languages": [], - "quality": "WEB-DL", - "codec": "x264", - "group": "PUNCH", - "ppv": True, - }), - ("UFC 226 PPV Miocic vs Cormier HDTV x264-Ebi [TJET]", { - "title": "UFC 226 Miocic vs Cormier", - "seasons": [], - "episodes": [], - "languages": [], - "quality": "HDTV", - "codec": "x264", - "ppv": True, - }) -]) +@pytest.mark.parametrize( + "release_name, expected", + [ + ( + "UFC.239.PPV.Jones.Vs.Santos.HDTV.x264-PUNCH[TGx]", + { + "title": "UFC 239 Jones Vs Santos", + "seasons": [], + "episodes": [], + "languages": [], + "quality": "HDTV", + "codec": "x264", + "group": "PUNCH", + "ppv": True, + }, + ), + ( + "UFC.Fight.Night.158.Cowboy.vs.Gaethje.WEB.x264-PUNCH[TGx]", + { + "title": "UFC Fight Night 158 Cowboy vs Gaethje", + "seasons": [], + "episodes": [], + "languages": [], + "quality": "WEB-DL", + "codec": "x264", + "group": "PUNCH", + "ppv": True, + }, + ), + ( + "UFC 226 PPV Miocic vs Cormier HDTV x264-Ebi [TJET]", + { + "title": "UFC 226 Miocic vs Cormier", + "seasons": [], + "episodes": [], + "languages": [], + "quality": "HDTV", + "codec": "x264", + "ppv": True, + }, + ), + ], +) def test_random_sports_parse(parser, release_name, expected): assert parser.parse(release_name) == expected diff --git a/tests/test_title.py b/tests/test_title.py index ce8b6c7..78ac999 100644 --- a/tests/test_title.py +++ b/tests/test_title.py @@ -47,7 +47,7 @@ def parser(): ("ww.Tamilblasters.sbs - 8 Bit Christmas (2021) HQ HDRip - x264 - Telugu (Fan Dub) - 400MB].mkv", "8 Bit Christmas"), ("www.1TamilMV.pics - 777 Charlie (2022) Tamil HDRip - 720p - x264 - HQ Clean Aud - 1.4GB.mkv", "777 Charlie"), ("Despicable.Me.4.2024.D.TELESYNC_14OOMB.avi", "Despicable Me 4"), - ("UFC.247.PPV.Jones.vs.Reyes.HDTV.x264-PUNCH[TGx]", "UFC 247 PPV Jones vs Reyes"), + ("UFC.247.PPV.Jones.vs.Reyes.HDTV.x264-PUNCH[TGx]", "UFC 247 Jones vs Reyes"), ("[www.1TamilMV.pics]_The.Great.Indian.Suicide.2023.Tamil.TRUE.WEB-DL.4K.SDR.HEVC.(DD+5.1.384Kbps.&.AAC).3.2GB.ESub.mkv", "The Great Indian Suicide"), ("Game of Thrones - S02E07 - A Man Without Honor [2160p] [HDR] [5.1, 7.1, 5.1] [ger, eng, eng] [Vio].mkv", "Game of Thrones"), ("Pawn.Stars.S09E13.1080p.HEVC.x265-MeGusta", "Pawn Stars"),