Skip to content

Commit

Permalink
feat: add cli commands for ptt and parsett
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Oct 2, 2024
1 parent 9222c56 commit 7580b29
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Project specific files
.vscode
*.txt
data.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
32 changes: 19 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
.PHONY: install format sort test coverage pr-ready publish clean
.PHONY: help install clean format sort test debug coverage pr-ready publish

SRC_DIR := ./PTT

# Install dependencies (with dev deps for development)
help:
@echo "Usage: make <target>"
@echo "Available targets:"
@echo " install Install dependencies"
@echo " clean Clean up temporary files"
@echo " format Format code"
@echo " sort Sort imports"
@echo " test Run tests"
@echo " debug Debug tests"
@echo " coverage Generate coverage report"
@echo " pr-ready Run format, sort, and test"
@echo " publish Publish to PyPI"

install:
@poetry install --with dev

Expand All @@ -12,26 +24,20 @@ clean:
@find . -type d -name '.pytest_cache' -exec rm -rf {} +
@find . -type d -name '.ruff_cache' -exec rm -rf {} +

# Run black
format:
@poetry run black $(SRC_DIR)

# Type checking
check:
@poetry run pyright

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

# Run tests
test: clean
@poetry run pytest
@poetry run pytest -n 4 --dist=loadscope tests

debug:
@poetry run pytest tests/test_main.py::test_debug_releases_parse -v -ss

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

pr-ready: sort format test

Expand Down
3 changes: 2 additions & 1 deletion PTT/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def add_defaults(parser: Parser):
parser.add_handler("edition", regex.compile(r"\bTheatrical\b", regex.IGNORECASE), value("Theatrical"), {"remove": True})
parser.add_handler("edition", regex.compile(r"\bUncut\b", regex.IGNORECASE), value("Uncut"), {"remove": True})
parser.add_handler("edition", regex.compile(r"\bIMAX\b", regex.IGNORECASE), value("IMAX"), {"remove": True})
parser.add_handler("edition", regex.compile(r"\bDiamond\b", regex.IGNORECASE), value("Diamond Edition"), {"remove": True})
parser.add_handler("edition", regex.compile(r"\b\.Diamond\.\b", regex.IGNORECASE), value("Diamond Edition"), {"remove": True})
parser.add_handler("edition", regex.compile(r"\bRemaster(?:ed)?\b", regex.IGNORECASE), value("Remastered"), {"remove": True, "skipIfAlreadyFound": True})

# Upscaled
Expand Down Expand Up @@ -250,6 +250,7 @@ def handle_space_in_codec(context):
parser.add_handler("audio", regex.compile(r"\b5\.1(ch)?\b", regex.IGNORECASE), uniq_concat(value("AC3")), {"remove": True, "skipIfAlreadyFound": True})
parser.add_handler("audio", regex.compile(r"\b(DD2?[\+p]2?(.?5.1)?|DD Plus|Dolby Digital Plus)\b", regex.IGNORECASE), uniq_concat(value("Dolby Digital Plus")), {"remove": True, "skipIfAlreadyFound": False})
parser.add_handler("audio", regex.compile(r"\b(DD|Dolby.?Digital.?)2?(5.?1)?(?!.?(Plus|P|\+))\b", regex.IGNORECASE), uniq_concat(value("Dolby Digital")), {"remove": True, "skipIfAlreadyFound": False})
parser.add_handler("audio", regex.compile(r"\bDolbyD\b", regex.IGNORECASE), uniq_concat(value("Dolby Digital")), {"remove": True, "skipIfFirst": True})
parser.add_handler("audio", regex.compile(r"\bQ?Q?AAC(x?2)?\b", regex.IGNORECASE), uniq_concat(value("AAC")), {"remove": True, "skipIfAlreadyFound": False})
parser.add_handler("audio", regex.compile(r"\b(H[DQ])?.?(Clean.?Aud(io)?)\b", regex.IGNORECASE), uniq_concat(value("HQ Clean Audio")), {"remove": True, "skipIfAlreadyFound": False})

Expand Down
14 changes: 14 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import argparse

def main():
parser = argparse.ArgumentParser(description="Parse filename or torrent name using Parsett")
parser.add_argument('filename', type=str, help="Parse filename")

args = parser.parse_args()

if args.filename:
from PTT import parse_title
print(parse_title(args.filename))

if __name__ == "__main__":
main()
65 changes: 35 additions & 30 deletions poetry.lock

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

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ version = "1.3.1"
description = "PTT"
authors = ["Dreu LaVelle <[email protected]>"]
license = "MIT"
package-mode = true

[tool.poetry.dependencies]
python = "^3.11"
regex = "^2023.12.25"
arrow = "^1.3.0"

[tool.poetry.group.dev.dependencies]
pyright = "^1.1.352"
pyperf = "^2.2.0"
ruff = "^0.3.0"
isort = "^5.10.1"
Expand All @@ -20,6 +20,7 @@ pytest-cov = "^5.0.0"
codecov = "^2.1.13"
coverage = "^7.4.4"
black = "^24.4.2"
pytest-xdist = "^3.6.1"

[build-system]
requires = ["poetry-core"]
Expand All @@ -28,6 +29,10 @@ build-backend = "poetry.core.masonry.api"
[[tool.poetry.packages]]
include = "PTT"

[tool.poetry.scripts]
parsett = "cli:main"
ptt = "cli:main"

[tool.coverage.run]
branch = true

Expand Down
41 changes: 25 additions & 16 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def parser():
return p


@pytest.mark.parametrize("release_name, expected", [
@pytest.mark.parametrize("release_name, expected_output", [
("sons.of.anarchy.s05e10.480p.BluRay.x264-GAnGSteR", {
"title": "sons of anarchy",
"resolution": "480p",
Expand Down Expand Up @@ -972,25 +972,34 @@ def parser():
"channels": ["5.1"],
"group": "QRips",
"size": "2.2GB"
}),
("Blood Diamond (2006) 1080p BluRay H264 DolbyD 5 1 + nickarad mp4", {
"title": "Blood Diamond",
"year": 2006,
"seasons": [],
"episodes": [],
"languages": [],
"resolution": "1080p",
"quality": "BluRay",
"codec": "avc",
"audio": ["Dolby Digital"],
"channels": ["5.1"],
"container": "mp4"
})
])
def test_random_releases_parse(parser, release_name, expected):
assert parser.parse(release_name) == expected
def test_random_releases_parse(parser, release_name, expected_output):
assert parser.parse(release_name) == expected_output

# @pytest.mark.parametrize("release_name, expected", [
# ("Adbhut (2024) Hindi 1080p HDTVRip x264 AAC 5.1 [2.2GB] - QRips", {
# "title": "Adbhut",
# "year": 2024,
# "seasons": [],
# "episodes": [],
# "languages": ["hi"],
# "resolution": "1080p",
# "quality": "HDTVRip",
# "codec": "avc",
# "audio": ["AC3", "AAC"],
# "channels": ["5.1"],
# "group": "QRips",
# "size": "2.2GB"
# ("[ www.TorrentDay.com ] - The.Lying.Game.S02E07.HDTV.XviD-AFG", {
# "title": "The Lying Game",
# "seasons": [2],
# "episodes": [7],
# "languages": [],
# "quality": "HDTV",
# "codec": "xvid",
# "group": "AFG",
# "site": "www.TorrentDay.com"
# })
# ])
# def test_debug_releases_parse(parser, release_name, expected):
Expand Down

0 comments on commit 7580b29

Please sign in to comment.