feat: 增加session方法,用于获取tr的会话、配置信息

This commit is contained in:
jeblove 2024-03-28 21:24:16 +08:00
parent ff07841dd6
commit c180e50164

View File

@ -1,4 +1,4 @@
from typing import Optional, Union, Tuple, List from typing import Optional, Union, Tuple, List, Dict
import transmission_rpc import transmission_rpc
from transmission_rpc import Client, Torrent, File from transmission_rpc import Client, Torrent, File
@ -18,7 +18,7 @@ class Transmission:
trc: Optional[Client] = None trc: Optional[Client] = None
# 参考transmission web仅查询需要的参数加速种子搜索 # 参考transmission web仅查询需要的参数加速种子搜索
_trarg = ["id", "name", "status", "labels", "hashString", "totalSize", "percentDone", "addedDate", "trackerStats", _trarg = ["id", "name", "status", "labels", "hashString", "totalSize", "percentDone", "addedDate", "trackerList", "trackerStats",
"leftUntilDone", "rateDownload", "rateUpload", "recheckProgress", "rateDownload", "rateUpload", "leftUntilDone", "rateDownload", "rateUpload", "recheckProgress", "rateDownload", "rateUpload",
"peersGettingFromUs", "peersSendingToUs", "uploadRatio", "uploadedEver", "downloadedEver", "downloadDir", "peersGettingFromUs", "peersSendingToUs", "uploadRatio", "uploadedEver", "downloadedEver", "downloadDir",
"error", "errorString", "doneDate", "queuePosition", "activityDate", "trackers"] "error", "errorString", "doneDate", "queuePosition", "activityDate", "trackers"]
@ -395,3 +395,16 @@ class Transmission:
except Exception as err: except Exception as err:
logger.error(f"修改tracker出错{str(err)}") logger.error(f"修改tracker出错{str(err)}")
return False return False
def get_session(self) -> Dict[str, Union[int, bool, str]]:
"""
获取Transmission当前的会话信息和配置设置
:return dict or False
"""
if not self.trc:
return False
try:
return self.trc.get_session()
except Exception as err:
logger.error(f"获取session出错{str(err)}")
return False