transmission

package module
v0.0.0-...-b11d7d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 7 Imported by: 14

README

Transmission JSON RPC client

This library implements a JSON RPC client for interacting with Transmission remotely.

For more information about the underlaying API, see the official documentation.

Versions

The master branch of this repository is compatible with the master branch of the upstream transmission project.

If you want to use this lib with transmission 2.94 please import this project using this command:

go get -u -v github.com/odwrtw/transmission@2.94

Usage

package main

import (
        "crypto/tls"
        "net/http"

        "github.com/kr/pretty"

        "github.com/odwrtw/transmission"
)

func main() {
        // Let's create a simple client
        conf := transmission.Config{
                Address: "http://localhost:9091/transmission/rpc",
        }
        t, err := transmission.New(conf)
        if err != nil {
                pretty.Println(err)
        }

        // With a self signed certificate
        tr := &http.Transport{
                TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
        }
        httpClient := http.Client{Transport: tr}

        conf = transmission.Config{
                Address:    "http://localhost:9091/transmission/rpc",
                HTTPClient: &httpClient,
        }
        t, err = transmission.New(conf)
        if err != nil {
                pretty.Println(err)
        }

        // Get all the torrents
        torrents, err := t.GetTorrents()
        if err != err {
                pretty.Println(err)
        }
        pretty.Println(torrents)

        // Add a torrent
        torrent, err := t.Add("http://cdimage.debian.org/debian-cd/8.1.0/amd64/bt-cd/debian-8.1.0-amd64-CD-1.iso.torrent")
        if err != nil {
                pretty.Println(err)
        }

        // Update it
        torrent.Update()
        pretty.Println(torrent)

        // Remove it
        err = t.RemoveTorrents([]*transmission.Torrent{torrent}, true)
        if err != nil {
                pretty.Println(err)
        }

        // Update and print the current session
        t.Session.Update()
        pretty.Println(t.Session)
}

Documentation

Index

Constants

View Source
const (
	// StatusStopped stopped
	StatusStopped = 0
	// StatusCheckPending check pending
	StatusCheckPending = 1
	// StatusChecking checking
	StatusChecking = 2
	// StatusDownloadPending download pending
	StatusDownloadPending = 3
	// StatusDownloading downloading
	StatusDownloading = 4
	// StatusSeedPending seed pending
	StatusSeedPending = 5
	// StatusSeeding seeding
	StatusSeeding = 6
)

Variables

View Source
var (
	// ErrDuplicateTorrent returned when the torrent is already added
	ErrDuplicateTorrent = errors.New("Torrent already added")
)

Functions

This section is empty.

Types

type AddTorrentArg

type AddTorrentArg struct {
	//The format of the "cookies" should be NAME=CONTENTS, where NAME is the
	//cookie name and CONTENTS is what the cookie should contain.  Set multiple
	//cookies like this: "name1=content1; name2=content2;" etc.
	//<http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCOOKIE>
	Cookies string `json:"cookies,omitempty"`
	// DownloadDir path to download the torrent to
	DownloadDir string `json:"download-dir,omitempty"`
	// Filename filename or URL of the .torrent file
	Filename string `json:"filename,omitempty"`
	// Metainfo base64-encoded .torrent content
	Metainfo string `json:"metainfo,omitempty"`
	// Paused if true add torrent paused default false
	Paused bool `json:"paused,omitempty"`
	// PeerLimit maximum number of peers
	PeerLimit int `json:"peer-limit,omitempty"`
	// BandwidthPriority torrent's bandwidth
	BandwidthPriority int   `json:",omitempty"`
	FilesWanted       []int `json:"files-wanted,omitempty"`
	FilesUnwanted     []int `json:"files-unwanted,omitempty"`
	PriorityHigh      []int `json:"priority-high,omitempty"`
	PriorityLow       []int `json:"priority-low,omitempty"`
	PriorityNormal    []int `json:"priority-normal,omitempty"`
}

AddTorrentArg params for Client.AddTorrent

type Client

type Client struct {
	Session *Session

	*Config
	// contains filtered or unexported fields
}

Client transmission client

func New

func New(conf Config) (*Client, error)

New create a new transmission client

func (*Client) Add

func (c *Client) Add(filename string) (*Torrent, error)

Add shortcut for Client.AddTorrent

func (*Client) AddTorrent

func (c *Client) AddTorrent(args AddTorrentArg) (*Torrent, error)

AddTorrent add torrent from filename or metadata see AddTorrentArg for arguments

