45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
import importlib
|
|
from pathlib import Path
|
|
from pkgutil import iter_modules
|
|
from typing import Optional
|
|
|
|
from watfag.parsers.generic import Release, ParserManager
|
|
|
|
|
|
class TVBoxSetRelease(Release):
|
|
"""Holds info representing a release of a TV box set."""
|
|
def __init__(self, unparsed_text, dl_link, **kwargs):
|
|
super().__init__(unparsed_text, dl_link, **kwargs)
|
|
self.show_title: str = ""
|
|
self.seasons: Optional[str] = None
|
|
|
|
def __str__(self):
|
|
parts = [f"{self.show_title} (Seasons: {self.seasons})"]
|
|
for attr in ['quality', 'video_codec', 'audio_codec', 'audio_layout', 'dynamic_range', 'repack', 'multi', 'source']:
|
|
value = getattr(self, attr)
|
|
parts.append(f"{attr.capitalize()}: {value if value else 'Unknown'}")
|
|
if self.streaming:
|
|
parts.append(f"Streaming: {self.streaming}")
|
|
parts.append(f"Group: {self.group_name if self.group else 'Unknown'}")
|
|
if not self.fully_consumed():
|
|
parts.append(f"Unparsed: {self.metadata_text}")
|
|
parts.append(f"WATFAG: {self.watfag:.2f}")
|
|
return " | ".join(parts)
|
|
|
|
class TVBoxSetParser:
|
|
"""
|
|
This class can be inherited by any parser that is specific to TV box sets.
|
|
It allows dynamic importing of parser classes and provides a method to run all parsers on a given TV box set release.
|
|
"""
|
|
|
|
class TVBoxSetParserManager(ParserManager):
|
|
"""Parses TV box set releases."""
|
|
def collect_parsers(self):
|
|
"""Dynamically imports all TV box set parsers."""
|
|
super().collect_parsers()
|
|
package_dir = Path(__file__).parent
|
|
for _, module_name, _ in iter_modules([package_dir]):
|
|
importlib.import_module(f"{__package__}.{module_name}")
|
|
|
|
self.parsers.extend(TVBoxSetParser.__subclasses__())
|