mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix(rtorrent): address code review feedback
- Replace direct _proxy access in transfer_completed with set_torrents_tag(overwrite=True) for proper encapsulation and error logging - Optimize episode collection by using set accumulation instead of repeated list-set conversions in loop - Fix type hint for hashs parameter in transfer_completed (str -> Union[str, list]) - Add overwrite parameter to set_torrents_tag to support tag replacement Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
c35faf5356
commit
def652c768
@@ -196,7 +196,7 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]):
|
|||||||
# 不需要的文件ID
|
# 不需要的文件ID
|
||||||
file_ids = []
|
file_ids = []
|
||||||
# 需要的集清单
|
# 需要的集清单
|
||||||
sucess_epidised = []
|
sucess_epidised = set()
|
||||||
try:
|
try:
|
||||||
for torrent_file in torrent_files:
|
for torrent_file in torrent_files:
|
||||||
file_id = torrent_file.get("id")
|
file_id = torrent_file.get("id")
|
||||||
@@ -206,10 +206,11 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]):
|
|||||||
or not set(meta_info.episode_list).issubset(episodes):
|
or not set(meta_info.episode_list).issubset(episodes):
|
||||||
file_ids.append(file_id)
|
file_ids.append(file_id)
|
||||||
else:
|
else:
|
||||||
sucess_epidised = list(set(sucess_epidised).union(set(meta_info.episode_list)))
|
sucess_epidised.update(meta_info.episode_list)
|
||||||
finally:
|
finally:
|
||||||
torrent_files.clear()
|
torrent_files.clear()
|
||||||
del torrent_files
|
del torrent_files
|
||||||
|
sucess_epidised = list(sucess_epidised)
|
||||||
if sucess_epidised and file_ids:
|
if sucess_epidised and file_ids:
|
||||||
# 设置不需要的文件优先级为0(不下载)
|
# 设置不需要的文件优先级为0(不下载)
|
||||||
server.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0)
|
server.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0)
|
||||||
@@ -321,7 +322,7 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]):
|
|||||||
return None
|
return None
|
||||||
return ret_torrents # noqa
|
return ret_torrents # noqa
|
||||||
|
|
||||||
def transfer_completed(self, hashs: str, downloader: Optional[str] = None) -> None:
|
def transfer_completed(self, hashs: Union[str, list], downloader: Optional[str] = None) -> None:
|
||||||
"""
|
"""
|
||||||
转移完成后的处理
|
转移完成后的处理
|
||||||
:param hashs: 种子Hash
|
:param hashs: 种子Hash
|
||||||
@@ -338,15 +339,7 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]):
|
|||||||
else:
|
else:
|
||||||
tags = ['已整理']
|
tags = ['已整理']
|
||||||
# 直接设置完整标签(覆盖)
|
# 直接设置完整标签(覆盖)
|
||||||
if isinstance(hashs, str):
|
server.set_torrents_tag(ids=hashs, tags=tags, overwrite=True)
|
||||||
hashs_list = [hashs]
|
|
||||||
else:
|
|
||||||
hashs_list = hashs
|
|
||||||
for tid in hashs_list:
|
|
||||||
try:
|
|
||||||
server._proxy.d.custom1.set(tid, ",".join(tags))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def remove_torrents(self, hashs: Union[str, list], delete_file: Optional[bool] = True,
|
def remove_torrents(self, hashs: Union[str, list], delete_file: Optional[bool] = True,
|
||||||
|
|||||||
@@ -402,9 +402,12 @@ class Rtorrent:
|
|||||||
logger.error(f"设置种子文件状态出错:{str(err)}")
|
logger.error(f"设置种子文件状态出错:{str(err)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_torrents_tag(self, ids: Union[str, list], tags: List[str]) -> bool:
|
def set_torrents_tag(self, ids: Union[str, list], tags: List[str], overwrite: bool = False) -> bool:
|
||||||
"""
|
"""
|
||||||
设置种子标签(使用d.custom1)
|
设置种子标签(使用d.custom1)
|
||||||
|
:param ids: 种子Hash
|
||||||
|
:param tags: 标签列表
|
||||||
|
:param overwrite: 是否覆盖现有标签,默认为合并
|
||||||
"""
|
"""
|
||||||
if not self._proxy:
|
if not self._proxy:
|
||||||
return False
|
return False
|
||||||
@@ -414,12 +417,16 @@ class Rtorrent:
|
|||||||
if isinstance(ids, str):
|
if isinstance(ids, str):
|
||||||
ids = [ids]
|
ids = [ids]
|
||||||
for tid in ids:
|
for tid in ids:
|
||||||
# 获取现有标签
|
if overwrite:
|
||||||
existing = self._proxy.d.custom1(tid)
|
# 直接覆盖标签
|
||||||
existing_tags = [t.strip() for t in existing.split(",") if t.strip()] if existing else []
|
self._proxy.d.custom1.set(tid, ",".join(tags))
|
||||||
# 合并标签
|
else:
|
||||||
merged = list(set(existing_tags + tags))
|
# 获取现有标签
|
||||||
self._proxy.d.custom1.set(tid, ",".join(merged))
|
existing = self._proxy.d.custom1(tid)
|
||||||
|
existing_tags = [t.strip() for t in existing.split(",") if t.strip()] if existing else []
|
||||||
|
# 合并标签
|
||||||
|
merged = list(set(existing_tags + tags))
|
||||||
|
self._proxy.d.custom1.set(tid, ",".join(merged))
|
||||||
return True
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"设置种子Tag出错:{str(err)}")
|
logger.error(f"设置种子Tag出错:{str(err)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user