func (*Client) BlocklistUpdate

func (c *Client) BlocklistUpdate() (int, error)

BlocklistUpdate update blocklist and return blocklist rules size

func (*Client) Do

func (c *Client) Do(req *http.Request, retry bool) (*http.Response, error)

Do low level function for interact with transmission only take care of authentification and session id

func (*Client) FreeSpace

func (c *Client) FreeSpace(path string) (int, error)

FreeSpace tests how much free space is available in a client-specified folder.

func (*Client) GetTorrentMap

func (c *Client) GetTorrentMap() (TorrentMap, error)

GetTorrentMap returns a map of torrents indexed by torrent hash.

func (*Client) GetTorrents

func (c *Client) GetTorrents() ([]*Torrent, error)

GetTorrents return list of torrent

func (*Client) PortTest

func (c *Client) PortTest() (bool, error)

PortTest tests to see if your incoming peer port is accessible from the outside world.

func (*Client) QueueMoveBottom

func (c *Client) QueueMoveBottom(torrents []*Torrent) error

QueueMoveBottom moves torrents to botton of the queue

func (*Client) QueueMoveDown

func (c *Client) QueueMoveDown(torrents []*Torrent) error

QueueMoveDown moves torrents down in the queue

func (*Client) QueueMoveTop

func (c *Client) QueueMoveTop(torrents []*Torrent) error

QueueMoveTop moves torrents to top of the queue

func (*Client) QueueMoveUp

func (c *Client) QueueMoveUp(torrents []*Torrent) error

QueueMoveUp moves torrents up in the queue

func (*Client) RemoveTorrents

func (c *Client) RemoveTorrents(torrents []*Torrent, removeData bool) error

RemoveTorrents remove torrents

type Config

type Config struct {
	Address  string
	User     string
	Password string
	// HTTPClient specify your own if you need default: http.Client
	HTTPClient *http.Client
}

Config used to configure transmission client

type File

type File struct {
	BytesCompleted int64
	Length         int64
	Name           string
}

File transmission API response

type FileStats

type FileStats struct {
	BytesCompleted int64
	Wanted         bool
	Priority       int
}

FileStats transmission API response

type Peers

type Peers struct {
	Address            string
	ClientName         string
	ClientIsChoked     bool
	ClientIsInterested bool
	FlagStr            string
	IsDownloadingFrom  bool
	IsEncrypted        bool
	IsIncoming         bool
	IsUploadingTo      bool
	IsUTP              bool
	PeerIsChoked       bool
	PeerIsInterested   bool
	Port               int
	Progress           float64
	RateToClient       int
	RateToPeer         int
}

Peers transmission API response

type PeersFrom

type PeersFrom struct {
	FromCache    int
	FromDht      int
	FromIncoming int
	FromLpd      int
	FromLtep     int
	FromPex      int
	FromTracker  int
}

PeersFrom transmission API response

type Request

type Request struct {
	Method    string      `json:"method"`
	Arguments interface{} `json:"arguments"`
}

Request object for API call

type Response

type Response struct {
	Arguments interface{} `json:"arguments"`
	Result    string      `json:"result"`
}

Response object for API call response

type Session

