1package transmission 2 3// SetSessionArgs arguments for Session.Set 4type SetSessionArgs struct { 5 AltSpeedDown int `json:"alt-speed-down,omitempty"` 6 AltSpeedEnabled bool `json:"alt-speed-enabled,omitempty"` 7 AltSpeedTimeBegin int `json:"alt-speed-time-begin,omitempty"` 8 AltSpeedTimeEnabled bool `json:"alt-speed-time-enabled,omitempty"` 9 AltSpeedTimeEnd int `json:"alt-speed-time-end,omitempty"` 10 AltSpeedTimeDay int `json:"alt-speed-time-day,omitempty"` 11 AltSpeedUp int `json:"alt-speed-up,omitempty"` 12 BlocklistURL string `json:"blocklist-url,omitempty"` 13 BlocklistEnabled bool `json:"blocklist-enabled,omitempty"` 14 CacheSizeMb int `json:"cache-size-mb,omitempty"` 15 DownloadDir string `json:"download-dir,omitempty"` 16 DownloadQueueSize int `json:"download-queue-size,omitempty"` 17 DownloadQueueEnabled bool `json:"download-queue-enabled,omitempty"` 18 DhtEnabled bool `json:"dht-enabled,omitempty"` 19 Encryption string `json:"encryption,omitempty"` 20 IdleSeedingLimit int `json:"idle-seeding-limit,omitempty"` 21 IdleSeedingLimitEnabled bool `json:"idle-seeding-limit-enabled,omitempty"` 22 IncompleteDir string `json:"incomplete-dir,omitempty"` 23 IncompleteDirEnabled bool `json:"incomplete-dir-enabled,omitempty"` 24 LpdEnabled bool `json:"lpd-enabled,omitempty"` 25 PeerLimitGlobal int `json:"peer-limit-global,omitempty"` 26 PeerLimitPerTorrent int `json:"peer-limit-per-torrent,omitempty"` 27 PexEnabled bool `json:"pex-enabled,omitempty"` 28 PeerPort int `json:"peer-port,omitempty"` 29 PeerPortRandomOnStart bool `json:"peer-port-random-on-start,omitempty"` 30 PortForwardingEnabled bool `json:"port-forwarding-enabled,omitempty"` 31 QueueStalledEnabled bool `json:"queue-stalled-enabled,omitempty"` 32 QueueStalledMinutes int `json:"queue-stalled-minutes,omitempty"` 33 RenamePartialFiles bool `json:"rename-partial-files,omitempty"` 34 ScriptTorrentDoneFilename string `json:"script-torrent-done-filename,omitempty"` 35 ScriptTorrentDoneEnabled bool `json:"script-torrent-done-enabled,omitempty"` 36 SeedRatioLimit float64 `json:"seedRatioLimit,omitempty"` 37 SeedRatioLimited bool `json:"seedRatioLimited,omitempty"` 38 SeedQueueSize int `json:"seed-queue-size,omitempty"` 39 SeedQueueEnabled bool `json:"seed-queue-enabled,omitempty"` 40 SpeedLimitDown int `json:"speed-limit-down,omitempty"` 41 SpeedLimitDownEnabled bool `json:"speed-limit-down-enabled,omitempty"` 42 SpeedLimitUp int `json:"speed-limit-up,omitempty"` 43 SpeedLimitUpEnabled bool `json:"speed-limit-up-enabled,omitempty"` 44 StartAddedTorrents bool `json:"start-added-torrents,omitempty"` 45 TrashOriginalTorrentFiles bool `json:"trash-original-torrent-files,omitempty"` 46 Units *Units `json:"units,omitempty"` 47 UtpEnabled bool `json:"utp-enabled,omitempty"` 48} 49 50// Session object contain information about transmission 51// session and interact with it 52type Session struct { 53 Client *Client `json:"-"` 54 AltSpeedDown int `jsonn:"alt-speed-down"` 55 AltSpeedEnabled bool `json:"alt-speed-enabled"` 56 AltSpeedTimeBegin int `json:"alt-speed-time-begin"` 57 AltSpeedTimeEnabled bool `json:"alt-speed-time-enabled"` 58 AltSpeedTimeEnd int `json:"alt-speed-time-end"` 59 AltSpeedTimeDay int `json:"alt-speed-time-day"` 60 AltSpeedUp int `json:"alt-speed-up"` 61 BlocklistURL string `json:"blocklist-url"` 62 BlocklistEnabled bool `json:"blocklist-enabled"` 63 BlocklistSize int `json:"blocklist-size"` 64 CacheSizeMb int `json:"cache-size-mb"` 65 ConfigDir string `json:"config-dir"` 66 DownloadDir string `json:"download-dir"` 67 DownloadQueueSize int `json:"download-queue-size"` 68 DownloadQueueEnabled bool `json:"download-queue-enabled"` 69 DhtEnabled bool `json:"dht-enabled"` 70 Encryption string `json:"encryption"` 71 IdleSeedingLimit int `json:"idle-seeding-limit"` 72 IdleSeedingLimitEnabled bool `json:"idle-seeding-limit-enabled"` 73 IncompleteDir string `json:"incomplete-dir"` 74 IncompleteDirEnabled bool `json:"incomplete-dir-enabled"` 75 LpdEnabled bool `json:"lpd-enabled"` 76 PeerLimitGlobal int `json:"peer-limit-global"` 77 PeerLimitPerTorrent int `json:"peer-limit-per-torrent"` 78 PexEnabled bool `json:"pex-enabled"` 79 PeerPort int `json:"peer-port"` 80 PeerPortRandomOnStart bool `json:"peer-port-random-on-start"` 81 PortForwardingEnabled bool `json:"port-forwarding-enabled"` 82 QueueStalledEnabled bool `json:"queue-stalled-enabled"` 83 QueueStalledMinutes int `json:"queue-stalled-minutes"` 84 RenamePartialFiles bool `json:"rename-partial-files"` 85 RPCVersion int `json:"rpc-version"` 86 RPCVersionMinimum int `json:"rpc-version-minimum"` 87 ScriptTorrentDoneFilename string `json:"script-torrent-done-filename"` 88 ScriptTorrentDoneEnabled bool `json:"script-torrent-done-enabled"` 89 SeedRatioLimit float64 `json:"seedRatioLimit"` 90 SeedRatioLimited bool `json:"seedRatioLimited"` 91 SeedQueueSize int `json:"seed-queue-size"` 92 SeedQueueEnabled bool `json:"seed-queue-enabled"` 93 SpeedLimitDown int `json:"speed-limit-down"` 94 SpeedLimitDownEnabled bool `json:"speed-limit-down-enabled"` 95 SpeedLimitUp int `json:"speed-limit-up"` 96 SpeedLimitUpEnabled bool `json:"speed-limit-up-enabled"` 97 StartAddedTorrents bool `json:"start-added-torrents"` 98 TrashOriginalTorrentFiles bool `json:"trash-original-torrent-files"` 99 Units *Units `json:"units"` 100 UtpEnabled bool `json:"utp-enabled"` 101 Version string `json:"version"` 102} 103 104// Statictics represent session statictics 105type Statictics struct { 106 ActiveTorrentCount int 107 DownloadSpeed int 108 PausedTorrentCount int 109 TorrentCount int 110 UploadSpeed int 111 CumulativeStats *StaticticDetail `json:"cumulative-stats"` 112 CurrentStats *StaticticDetail `json:"current-stats"` 113} 114 115// StaticticDetail represent statictics details 116type StaticticDetail struct { 117 UploadedBytes int 118 DownloadedBytes int 119 FilesAdded int 120 SessionCount int 121 SecondsActive int 122} 123 124// Units in session 125type Units struct { 126 SpeedUnits []string `json:"speed-units"` 127 SpeedBytes int `json:"speed-bytes"` 128 SizeUnits []string `json:"size-units"` 129 SizeBytes int `json:"size-bytes"` 130 MemoryUnits []string `json:"memory-units"` 131 MemoryBytes int `json:"memory-bytes"` 132} 133 134// Set set session params see SetSessionArgs 135func (s *Session) Set(args SetSessionArgs) error { 136 tReq := &Request{ 137 Arguments: args, 138 Method: "session-set", 139 } 140 r := &Response{} 141 err := s.Client.request(tReq, r) 142 if err != nil { 143 return err 144 } 145 return nil 146} 147 148// Update session information from transmission 149func (s *Session) Update() error { 150 tReq := &Request{ 151 Method: "session-get", 152 } 153 r := &Response{Arguments: s} 154 155 err := s.Client.request(tReq, r) 156 if err != nil { 157 return err 158 } 159 return nil 160} 161 162// Stats return session statictics 163func (s *Session) Stats() (Statictics, error) { 164 tReq := &Request{ 165 Method: "session-stats", 166 } 167 168 stat := Statictics{} 169 170 r := &Response{Arguments: &stat} 171 172 err := s.Client.request(tReq, r) 173 if err != nil { 174 return Statictics{}, err 175 } 176 177 return stat, nil 178} 179 180// Close tells the transmission session to shut down. 181func (s *Session) Close() error { 182 tReq := &Request{ 183 Method: "session-close", 184 } 185 r := &Response{} 186 187 err := s.Client.request(tReq, r) 188 if err != nil { 189 return err 190 } 191 return nil 192} 193