Linuxmint中的还是transmission3版本,首先安装transmission4。
1、安装transmission4:
sudo add-apt-repository ppa:ubuntuhandbook1/transmission_rpc
sudo apt update
sudo apt install transmission-gtk
2、安装transmission_rpc:
pip install transmission_rpc
3、连接transmission4:
from transmission_rpc import Client
client = Client(host="localhost", port=9091, username="111", password="123456")
4、遍历下载的任务:
# 获取所有活动(包括下载中、错误、已停止等状态)的torrent
torrents = client.get_torrents()
for torrent in torrents:
print(f"{torrent.name}")
5、修改添加种子的trackerlist:
注意tracker_list的格式!!!
清空种子的trackerlist就传入空list。
经测试,似乎tracker_list最多添加33个,超过33个会报错:
transmission_rpc.error.TransmissionError: Query failed with result "Invalid tracker list".
client.change_torrent(
torrent.id,
tracker_list=[
["https://tracker1/announce"],
["https://backup1.example.com/announce"],
["https://backup2.example.com/announce"],
],
)
# 种子tracker数目
print(len(torrent.trackers))
6、暂停、恢复下载种子
client.stop_torrent(torrent.id) # 暂停
client.start_torrent(torrent.id) # 恢复下载
7、取消和恢复下载种子内的指定文件
取消下载指定文件:files_unwanted 恢复下载指定文件:files_wanted
client.change_torrent(
torrent.hashString,
files_unwanted=[
f.id for f in torrent.get_files() if f.name.endswith(".jpg")
],
)
8、遍历种子内的所有文件
torrents = client.get_torrents()
for torrent in torrents:
print(f"torrent: {torrent.name}")
for t in torrent.get_files():
print(f"{t.name} - {t.id}")
9、重命名种子内的文件或者文件夹
location:要重命名的文件夹或文件的在种子内的全路径 name:重命名后的文件名,不用附带全路径,只是名字
# 重命名文件
client.rename_torrent_path(torrent.id, location="4/4.jpg", name="12.jpg")
# 重命名文件夹
client.rename_torrent_path(torrent.id, location="4/文件夹1", name="test")
client.rename_torrent_path(torrent.id, location="文件夹", name="test")