type Session struct {
	Client                    *Client `json:"-"`
	AltSpeedDown              int     `jsonn:"alt-speed-down"`
	AltSpeedEnabled           bool    `json:"alt-speed-enabled"`
	AltSpeedTimeBegin         int     `json:"alt-speed-time-begin"`
	AltSpeedTimeEnabled       bool    `json:"alt-speed-time-enabled"`
	AltSpeedTimeEnd           int     `json:"alt-speed-time-end"`
	AltSpeedTimeDay           int     `json:"alt-speed-time-day"`
	AltSpeedUp                int     `json:"alt-speed-up"`
	BlocklistURL              string  `json:"blocklist-url"`
	BlocklistEnabled          bool    `json:"blocklist-enabled"`
	BlocklistSize             int     `json:"blocklist-size"`
	CacheSizeMb               int     `json:"cache-size-mb"`
	ConfigDir                 string  `json:"config-dir"`
	DownloadDir               string  `json:"download-dir"`
	DownloadQueueSize         int     `json:"download-queue-size"`
	DownloadQueueEnabled      bool    `json:"download-queue-enabled"`
	DhtEnabled                bool    `json:"dht-enabled"`
	Encryption                string  `json:"encryption"`
	IdleSeedingLimit          int     `json:"idle-seeding-limit"`
	IdleSeedingLimitEnabled   bool    `json:"idle-seeding-limit-enabled"`
	IncompleteDir             string  `json:"incomplete-dir"`
	IncompleteDirEnabled      bool    `json:"incomplete-dir-enabled"`
	LpdEnabled                bool    `json:"lpd-enabled"`
	PeerLimitGlobal           int     `json:"peer-limit-global"`
	PeerLimitPerTorrent       int     `json:"peer-limit-per-torrent"`
	PexEnabled                bool    `json:"pex-enabled"`
	PeerPort                  int     `json:"peer-port"`
	PeerPortRandomOnStart     bool    `json:"peer-port-random-on-start"`
	PortForwardingEnabled     bool    `json:"port-forwarding-enabled"`
	QueueStalledEnabled       bool    `json:"queue-stalled-enabled"`
	QueueStalledMinutes       int     `json:"queue-stalled-minutes"`
	RenamePartialFiles        bool    `json:"rename-partial-files"`
	RPCVersion                int     `json:"rpc-version"`
	RPCVersionMinimum         int     `json:"rpc-version-minimum"`
	ScriptTorrentDoneFilename string  `json:"script-torrent-done-filename"`
	ScriptTorrentDoneEnabled  bool    `json:"script-torrent-done-enabled"`
	SeedRatioLimit            float64 `json:"seedRatioLimit"`
	SeedRatioLimited          bool    `json:"seedRatioLimited"`
	SeedQueueSize             int     `json:"seed-queue-size"`
	SeedQueueEnabled          bool    `json:"seed-queue-enabled"`
	SpeedLimitDown            int     `json:"speed-limit-down"`
	SpeedLimitDownEnabled     bool    `json:"speed-limit-down-enabled"`
	SpeedLimitUp              int     `json:"speed-limit-up"`
	SpeedLimitUpEnabled       bool    `json:"speed-limit-up-enabled"`
	StartAddedTorrents        bool    `json:"start-added-torrents"`
	TrashOriginalTorrentFiles bool    `json:"trash-original-torrent-files"`
	Units                     *Units  `json:"units"`
	UtpEnabled                bool    `json:"utp-enabled"`
	Version                   string  `json:"version"`
}

Session object contain information about transmission session and interact with it

func (*Session) Close

func (s *Session) Close() error

Close tells the transmission session to shut down.

func (*Session) Set

func (s *Session) Set(args SetSessionArgs) error

Set set session params see SetSessionArgs

func (*Session) Stats

func (s *Session) Stats() (Statistics, error)

Stats return session statistics

func (*Session) Update

func (s *Session) Update() error

Update session information from transmission

type SetSessionArgs

