Revert "Merge pull request #5573 from wikrin/refactor-static-methods-conversion"

This reverts commit b8fc20b981, reversing
changes made to e09cfc6704.
This commit is contained in:
jxxghp
2026-03-14 18:21:31 +08:00
parent f38cb274e4
commit 6065c29891
20 changed files with 79 additions and 81 deletions
+11 -16
View File
@@ -27,36 +27,31 @@ class DirectoryHelper:
return []
return [schemas.TransferDirectoryConf(**d) for d in dir_confs]
@staticmethod
def get_download_dirs() -> List[schemas.TransferDirectoryConf]:
def get_download_dirs(self) -> List[schemas.TransferDirectoryConf]:
"""
获取所有下载目录
"""
return sorted([d for d in DirectoryHelper.get_dirs() if d.download_path], key=lambda x: x.priority)
return sorted([d for d in self.get_dirs() if d.download_path], key=lambda x: x.priority)
@staticmethod
def get_local_download_dirs() -> List[schemas.TransferDirectoryConf]:
def get_local_download_dirs(self) -> List[schemas.TransferDirectoryConf]:
"""
获取所有本地的可下载目录
"""
return [d for d in DirectoryHelper.get_download_dirs() if d.storage == "local"]
return [d for d in self.get_download_dirs() if d.storage == "local"]
@staticmethod
def get_library_dirs() -> List[schemas.TransferDirectoryConf]:
def get_library_dirs(self) -> List[schemas.TransferDirectoryConf]:
"""
获取所有媒体库目录
"""
return sorted([d for d in DirectoryHelper.get_dirs() if d.library_path], key=lambda x: x.priority)
return sorted([d for d in self.get_dirs() if d.library_path], key=lambda x: x.priority)
@staticmethod
def get_local_library_dirs() -> List[schemas.TransferDirectoryConf]:
def get_local_library_dirs(self) -> List[schemas.TransferDirectoryConf]:
"""
获取所有本地的媒体库目录
"""
return [d for d in DirectoryHelper.get_library_dirs() if d.library_storage == "local"]
return [d for d in self.get_library_dirs() if d.library_storage == "local"]
@staticmethod
def get_dir(media: Optional[MediaInfo], include_unsorted: Optional[bool] = False,
def get_dir(self, media: Optional[MediaInfo], include_unsorted: Optional[bool] = False,
storage: Optional[str] = None, src_path: Path = None,
target_storage: Optional[str] = None, dest_path: Path = None
) -> Optional[schemas.TransferDirectoryConf]:
@@ -71,7 +66,7 @@ class DirectoryHelper:
"""
# 电影/电视剧
media_type = media.type.value if media else None
dirs = DirectoryHelper.get_dirs()
dirs = self.get_dirs()
# 如果存在源目录,并源目录为任一下载目录的子目录时,则进行源目录匹配,否则,允许源目录按同盘优先的逻辑匹配
matching_dirs = [d for d in dirs if src_path.is_relative_to(d.download_path)] if src_path else []
@@ -111,7 +106,7 @@ class DirectoryHelper:
# 优先源目录同盘
for matched_dir in matched_dirs:
matched_path = Path(matched_dir.download_path)
if DirectoryHelper._is_same_source((src_path, storage or "local"), (matched_path, matched_dir.library_storage)):
if self._is_same_source((src_path, storage or "local"), (matched_path, matched_dir.library_storage)):
return matched_dir
return matched_dirs[0]
return None
+6 -9
View File
@@ -21,24 +21,22 @@ class RuleHelper:
return []
return [FilterRuleGroup(**group) for group in rule_groups]
@staticmethod
def get_rule_group(group_name: str) -> Optional[FilterRuleGroup]:
def get_rule_group(self, group_name: str) -> Optional[FilterRuleGroup]:
"""
获取规则组
"""
rule_groups = RuleHelper.get_rule_groups()
rule_groups = self.get_rule_groups()
for group in rule_groups:
if group.name == group_name:
return group
return None
@staticmethod
def get_rule_group_by_media(media: MediaInfo = None, group_names: list = None) -> List[FilterRuleGroup]:
def get_rule_group_by_media(self, media: MediaInfo = None, group_names: list = None) -> List[FilterRuleGroup]:
"""
根据媒体信息获取规则组
"""
ret_groups = []
rule_groups = RuleHelper.get_rule_groups()
rule_groups = self.get_rule_groups()
if group_names:
rule_groups = [group for group in rule_groups if group.name in group_names]
for group in rule_groups:
@@ -60,12 +58,11 @@ class RuleHelper:
return []
return [CustomRule(**rule) for rule in rules]
@staticmethod
def get_custom_rule(rule_id: str) -> Optional[CustomRule]:
def get_custom_rule(self, rule_id: str) -> Optional[CustomRule]:
"""
获取自定义规则
"""
rules = RuleHelper.get_custom_rules()
rules = self.get_custom_rules()
for rule in rules:
if rule.id == rule_id:
return rule
+6 -9
View File
@@ -145,8 +145,7 @@ class TorrentHelper:
self.add_invalid(url)
return cache_path, None, "", [], f"下载种子出错,状态码:{req.status_code}"
@staticmethod
def get_torrent_info(torrent_path: Path) -> Tuple[str, List[str]]:
def get_torrent_info(self, torrent_path: Path) -> Tuple[str, List[str]]:
"""
获取种子文件的文件夹名和文件清单
:param torrent_path: 种子文件路径
@@ -157,7 +156,7 @@ class TorrentHelper:
try:
torrentinfo = Torrent.from_file(torrent_path)
# 获取文件清单
return TorrentHelper.get_fileinfo_from_torrent(torrentinfo)
return self.get_fileinfo_from_torrent(torrentinfo)
except Exception as err:
logger.error(f"种子文件解析失败:{str(err)}")
return "", []
@@ -193,8 +192,7 @@ class TorrentHelper:
logger.debug(f"解析种子:{torrent.name} => 目录:{folder_name},文件清单:{file_list}")
return folder_name, file_list
@staticmethod
def get_fileinfo_from_torrent_content(torrent_content: Union[str, bytes]) -> Tuple[str, List[str]]:
def get_fileinfo_from_torrent_content(self, torrent_content: Union[str, bytes]) -> Tuple[str, List[str]]:
"""
从种子内容中获取文件夹名和文件清单
:param torrent_content: 种子内容
@@ -212,7 +210,7 @@ class TorrentHelper:
# 解析种子内容
torrentinfo = Torrent.from_string(torrent_content)
# 获取文件清单
return TorrentHelper.get_fileinfo_from_torrent(torrentinfo)
return self.get_fileinfo_from_torrent(torrentinfo)
except Exception as err:
logger.error(f"种子内容解析失败:{str(err)}")
return "", []
@@ -294,8 +292,7 @@ class TorrentHelper:
# 排序
return sorted(torrent_list, key=lambda x: get_sort_str(x), reverse=True)
@staticmethod
def sort_group_torrents(torrent_list: List[Context]) -> List[Context]:
def sort_group_torrents(self, torrent_list: List[Context]) -> List[Context]:
"""
对媒体信息进行排序、去重
"""
@@ -303,7 +300,7 @@ class TorrentHelper:
return []
# 排序
torrent_list = TorrentHelper.sort_torrents(torrent_list)
torrent_list = self.sort_torrents(torrent_list)
# 控重
result = []