Models¶
This module contains models used in the RTN package for parsing torrent titles, ranking media quality, and defining user settings.
Models:
- ParsedData
: Model for storing parsed information from a torrent title.
- BaseRankingModel
: Base class for ranking models used in the context of media quality and attributes.
- Torrent
: Model for representing a torrent with metadata parsed from its title and additional computed properties.
- DefaultRanking
: Default ranking model preset that covers the most common use cases.
- BestRanking
: Ranking model preset that prioritizes the highest quality and most desirable attributes.
- CustomRank
: Model used in the SettingsModel
for defining custom ranks for specific attributes.
- SettingsModel
: User-defined settings model for ranking torrents, including preferences for filtering torrents based on regex patterns and customizing ranks for specific torrent attributes.
For more information on each model, refer to the respective docstrings.
Note:
- The ParsedData
model contains attributes for storing parsed information from a torrent title.
- The BaseRankingModel
model is a base class for ranking models used in the context of media quality and attributes.
- The CustomRank
model is used in the SettingsModel
for defining custom ranks for specific attributes.
- The SettingsModel
model allows users to define custom settings for ranking torrents based on quality attributes and regex patterns.
AudioRankModel
¶
Bases: ConfigModelBase
Ranking configuration for audio attributes.
Source code in RTN/models.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|
BaseRankingModel
¶
Bases: BaseModel
A base class for ranking models used in the context of media quality and attributes. The ranking values are used to determine the quality of a media item based on its attributes.
Note
- The higher the ranking value, the better the quality of the media item.
- The default ranking values are set to 0, which means that the attribute does not affect the overall rank.
- Users can customize the ranking values based on their preferences and requirements by using inheritance.
Source code in RTN/models.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
BestRanking
¶
Bases: BaseRankingModel
Ranking model preset that covers the highest qualities like 4K HDR.
Source code in RTN/models.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
|
ConfigModelBase
¶
Bases: BaseModel
Base class for config models that need dict-like behavior
Source code in RTN/models.py
428 429 430 431 432 433 434 435 436 437 |
|
CustomRank
¶
Bases: BaseModel
Custom Ranks used in SettingsModel.
Source code in RTN/models.py
481 482 483 484 485 486 487 488 489 |
|
model_dump(**kwargs)
¶
Ensure serialization consistency.
Source code in RTN/models.py
487 488 489 |
|
CustomRanksConfig
¶
Bases: ConfigModelBase
Configuration for custom ranks.
Source code in RTN/models.py
593 594 595 596 597 598 599 600 |
|
DefaultRanking
¶
Bases: BaseRankingModel
Ranking model preset that covers the most common use cases.
Source code in RTN/models.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
ExtrasRankModel
¶
Bases: ConfigModelBase
Ranking configuration for extras attributes.
Source code in RTN/models.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
|
HdrRankModel
¶
Bases: ConfigModelBase
Ranking configuration for HDR attributes.
Source code in RTN/models.py
524 525 526 527 528 529 530 531 532 533 534 535 536 |
|
LanguagesConfig
¶
Bases: ConfigModelBase
Configuration for which languages are enabled.
Source code in RTN/models.py
474 475 476 477 478 |
|
OptionsConfig
¶
Bases: ConfigModelBase
Configuration for various options.
Source code in RTN/models.py
463 464 465 466 467 468 469 470 471 |
|
ParsedData
¶
Bases: BaseModel
Parsed data model for a torrent title.
Source code in RTN/models.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
type
property
¶
Returns the type of the torrent based on its attributes.
QualityRankModel
¶
Bases: ConfigModelBase
Ranking configuration for quality attributes.
Source code in RTN/models.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
|
ResolutionConfig
¶
Bases: ConfigModelBase
Configuration for which resolutions are enabled.
Source code in RTN/models.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
|
json(**kwargs)
¶
Ensure alias serialization for JSON output
Source code in RTN/models.py
458 459 460 |
|
RipsRankModel
¶
Bases: ConfigModelBase
Ranking configuration for rips attributes.
Source code in RTN/models.py
509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
SettingsModel
¶
Bases: BaseModel
Represents user-defined settings for ranking torrents, including preferences for filtering torrents based on regex patterns and customizing ranks for specific torrent attributes.
Attributes:
Name | Type | Description |
---|---|---|
profile |
str
|
Identifier for the settings profile, allowing for multiple configurations. |
require |
List[str | Pattern]
|
Patterns torrents must match to be considered. |
exclude |
List[str | Pattern]
|
Patterns that, if matched, result in torrent exclusion. |
preferred |
List[str | Pattern]
|
Patterns indicating preferred attributes in torrents. Given +10000 points by default. |
resolutions |
ResolutionConfig
|
Configuration for which resolutions are enabled. |
options |
OptionsConfig
|
Configuration for various options like title similarity and trash removal. |
languages |
LanguagesConfig
|
Configuration for which languages are enabled, excluded, and preferred. |
custom_ranks |
CustomRanksConfig
|
Custom ranking configurations for specific attributes. |
Methods:
Name | Description |
---|---|
compile_and_validate_patterns |
Compiles string patterns to regex.Pattern objects, handling case sensitivity. |
Note
- Patterns enclosed in '/' are compiled as case-sensitive.
- Patterns not enclosed are compiled as case-insensitive by default.
- The model supports advanced regex features for precise filtering and ranking.
Example
settings = SettingsModel( ... profile="default", ... require=["\b4K|1080p\b", "720p"], ... exclude=["CAM", "TS"], ... preferred=["BluRay", r"/\bS\d+/", "/HDR|HDR10/"], ... resolutions=ResolutionConfig(r1080p=True, r720p=True), ... options=OptionsConfig(remove_all_trash=True), ... languages=LanguagesConfig(required=["en"]), ... custom_ranks=CustomRanksConfig() ... ) print([p.pattern for p in settings.require]) ['\b4K|1080p\b', '720p'] print(settings.resolutions.r1080p) True print(settings.options.remove_all_trash) True
Source code in RTN/models.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 |
|
__getitem__(item)
¶
Access custom rank settings via attribute keys.
Source code in RTN/models.py
722 723 724 |
|
compile_and_validate_patterns(values)
¶
Compile string patterns to regex.Pattern, keeping compiled patterns unchanged.
Source code in RTN/models.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
deserialize_patterns(values)
classmethod
¶
Convert string patterns back to compiled regex.
Source code in RTN/models.py
709 710 711 712 713 |
|
load(path)
classmethod
¶
Load settings from a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
Path to the settings file. |
required |
Returns:
Name | Type | Description |
---|---|---|
SettingsModel |
SettingsModel
|
A new settings instance with the loaded configuration. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the settings file doesn't exist. |
JSONDecodeError
|
If the settings file is corrupted or contains invalid JSON. |
ValidationError
|
If the settings file contains invalid configuration. |
Source code in RTN/models.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
|
load_or_default(path=None)
classmethod
¶
Load settings from a file if it exists, otherwise create default settings and save them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Union[str, Path]]
|
Optional path to the settings file. If None, returns default settings without saving. |
None
|
Returns:
Name | Type | Description |
---|---|---|
SettingsModel |
SettingsModel
|
Either the loaded settings or default settings. |
Raises:
Type | Description |
---|---|
JSONDecodeError
|
If the settings file is corrupted or contains invalid JSON. |
Source code in RTN/models.py
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 |
|
save(path)
¶
Save settings to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
Path where the settings file should be saved. Can be either a string or Path object. |
required |
Example
settings = SettingsModel() settings.save("my_settings.json") settings.save(Path("configs/my_settings.json"))
Source code in RTN/models.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
|
serialize_patterns(values)
¶
Convert regex patterns to strings for JSON serialization.
Source code in RTN/models.py
704 705 706 707 |
|
validate_profile(v)
¶
Validate profile field and default to 'custom' if not a standard profile
Source code in RTN/models.py
715 716 717 718 719 720 |
|
Torrent
¶
Bases: BaseModel
Represents a torrent with metadata parsed from its title and additional computed properties.
Attributes:
Name | Type | Description |
---|---|---|
`raw_title` |
str
|
The original title of the torrent. |
`infohash` |
str
|
The SHA-1 hash identifier of the torrent. |
`data` |
ParsedData
|
Metadata extracted from the torrent title. |
`fetch` |
bool
|
Indicates whether the torrent meets the criteria for fetching based on user settings. |
`rank` |
int
|
The computed ranking score of the torrent based on user-defined preferences. |
`lev_ratio` |
float
|
The Levenshtein ratio comparing the parsed title and the raw title for similarity. |
Methods:
Name | Description |
---|---|
__eq__ |
Determines equality based on the infohash of the torrent, allowing for easy comparison. |
__hash__ |
Generates a hash based on the infohash of the torrent for set operations. |
Raises:
Type | Description |
---|---|
`GarbageTorrent`
|
If the title is identified as trash and should be ignored by the scraper. |
Example
torrent = Torrent( ... raw_title="The Walking Dead S05E03 720p HDTV x264-ASAP[ettv]", ... infohash="c08a9ee8ce3a5c2c08865e2b05406273cabc97e7", ... data=ParsedData(...), ... fetch=True, ... rank=500, ... lev_ratio=0.95, ... ) isinstance(torrent, Torrent) True torrent.raw_title 'The Walking Dead S05E03 720p HDTV x264-ASAP[ettv]' torrent.infohash 'c08a9ee8ce3a5c2c08865e2b05406273cabc97e7' torrent.data.parsed_title 'The Walking Dead' torrent.fetch True torrent.rank 500 torrent.lev_ratio 0.95
Source code in RTN/models.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
__eq__(other)
¶
Compares Torrent objects based on their infohash.
Source code in RTN/models.py
169 170 171 |
|
validate_infohash(v)
¶
Validates infohash length and format (MD5 or SHA-1).
Source code in RTN/models.py
162 163 164 165 166 167 |
|
TrashRankModel
¶
Bases: ConfigModelBase
Ranking configuration for trash attributes.
Source code in RTN/models.py
581 582 583 584 585 586 587 588 589 590 |
|