type SetSessionArgs struct {
	AltSpeedDown              int     `json:"alt-speed-down,omitempty"`
	AltSpeedEnabled           bool    `json:"alt-speed-enabled,omitempty"`
	AltSpeedTimeBegin         int     `json:"alt-speed-time-begin,omitempty"`
	AltSpeedTimeEnabled       bool    `json:"alt-speed-time-enabled,omitempty"`
	AltSpeedTimeEnd           int     `json:"alt-speed-time-end,omitempty"`
	AltSpeedTimeDay           int     `json:"alt-speed-time-day,omitempty"`
	AltSpeedUp                int     `json:"alt-speed-up,omitempty"`
	BlocklistURL              string  `json:"blocklist-url,omitempty"`
	BlocklistEnabled          bool    `json:"blocklist-enabled,omitempty"`
	CacheSizeMb               int     `json:"cache-size-mb,omitempty"`
	DownloadDir               string  `json:"download-dir,omitempty"`
	DownloadQueueSize         int     `json:"download-queue-size,omitempty"`
	DownloadQueueEnabled      bool    `json:"download-queue-enabled,omitempty"`
	DhtEnabled                bool    `json:"dht-enabled,omitempty"`
	Encryption                string  `json:"encryption,omitempty"`
	IdleSeedingLimit          int     `json:"idle-seeding-limit,omitempty"`
	IdleSeedingLimitEnabled   bool    `json:"idle-seeding-limit-enabled,omitempty"`
	IncompleteDir             string  `json:"incomplete-dir,omitempty"`
	IncompleteDirEnabled      bool    `json:"incomplete-dir-enabled,omitempty"`
	LpdEnabled                bool    `json:"lpd-enabled,omitempty"`
	PeerLimitGlobal           int     `json:"peer-limit-global,omitempty"`
	PeerLimitPerTorrent       int     `json:"peer-limit-per-torrent,omitempty"`
	PexEnabled                bool    `json:"pex-enabled,omitempty"`
	PeerPort                  int     `json:"peer-port,omitempty"`
	PeerPortRandomOnStart     bool    `json:"peer-port-random-on-start,omitempty"`
	PortForwardingEnabled     bool    `json:"port-forwarding-enabled,omitempty"`
	QueueStalledEnabled       bool    `json:"queue-stalled-enabled,omitempty"`
	QueueStalledMinutes       int     `json:"queue-stalled-minutes,omitempty"`
	RenamePartialFiles        bool    `json:"rename-partial-files,omitempty"`
	ScriptTorrentDoneFilename string  `json:"script-torrent-done-filename,omitempty"`
	ScriptTorrentDoneEnabled  bool    `json:"script-torrent-done-enabled,omitempty"`
	SeedRatioLimit            float64 `json:"seedRatioLimit,omitempty"`
	SeedRatioLimited          bool    `json:"seedRatioLimited,omitempty"`
	SeedQueueSize             int     `json:"seed-queue-size,omitempty"`
	SeedQueueEnabled          bool    `json:"seed-queue-enabled,omitempty"`
	SpeedLimitDown            int     `json:"speed-limit-down,omitempty"`
	SpeedLimitDownEnabled     bool    `json:"speed-limit-down-enabled,omitempty"`
	SpeedLimitUp              int     `json:"speed-limit-up,omitempty"`
	SpeedLimitUpEnabled       bool    `json:"speed-limit-up-enabled,omitempty"`
	StartAddedTorrents        bool    `json:"start-added-torrents,omitempty"`
	TrashOriginalTorrentFiles bool    `json:"trash-original-torrent-files,omitempty"`
	Units                     *Units  `json:"units,omitempty"`
	UtpEnabled                bool    `json:"utp-enabled,omitempty"`
}

SetSessionArgs arguments for Session.Set

type SetTorrentArg

type SetTorrentArg struct {
	BandwidthPriority   int      `json:"bandwidthPriority,omitempty"`
	DownloadLimit       int      `json:"downloadLimit,omitempty"`
	DownloadLimited     bool     `json:"downloadLimited,omitempty"`
	FilesWanted         []int    `json:"files-wanted,omitempty"`
	FilesUnwanted       []int    `json:"files-unwanted,omitempty"`
	HonorsSessionLimits bool     `json:"honorsSessionLimits,omitempty"`
	Ids                 int      `json:"ids"`
	Labels              []string `json:"labels,omitempty"`
	Location            string   `json:"location,omitempty"`
	PeerLimit           int      `json:"peer-limit,omitempty"`
	PriorityHigh        []int    `json:"priority-high,omitempty"`
	PriorityLow         []int    `json:"priority-low,omitempty"`
	PriorityNormal      []int    `json:"priority-normal,omitempty"`
	QueuePosition       int      `json:"queuePosition,omitempty"`
	SeedIdleLimit       int      `json:"seedIdleLimit,omitempty"`
	SeedIdleMode        int      `json:"seedIdleMode,omitempty"`
	SeedRatioLimit      float64  `json:"seedRatioLimit,omitempty"`
	SeedRatioMode       int      `json:"seedRatioMode,omitempty"`
	TrackerAdd          []string `json:"trackerAdd,omitempty"`
	TrackerRemove       []int    `json:"trackerRemove,omitempty"`
	// TrackerReplace       `json:"trackerReplace,omitempty"`
	UploadLimit   int  `json:"uploadLimit,omitempty"`
	UploadLimited bool `json:"uploadLimited,omitempty"`
}

SetTorrentArg arguments for Torrent.Set method

type StatisticDetail

type StatisticDetail struct {
	UploadedBytes   int64
	DownloadedBytes int64
	FilesAdded      int64
	SessionCount    int64
	SecondsActive   int64
}

StatisticDetail represent statistics details

type Statistics

type Statistics struct {
	ActiveTorrentCount int
	DownloadSpeed      int
	PausedTorrentCount int
	TorrentCount       int
	UploadSpeed        int
	CumulativeStats    *StatisticDetail `json:"cumulative-stats"`
	CurrentStats       *StatisticDetail `json:"current-stats"`
}

Statistics represent session statistics

type Torrent

