Skip to content

Commit

Permalink
fix: spanish titles with seasons werent parsing as seasons. added spa…
Browse files Browse the repository at this point in the history
…nish lang infer as well for this.
  • Loading branch information
dreulavelle committed Aug 29, 2024
1 parent d314e19 commit f890cf3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 34 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ clean:
format:
@poetry run black $(SRC_DIR)

# Type checking
check:
@poetry run pyright

# Sort imports
sort:
@poetry run isort $(SRC_DIR)

# Run tests
test:
test: clean
@poetry run pytest

# Run tests with coverage
coverage:
coverage: clean
@poetry run pytest --cov=$(SRC_DIR) --cov-report=xml --cov-report=term
@poetry run pyright $(SRC_DIR)

pr-ready: sort format test

Expand Down
7 changes: 6 additions & 1 deletion PTT/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def handle_volumes(context):

parser.add_handler("volumes", handle_volumes)

# Pre-Language
parser.add_handler("languages", regex.compile(r"\b(temporadas?|completa)\b", regex.IGNORECASE), uniq_concat(value("es")), {"skipIfAlreadyFound": False})

# Complete
parser.add_handler("complete", regex.compile(r"(?:\bthe\W)?(?:\bcomplete|collection|dvd)?\b[ .]?\bbox[ .-]?set\b", regex.IGNORECASE), boolean)
parser.add_handler("complete", regex.compile(r"(?:\bthe\W)?(?:\bcomplete|collection|dvd)?\b[ .]?\bmini[ .-]?series\b", regex.IGNORECASE), boolean)
Expand All @@ -274,12 +277,13 @@ 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})
parser.add_handler("complete", regex.compile(r"\bcompleta\b", 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})
parser.add_handler("seasons", regex.compile(r"(?:complete\W|seasons?\W|\W|^)[([]?(s\d{2,}-\d{2,}\b)[)\]]?", regex.IGNORECASE), range_func, {"remove": True})
parser.add_handler("seasons", regex.compile(r"(?:complete\W|seasons?\W|\W|^)[([]?(s[1-9]-[2-9])[)\]]?", regex.IGNORECASE), range_func, {"remove": True})
parser.add_handler("seasons", regex.compile(r"\d+ª(?:.+)?(?:a.?)?\d+ª(?:(?:.+)?(?:temporadas?))", regex.IGNORECASE), range_func, {"remove": True})
parser.add_handler("seasons", regex.compile(r"(?:(?:\bthe\W)?\bcomplete\W)?(?:seasons?|[Сс]езони?|temporadas?)[. ]?[-:]?[. ]?[([]?((?:\d{1,2}[., /\\&]+)+\d{1,2}\b)[)\]]?", regex.IGNORECASE), range_func, {"remove": True})
parser.add_handler("seasons", regex.compile(r"(?:(?:\bthe\W)?\bcomplete\W)?(?:seasons?|[Сс]езони?|temporadas?)[. ]?[-:]?[. ]?[([]?((?:\d{1,2}[.-]+)+[1-9]\d?\b)[)\]]?", regex.IGNORECASE), range_func, {"remove": True})
parser.add_handler("seasons", regex.compile(r"(?:(?:\bthe\W)?\bcomplete\W)?season[. ]?[([]?((?:\d{1,2}[. -]+)+[1-9]\d?\b)[)\]]?(?!.*\.\w{2,4}$)", regex.IGNORECASE), range_func, {"remove": True})
Expand Down Expand Up @@ -382,6 +386,7 @@ def handle_episodes(context):
parser.add_handler("languages", regex.compile(r"\b(VOST(?:FR?|A)?)\b", regex.IGNORECASE), uniq_concat(value("fr")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b(VF[FQIB2]?|(TRUE|SUB)?.?FRENCH|(VOST)?FR2?)\b", regex.IGNORECASE), uniq_concat(value("fr")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bspanish\W?latin|american\W*(?:spa|esp?)", regex.IGNORECASE), uniq_concat(value("es")), {"skipFromTitle": True, "skipIfAlreadyFound": False, "remove": True})
parser.add_handler("languages", regex.compile(r"\b(?:\bla\b.+(?:cia\b))", regex.IGNORECASE), uniq_concat(value("es")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b(?:audio.)?lat(?:i|ino)?\b", regex.IGNORECASE), uniq_concat(value("es")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\b(?:audio.)?(?:ESP|spa|(en[ .]+)?espa[nñ]ola?|castellano)\b", regex.IGNORECASE), uniq_concat(value("es")), {"skipIfAlreadyFound": False})
parser.add_handler("languages", regex.compile(r"\bes(?=[ .,/-]+(?:[A-Z]{2}[ .,/-]+){2,})\b", regex.IGNORECASE), uniq_concat(value("es")), {"skipFromTitle": True, "skipIfAlreadyFound": False})
Expand Down
1 change: 1 addition & 0 deletions PTT/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def range_func(input_str: str) -> Optional[List[int]]:
if len(numbers) == 1:
return numbers

