1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
# Copyright (c) 2018-2022 Trim21 <i@trim21.me>
# Copyright (c) 2008-2014 Erik Svensson <erik.public@gmail.com>
# Licensed under the MIT license.
from __future__ import annotations
import enum
import logging
from typing import NamedTuple
LOGGER = logging.getLogger("transmission-rpc")
LOGGER.setLevel(logging.ERROR)
DEFAULT_TIMEOUT = 30.0
class Priority(enum.IntEnum):
Low = -1
Normal = 0
High = 1
class RatioLimitMode(enum.IntEnum):
"""torrent radio limit mode"""
#: follow the global settings
Global = 0
#: override the global settings, seeding until a certain ratio
Single = 1
#: override the global settings, seeding regardless of ratio
Unlimited = 2
class IdleMode(enum.IntEnum):
"""torrent idle mode"""
#: follow the global settings
Global = 0
#: override the global settings, seeding until a certain idle time
Single = 1
#: override the global settings, seeding regardless of activity
Unlimited = 2
class Args(NamedTuple):
type: str
added_version: int
removed_version: int | None = None
previous_argument_name: str | None = None
next_argument_name: str | None = None
description: str = ""
def __repr__(self) -> str:
return (
f"Args({self.type!r},"
f" {self.added_version!r},"
f" {self.removed_version!r},"
f" {self.previous_argument_name!r},"
f" {self.next_argument_name!r},"
f" {self.description!r})"
)
def __str__(self) -> str:
return f"Args<type={self.type}, {self.added_version}, description={self.description!r})"
class Type:
number = "number"
string = "string"
array = "array"
boolean = "boolean"
double = "double"
object = "object"
TORRENT_GET_ARGS: dict[str, Args] = {
"activityDate": Args(Type.number, 1, description="Last time of upload or download activity."),
"addedDate": Args(Type.number, 1, description="The date when this torrent was first added."),
"bandwidthPriority": Args(Type.number, 5, description="Bandwidth priority. Low (-1), Normal (0) or High (1)."),
"comment": Args(Type.string, 1, description="Torrent comment."),
"corruptEver": Args(Type.number, 1, description="Number of bytes of corrupt data downloaded."),
"creator": Args(Type.string, 1, description="Torrent creator."),
"dateCreated": Args(Type.number, 1, description="Torrent creation date."),
"desiredAvailable": Args(Type.number, 1, description="Number of bytes available and left to be downloaded."),
"doneDate": Args(Type.number, 1, description="The date when the torrent finished downloading."),
"downloadDir": Args(Type.string, 4, description="The directory path where the torrent is downloaded to."),
"downloadedEver": Args(Type.number, 1, description="Number of bytes of good data downloaded."),
"downloadLimit": Args(Type.number, 1, None, None, None, "Download limit in Kbps."),
"downloadLimitMode": Args(
Type.number, 1, 5, description="Download limit mode. 0 means global, 1 means single, 2 unlimited."
),
"downloadLimited": Args(Type.boolean, 5, None, None, None, "Download limit is enabled"),
"editDate": Args(Type.number, 16),
"error": Args(
Type.number,
1,
description="Kind of error. 0 means OK, 1 means tracker warning, 2 means tracker error, 3 means local error.",
),
"errorString": Args(Type.number, 1, None, None, None, "Error message."),
"eta": Args(
Type.number,
1,
description="Estimated number of seconds left when downloading or seeding. -1 means not available and -2 means unknown.",
),
"etaIdle": Args(
Type.number,
15,
description="Estimated number of seconds left until the idle time limit is reached. -1 means not available and -2 means unknown.",
),
"files": Args(Type.array, 1, description="Array of file object containing key, bytesCompleted, length and name."),
"fileStats": Args(
Type.array, 5, description="Away of file statistics containing bytesCompleted, wanted and priority."
),
"group": Args(Type.string, 17, description="The name of this torrent's bandwidth group"),
"hashString": Args(Type.string, 1, description="Hashstring unique for the torrent even between sessions."),
"haveUnchecked": Args(Type.number, 1, None, None, None, "Number of bytes of partial pieces."),
"haveValid": Args(Type.number, 1, description="Number of bytes of checksum verified data."),
"honorsSessionLimits": Args(Type.boolean, 5, description="True if session upload limits are honored"),
"id": Args(Type.number, 1, None, None, None, "Session unique torrent id."),
"isFinished": Args(Type.boolean, 9, description="True if the torrent is finished. Downloaded and seeded."),
"isPrivate": Args(Type.boolean, 1, None, None, None, "True if the torrent is private."),
"isStalled": Args(Type.boolean, 14, description="True if the torrent has stalled (been idle for a long time)."),
"labels": Args(Type.array, 16, None, None, None, "array of string labels"),
"leftUntilDone": Args(Type.number, 1, description="Number of bytes left until the download is done."),
"magnetLink": Args(Type.string, 7, None, None, None, "The magnet link for this torrent."),
"manualAnnounceTime": Args(Type.number, 1, description="The time until you manually ask for more peers."),
"maxConnectedPeers": Args(Type.number, 1, None, None, None, "Maximum of connected peers."),
"metadataPercentComplete": Args(Type.double, 7, description="Download progress of metadata. 0.0 to 1.0."),
"name": Args(Type.string, 1, None, None, None, "Torrent name."),
"peer-limit": Args(Type.number, 5, None, None, None, "Maximum number of peers."),
"peers": Args(Type.array, 2, None, None, None, "Array of peer objects."),
"peersConnected": Args(Type.number, 1, None, None, None, "Number of peers we are connected to."),
"peersFrom": Args(Type.object, 1, description="Object containing download peers counts for different peer types."),
"peersGettingFromUs": Args(Type.number, 1, description="Number of peers we are sending data to."),
"peersSendingToUs": Args(Type.number, 1, None, None, None, "Number of peers sending to us"),
"percentComplete": Args(Type.double, 17),
"percentDone": Args(Type.double, 5, description="Download progress of selected files. 0.0 to 1.0."),
"pieces": Args(Type.string, 5, description="String with base64 encoded bitfield indicating finished pieces."),
"pieceCount": Args(Type.number, 1, None, None, None, "Number of pieces."),
"pieceSize": Args(Type.number, 1, None, None, None, "Number of bytes in a piece."),
"priorities": Args(Type.array, 1, None, None, None, "Array of file priorities."),
"primary-mime-type": Args(Type.string, 17),
"queuePosition": Args(Type.number, 14, None, None, None, "The queue position."),
"rateDownload": Args(Type.number, 1, None, None, None, "(B/s)"),
"rateUpload": Args(Type.number, 1, None, None, None, "(B/s)"),
"recheckProgress": Args(Type.double, 1, None, None, None, "Progress of recheck. 0.0 to 1.0."),
"secondsDownloading": Args(Type.number, 15, None, None, None, ""),
"secondsSeeding": Args(Type.number, 15, None, None, None, ""),
"seedIdleLimit": Args(Type.number, 10, None, None, None, "Idle limit in minutes."),
"seedIdleMode": Args(Type.number, 10, description="Use global (0), torrent (1), or unlimited (2) limit."),
"seedRatioLimit": Args(Type.double, 5, None, None, None, "Seed ratio limit."),
"seedRatioMode": Args(Type.number, 5, description="Use global (0), torrent (1), or unlimited (2) limit."),
"sizeWhenDone": Args(Type.number, 1, description="Size of the torrent download in bytes."),
"startDate": Args(Type.number, 1, description="The date when the torrent was last started."),
"status": Args(Type.number, 1, None, None, None, "Current status, see source"),
"trackers": Args(Type.array, 1, None, None, None, "Array of tracker objects."),
"trackerStats": Args(Type.object, 7, description="Array of object containing tracker statistics."),
"totalSize": Args(Type.number, 1, None, None, None, "Total size of the torrent in bytes"),
"torrentFile": Args(Type.string, 5, None, None, None, "Path to .torrent file."),
"uploadedEver": Args(Type.number, 1, None, None, None, "Number of bytes uploaded, ever."),
"uploadLimit": Args(Type.number, 1, None, None, None, "Upload limit in Kbps"),
"uploadLimited": Args(Type.boolean, 5, None, None, None, "Upload limit enabled."),
"uploadRatio": Args(Type.double, 1, None, None, None, "Seed ratio."),
"wanted": Args(Type.array, 1, description="Array of booleans indicated wanted files."),
"webseeds": Args(Type.array, 1, None, None, None, "Array of webseeds objects"),
"webseedsSendingToUs": Args(Type.number, 1, None, None, None, "Number of webseeds seeding to us."),
"file-count": Args(Type.number, 17),
"trackerList": Args(
Type.array,
17,
description="A Iterable[Iterable[str]] for a set of announce URLs, each inner list is for a tier",
),
}
class RpcMethod(str, enum.Enum):
SessionSet = "session-set"
SessionGet = "session-get"
SessionStats = "session-stats"
TorrentGet = "torrent-get"
TorrentAdd = "torrent-add"
TorrentSet = "torrent-set"
TorrentRemove = "torrent-remove"
TorrentStart = "torrent-start"
TorrentStartNow = "torrent-start-now" # added in 2.40
TorrentStop = "torrent-stop"
TorrentVerify = "torrent-verify"
TorrentReannounce = "torrent-reannounce"
TorrentSetLocation = "torrent-set-location"
TorrentRenamePath = "torrent-rename-path"
QueueMoveTop = "queue-move-top"
QueueMoveBottom = "queue-move-bottom"
QueueMoveUp = "queue-move-up"
QueueMoveDown = "queue-move-down"
GroupSet = "group-set"
GroupGet = "group-get"
FreeSpace = "free-space"
PortTest = "port-test"
BlocklistUpdate = "blocklist-update"
|