Skip to content

Commit

Permalink
fix: fix types on ParsedData model for KC
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Mar 27, 2024
1 parent 22b4c4d commit 9d83b4b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 51 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class ParsedData(BaseModel):
is_multi_audio: bool = False
is_multi_subtitle: bool = False
is_complete: bool = False
year: List[int] = []
year: int = 0
resolution: List[str] = []
quality: List[str] = []
season: List[int] = []
Expand All @@ -376,15 +376,14 @@ class ParsedData(BaseModel):
subtitles: List[str] = []
language: List[str] = []
bitDepth: List[int] = []
hdr: str | bool = False
hdr: str = ""
proper: bool = False
repack: bool = False
remux: bool = False
upscaled: bool = False
remastered: bool = False
directorsCut: bool = False
extended: bool = False
excess: list = []
```

This will continue to grow though as we expand on functionality, so keep checking back for this list!
Expand Down
5 changes: 2 additions & 3 deletions RTN/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ParsedData(BaseModel):
is_multi_audio: bool = False
is_multi_subtitle: bool = False
is_complete: bool = False
year: List[int] = []
year: int = 0
resolution: List[str] = []
quality: List[str] = []
season: List[int] = []
Expand All @@ -25,15 +25,14 @@ class ParsedData(BaseModel):
subtitles: List[str] = []
language: List[str] = []
bitDepth: List[int] = []
hdr: str | bool = False
hdr: str = ""
proper: bool = False
repack: bool = False
remux: bool = False
upscaled: bool = False
remastered: bool = False
directorsCut: bool = False
extended: bool = False
excess: list = []


class BaseRankingModel(BaseModel):
Expand Down
8 changes: 7 additions & 1 deletion RTN/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Any, List
from typing import Any, List, Tuple

import Levenshtein
import PTN
Expand Down Expand Up @@ -99,6 +99,11 @@ def rank(self, raw_title: str, infohash: str) -> Torrent:
lev_ratio=Levenshtein.ratio(parsed_data.parsed_title.lower(), raw_title.lower()),
)

def batch_rank(self, torrents: List[Tuple[str, str]], max_workers: int = 4) -> List[Torrent]:
"""Ranks a batch of torrents in parallel using multiple threads."""
with ThreadPoolExecutor(max_workers=max_workers) as executor:
return list(executor.map(lambda t: self.rank(t[0], t[1]), torrents))


def parse(raw_title: str) -> ParsedData:
"""
Expand All @@ -114,6 +119,7 @@ def parse(raw_title: str) -> ParsedData:
raise TypeError("The input title must be a non-empty string.")

parsed_dict: dict[str, Any] = PTN.parse(raw_title, coherent_types=True)
parsed_dict["year"] = parsed_dict["year"][0] if parsed_dict.get("year") else 0
extras: dict[str, Any] = parse_extras(raw_title)
full_data = {**parsed_dict, **extras} # Merge PTN parsed data with RTN extras.
full_data["raw_title"] = raw_title
Expand Down
2 changes: 1 addition & 1 deletion RTN/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ def parse_extras(raw_title: str) -> Dict[str, Any]:
"is_multi_audio": check_pattern(MULTI_AUDIO_COMPILED, raw_title),
"is_multi_subtitle": check_pattern(MULTI_SUBTITLE_COMPILED, raw_title),
"is_complete": check_pattern(COMPLETE_SERIES_COMPILED, raw_title),
"hdr": check_hdr_dolby_video(raw_title) or False,
"hdr": check_hdr_dolby_video(raw_title) or "",
"episode": extract_episodes(raw_title),
}
35 changes: 1 addition & 34 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rank-torrent-name"
version = "0.1.4"
version = "0.1.5"
description = "Parse Torrents using PTN and Rank them according to your preferences!"
authors = ["Spoked <dreu.lavelle@gmail.com>"]
license = "MIT"
Expand Down
Loading

0 comments on commit 9d83b4b

Please sign in to comment.