print(numbers, input_str)
return None


Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ def parser():
("[Hakata Ramen] Hoshiai No Sora (Stars Align) 01 [1080p][HEVC][x265][10bit][Dual-Subs] HR-DR", []),
("The English Patient (1996) 720p BrRip x264 - YIFY", []), # TODO: should have title "The English Patient"
("Do.Or.Die.1991.1080p.BluRay.x264-[YTS.LT].mp4", []),
("Castlevania 2017 1º temporada completa 1080p", []),
("City on a Hill - Temporada 1 [HDTV][Cap.110].avi", []),
("La inocencia [720p][wWw.EliteTorrent.NL].mkv", []),
("Reasonable Doubt - Temporada 1 [HDTV][Cap.101][www.AtomoHD.FI]", []),
("1883 - Temporada 1 [HDTV 720p][Cap.103][AC3 5.1][www.AtomoHD.fi]", []),
("Los Winchester - Temporada 1 [HDTV][Cap.103][www.atomoHD.tw]", []),
("El Inmortal- Temporada 1 [HDTV 720p][Cap.104][AC3 5.1][www.AtomoHD.ch]]", []),
("Castlevania 2017 1º temporada completa 1080p", ["es"]),
("City on a Hill - Temporada 1 [HDTV][Cap.110].avi", ["es"]),
("La inocencia [720p][wWw.EliteTorrent.NL].mkv", ["es"]),
("Reasonable Doubt - Temporada 1 [HDTV][Cap.101][www.AtomoHD.FI]", ["es"]),
("1883 - Temporada 1 [HDTV 720p][Cap.103][AC3 5.1][www.AtomoHD.fi]", ["es"]),
("Los Winchester - Temporada 1 [HDTV][Cap.103][www.atomoHD.tw]", ["es"]),
("El Inmortal- Temporada 1 [HDTV 720p][Cap.104][AC3 5.1][www.AtomoHD.ch]]", ["es"]),
("Black Friday (2021) [BluRay Rip][AC3 5.1][www.atomixHQ.TEL]", []),
("Deep Blue Sea 3 [HDR][wWw.EliteTorrent.SE]", []),
("The.Italian.Job.1969.1080p.BluRay.x265-RARBG.mp4", []),
Expand Down
64 changes: 43 additions & 21 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def parser():
"title": "Love, Death & Robots",
"seasons": [1],
"episodes": [],
"languages": [],
"languages": ["es"],
"resolution": "1080p",
"year": 2019,
"complete": True,
Expand Down Expand Up @@ -828,6 +828,7 @@ def parser():
"trash": True
}),
("The.Walking.Dead.S06E07.SUBFRENCH.HDTV.x264-AMB3R.mkv", {
# should detect french language and subbed
"title": "The Walking Dead",
"seasons": [6],
"episodes": [7],
Expand Down Expand Up @@ -864,28 +865,49 @@ def parser():
"size": "1.4GB",
"extension": "mkv",
"container": "mkv"
}),
("Game of Thrones 1ª a 8ª Temporada Completa [720p-1080p] [BluRay] [DUAL]", {
"title": "Game of Thrones",
"seasons": [1, 2, 3, 4, 5, 6, 7, 8],
"episodes": [],
"languages": ["es"],
"resolution": "1080p",
"quality": "BluRay",
"complete": True,
"dubbed": True
}),
("Kill.2024.REPACK.1080p.AMZN.WEB-DL.DDP5.1.Atmos.H.264-XEBEC.mkv", {
"title": "Kill",
"year": 2024,
"seasons": [],
"episodes": [],
"languages": [],
"resolution": "1080p",
"quality": "WEB-DL",
"codec": "avc",
"audio": ["Atmos", "Dolby Digital Plus"],
"channels": ["5.1"],
"group": "XEBEC",
"container": "mkv",
"extension": "mkv",
"network": "Amazon",
"repack": True
})
])
def test_random_releases_parse(parser, release_name, expected):
assert parser.parse(release_name) == expected

# @pytest.mark.parametrize("release_name, expected", [
# ("www.TamilBlasters.vip - Shang-Chi (2021) [720p BDRip - [Tamil + Telugu + Hindi + Eng] - x264 - DDP5.1 (192 Kbps) - 1.4GB - ESubs].mkv", {
# "title": "Shang-Chi",
# "year": 2021,
# "seasons": [],
# "episodes": [],
# "languages": ["en", "hi", "te", "ta"],
# "quality": "BDRip",
# "resolution": "720p",
# "codec": "avc",
# "audio": ["Dolby Digital Plus"],
# "channels": ["5.1"],
# "site": "www.TamilBlasters.vip",
# "size": "1.4GB",
# "extension": "mkv",
# "container": "mkv"
# })
# ])
# def test_debug_releases_parse(parser, release_name, expected):
# assert parser.parse(release_name) == expected
@pytest.mark.parametrize("release_name, expected", [
("Game of Thrones 1ª a 8ª Temporada Completa [720p-1080p] [BluRay] [DUAL]", {
"title": "Game of Thrones",
"seasons": [1, 2, 3, 4, 5, 6, 7, 8],
"episodes": [],
"languages": ["es"],
"resolution": "1080p",
"quality": "BluRay",
"complete": True,
"dubbed": True
})
])
def test_debug_releases_parse(parser, release_name, expected):
assert parser.parse(release_name) == expected

0 comments on commit f890cf3

Please sign in to comment.