type Torrent struct {
	Client                  *Client `json:"-"`
	ActivityDate            int
	AddedDate               int
	BandwidthPriority       int
	Comment                 string
	CorruptEver             int64
	Creator                 string
	DateCreated             int
	DesiredAvailable        int64
	DoneDate                int
	DownloadDir             string
	DownloadedEver          int64
	DownloadLimit           int
	DownloadLimited         bool
	Error                   int
	ErrorString             string
	Eta                     int
	EtaIdle                 int
	Files                   *[]File
	FileStats               *[]FileStats
	HashString              string
	HaveUnchecked           int64
	HaveValid               int64
	HonorsSessionLimits     bool
	ID                      int
	IsFinished              bool
	IsPrivate               bool
	IsStalled               bool
	Labels                  []string
	LeftUntilDone           int64
	MagnetLink              string
	ManualAnnounceTime      int
	MaxConnectedPeers       int
	MetadataPercentComplete float64
	Name                    string
	Peerlimit               int
	Peers                   *[]Peers
	PeersConnected          int
	PeersFrom               PeersFrom
	PeersGettingFromUs      int
	PeersSendingToUs        int
	PercentDone             float64
	Pieces                  string
	PieceCount              int
	PieceSize               int
	Priorities              []int
	QueuePosition           int
	RateDownload            int
	RateUpload              int
	RecheckProgress         float64
	SecondsDownloading      int
	SecondsSeeding          int
	SeedIdleLimit           int
	SeedIdleMode            int
	SeedRatioLimit          float64
	SeedRatioMode           int
	SizeWhenDone            int64
	StartDate               int
	Status                  int
	Trackers                *[]Trackers
	TrackerStats            *[]TrackerStats
	TotalSize               int64
	TorrentFile             string
	UploadedEver            int64
	UploadLimit             int
	UploadLimited           bool
	UploadRatio             float64
	Wanted                  []int
	Webseeds                []string
	WebseedsSendingToUs     int
}

Torrent represent a torrent present in transmission

func (*Torrent) PathRename

func (t *Torrent) PathRename(path string, newPath string) error

PathRename renames a file or directory in a torrent.

func (*Torrent) Reannounce

func (t *Torrent) Reannounce() error

Reannounce torrent

func (*Torrent) Set

func (t *Torrent) Set(arg SetTorrentArg) error

Set changes torrent param see SetTorrentArg

func (*Torrent) SetLocation

func (t *Torrent) SetLocation(path string, move bool) error

SetLocation moves a Torrent move if true, move from previous location. otherwise, search "location" for files

func (*Torrent) Start

func (t *Torrent) Start() error

Start torrent

func (*Torrent) StartNow

func (t *Torrent) StartNow() error

StartNow torrent

func (*Torrent) Stop

func (t *Torrent) Stop() error

Stop torrent

func (*Torrent) Update

func (t *Torrent) Update() error

Update torrent information from transmission

func (*Torrent) Verify

func (t *Torrent) Verify() error

Verify torrent

type TorrentMap

type TorrentMap map[string]*Torrent

TorrentMap is a map of Torrents indexed by torrent hash.

type Torrents

type Torrents struct {
	Torrents []*Torrent `json:"torrents"`
}

Torrents a list of Torrents

type TrackerStats

type TrackerStats struct {
	Announce              string
	AnnounceState         int
	DownloadCount         int
	HasAnnounced          bool
	HasScraped            bool
	Host                  string
	ID                    int
	IsBackup              bool
	LastAnnouncePeerCount int
	LastAnnounceResult    string
	LastAnnounceStartTime int
	LastAnnounceSucceeded bool
	LastAnnounceTime      int
	LastAnnounceTimedOut  bool
	LastScrapeResult      string
	LastScrapeStartTime   int
	LastScrapeSucceeded   bool
	LastScrapeTime        int
	LastScrapeTimedOut    bool
	LeecherCount          int
	NextAnnounceTime      int
	NextScrapeTim         int
	Scrap                 string
	ScrapeState           int
	SeederCount           int
	Tier                  int
}

TrackerStats transmission API response

type Trackers

type Trackers struct {
	Announce string
	ID       int
	Scrape   string
	Tier     int
}

Trackers from transmission API response

type Units

type Units struct {
	SpeedUnits  []string `json:"speed-units"`
	SpeedBytes  int      `json:"speed-bytes"`
	SizeUnits   []string `json:"size-units"`
	SizeBytes   int      `json:"size-bytes"`
	MemoryUnits []string `json:"memory-units"`
	MemoryBytes int      `json:"memory-bytes"`
}

Units in session

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL