feat: enhance agent download task controls

This commit is contained in:
jxxghp
2026-06-15 13:51:35 +08:00
parent d2803bed1e
commit 6a635ac720
19 changed files with 1332 additions and 183 deletions
+52
View File
@@ -338,6 +338,10 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]):
year=meta.year,
season_episode=meta.season_episode,
path=Path(self.normalize_return_path(torrent_path, downloader_name)),
save_path=self.normalize_return_path(
Path(torrent_data.get("save_path") or ""), downloader_name
) if torrent_data.get("save_path") else None,
content_path=self.normalize_return_path(torrent_path, downloader_name),
progress=torrent_data.get("progress", 0),
size=total_size,
state=self.__normalize_torrent_state(
@@ -522,6 +526,54 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]):
return None
return server.set_torrents_tag(ids=hashs, tags=tags)
def update_torrent(
self,
hash_string: str,
downloader: Optional[str] = None,
download_limit: Optional[float] = None,
upload_limit: Optional[float] = None,
tracker_list: Optional[list] = None,
save_path: Optional[str] = None,
category: Optional[str] = None,
ratio_limit: Optional[float] = None,
seeding_time_limit: Optional[int] = None,
) -> Optional[Dict[str, bool]]:
"""
修改下载任务属性。
:param hash_string: 种子Hash
:param downloader: 下载器
:param download_limit: 下载限速,单位 KB/s
:param upload_limit: 上传限速,单位 KB/s
:param tracker_list: Tracker URL列表,rTorrent 当前封装不支持
:param save_path: 保存目录
:param category: 分类,rTorrent 当前封装不支持
:param ratio_limit: 分享率限制,rTorrent 当前封装不支持
:param seeding_time_limit: 做种时间限制,rTorrent 当前封装不支持
:return: 各项修改结果
"""
server: Rtorrent = self.get_instance(downloader)
if not server:
return None
results = {}
if download_limit is not None or upload_limit is not None:
results["limits"] = server.change_torrent(
hash_string=hash_string,
download_limit=download_limit,
upload_limit=upload_limit,
)
if ratio_limit is not None or seeding_time_limit is not None:
results["seeding_limits"] = False
if tracker_list is not None:
results["trackers"] = False
if save_path is not None:
results["save_path"] = server.set_torrent_location(
hash_string=hash_string,
location=self.normalize_path(Path(save_path), downloader),
)
if category is not None:
results["category"] = False
return results
def start_torrents(
self, hashs: Union[list, str], downloader: Optional[str] = None
) -> Optional[bool]:
+56
View File
@@ -530,6 +530,62 @@ class Rtorrent:
break
return torrent_id
@staticmethod
def __build_throttle_name(torrent_hash: str) -> str:
"""
生成单任务限速组名称。
"""
return f"mp_{torrent_hash.lower()[:16]}"
def change_torrent(
self,
hash_string: str,
upload_limit: Optional[float] = None,
download_limit: Optional[float] = None,
) -> bool:
"""
修改单个种子的上传和下载限速。
:param hash_string: 种子Hash
:param upload_limit: 上传限速,单位 KB/s,0 表示不限速
:param download_limit: 下载限速,单位 KB/s,0 表示不限速
:return: 是否修改成功
"""
if not self._proxy or not hash_string:
return False
try:
throttle_name = self.__build_throttle_name(hash_string)
if download_limit is not None:
self._proxy.throttle.down.max.set(
throttle_name,
int(float(download_limit) * 1024),
)
if upload_limit is not None:
self._proxy.throttle.up.max.set(
throttle_name,
int(float(upload_limit) * 1024),
)
self._proxy.d.throttle_name.set(hash_string, throttle_name)
return True
except Exception as err:
logger.error(f"设置种子限速出错:{str(err)}")
return False
def set_torrent_location(self, hash_string: str, location: str) -> bool:
"""
修改种子保存目录。
:param hash_string: 种子Hash
:param location: 新保存目录
:return: 是否修改成功
"""
if not self._proxy or not hash_string or not location:
return False
try:
self._proxy.d.directory.set(hash_string, location)
return True
except Exception as err:
logger.error(f"设置种子保存目录出错:{str(err)}")
return False
def transfer_info(self) -> Optional[Dict]:
"""
获取传输信息