mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
feat: enhance agent download task controls
This commit is contained in:
@@ -310,6 +310,8 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
||||
torrent_data, "left_until_done", "leftUntilDone"
|
||||
) or 0
|
||||
torrent_path = __get_torrent_path(torrent_data)
|
||||
ratio_limit = __get_torrent_attr(torrent_data, "seed_ratio_limit", "seedRatioLimit")
|
||||
seeding_time_limit = __get_torrent_attr(torrent_data, "seed_idle_limit", "seedIdleLimit")
|
||||
return DownloaderTorrent(
|
||||
downloader=downloader_name,
|
||||
hash=torrent_data.hashString,
|
||||
@@ -318,12 +320,20 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
||||
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.download_dir), downloader_name
|
||||
) if getattr(torrent_data, "download_dir", None) else None,
|
||||
content_path=self.normalize_return_path(torrent_path, downloader_name),
|
||||
progress=__get_torrent_progress(torrent_data),
|
||||
size=__get_torrent_size(torrent_data),
|
||||
state=self.__normalize_torrent_state(torrent_data.status),
|
||||
dlspeed=StringUtils.str_filesize(dlspeed),
|
||||
upspeed=StringUtils.str_filesize(upspeed),
|
||||
tags=__get_torrent_labels(torrent_data),
|
||||
download_limit=__get_torrent_attr(torrent_data, "download_limit", "downloadLimit"),
|
||||
upload_limit=__get_torrent_attr(torrent_data, "upload_limit", "uploadLimit"),
|
||||
ratio_limit=ratio_limit,
|
||||
seeding_time_limit=seeding_time_limit,
|
||||
left_time=StringUtils.str_secends(
|
||||
left_until_done / dlspeed
|
||||
) if dlspeed > 0 else ''
|
||||
@@ -491,6 +501,85 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
||||
org_tags = server.get_torrent_tags(ids=hashs)
|
||||
return server.set_torrent_tag(ids=hashs, tags=tags, org_tags=org_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列表
|
||||
:param save_path: 保存目录
|
||||
:param category: 分类,Transmission 不支持
|
||||
:param ratio_limit: 分享率限制
|
||||
:param seeding_time_limit: 做种时间限制,单位分钟
|
||||
:return: 各项修改结果
|
||||
"""
|
||||
server: Transmission = self.get_instance(downloader)
|
||||
if not server:
|
||||
return None
|
||||
results = {}
|
||||
if any(
|
||||
value is not None
|
||||
for value in (download_limit, upload_limit, ratio_limit, seeding_time_limit)
|
||||
):
|
||||
change_result = server.change_torrent(
|
||||
hash_string=hash_string,
|
||||
download_limit=download_limit,
|
||||
upload_limit=upload_limit,
|
||||
ratio_limit=ratio_limit,
|
||||
seeding_time_limit=seeding_time_limit,
|
||||
)
|
||||
results["limits"] = change_result
|
||||
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 tracker_list is not None:
|
||||
results["trackers"] = server.update_tracker(
|
||||
hash_string=hash_string, tracker_list=tracker_list
|
||||
)
|
||||
if category is not None:
|
||||
results["category"] = False
|
||||
return results
|
||||
|
||||
def get_torrent_trackers(
|
||||
self,
|
||||
hash_string: str,
|
||||
downloader: Optional[str] = None,
|
||||
) -> Optional[Dict[str, List[str]]]:
|
||||
"""
|
||||
查询下载任务Tracker列表。
|
||||
:param hash_string: 种子Hash
|
||||
:param downloader: 下载器
|
||||
:return: 下载器名称到Tracker列表的映射
|
||||
"""
|
||||
if downloader:
|
||||
server: Transmission = self.get_instance(downloader)
|
||||
if not server:
|
||||
return None
|
||||
servers = {downloader: server}
|
||||
else:
|
||||
servers: Dict[str, Transmission] = self.get_instances()
|
||||
ret_trackers = {}
|
||||
for name, server in servers.items():
|
||||
trackers = server.get_trackers(hash_string)
|
||||
if trackers is not None:
|
||||
ret_trackers[name] = trackers
|
||||
return ret_trackers
|
||||
|
||||
def start_torrents(self, hashs: Union[list, str],
|
||||
downloader: Optional[str] = None) -> Optional[bool]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user