sane-bt-search: refactor: move filter logic off of Torrent class

This commit is contained in:
Colin 2023-08-20 08:53:06 +00:00
parent 35bc222552
commit 6894d5828b

View File

@ -97,11 +97,26 @@ class Filter:
def filter(self, t: 'Torrent', default: bool = False) -> bool:
valid = True
valid = valid and (not self.h265 or t.is_h265())
valid = valid and (not self.manga or t.is_manga(default))
valid = valid and (not self.video or t.is_video(default))
valid = valid and (not self.h265 or self.filter_h265(t))
valid = valid and (not self.manga or self.filter_manga(t, default))
valid = valid and (not self.video or self.filter_video(t, default))
return valid
@staticmethod
def filter_h265(t: 'Torrent') -> bool:
meta = t.title.lower()
return "h265" in meta \
or "x265" in meta \
or "HEVC" in meta
@staticmethod
def filter_manga(t: 'Torrent', default: bool = False) -> bool:
return is_cat(t.categories, MANGA_CATS, default)
@staticmethod
def filter_video(t: 'Torrent', default: bool = False) -> bool:
return is_cat(t.categories, VIDEO_CATS, default)
@dataclass(eq=True, order=True, unsafe_hash=True)
class Torrent:
@ -171,18 +186,6 @@ class Torrent:
magnet=self.magnet,
)
def is_h265(self) -> bool:
meta = self.title.lower()
return "h265" in meta \
or "x265" in meta \
or "HEVC" in meta
def is_manga(self, default: bool = False) -> bool:
return is_cat(self.categories, MANGA_CATS, default)
def is_video(self, default: bool = False) -> bool:
return is_cat(self.categories, VIDEO_CATS, default)
class Client:
def __init__(self):
self.apikey = open("/run/secrets/jackett_apikey").read().strip()