Documentation ¶
Overview ¶
Package delugeclient allows calling native RPC methods on a remote deluge server.
Index ¶
- Constants
- Variables
- type Account
- type AuthLevel
- type Client
- func (c *Client) AddTorrentFile(fileName, fileContentBase64 string, options *Options) (string, error)
- func (c *Client) AddTorrentMagnet(magnetURI string, options *Options) (string, error)
- func (c *Client) AddTorrentURL(url string, options *Options) (string, error)
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) DaemonLogin() error
- func (c *Client) DaemonVersion() (string, error)
- func (c *Client) DisablePlugin(name string) error
- func (c *Client) EnablePlugin(name string) error
- func (c *Client) ForceReannounce(ids []string) error
- func (c *Client) GetAvailablePlugins() ([]string, error)
- func (c *Client) GetEnabledPlugins() ([]string, error)
- func (c *Client) GetFreeSpace(path string) (int64, error)
- func (c *Client) GetLibtorrentVersion() (string, error)
- func (c *Client) GetListenPort() (uint16, error)
- func (c *Client) GetSessionStatus() (*SessionStatus, error)
- func (c *Client) LabelPlugin() (*LabelPlugin, error)
- func (c *Client) MethodsList() ([]string, error)
- func (c *Client) MoveStorage(torrentIDs []string, dest string) error
- func (c *Client) PauseTorrents(ids ...string) error
- func (c *Client) RemoveTorrent(id string, rmFiles bool) (bool, error)
- func (c *Client) RemoveTorrents(ids []string, rmFiles bool) ([]TorrentError, error)
- func (c *Client) ResumeTorrents(ids ...string) error
- func (c *Client) SessionState() ([]string, error)
- func (c *Client) SetTorrentOptions(id string, options *Options) error
- func (c *Client) SetTorrentTracker(id, trackerURL string) error
- func (c *Client) TestListenPort() (bool, error)
- func (c *Client) TorrentStatus(hash string) (*TorrentStatus, error)
- func (c *Client) TorrentsStatus(state TorrentState, hashes []string) (map[string]*TorrentStatus, error)
- type ClientV2
- type DelugeClient
- type DelugeResponse
- type File
- type LabelPlugin
- func (p LabelPlugin) AddLabel(label string) error
- func (p LabelPlugin) GetLabels() ([]string, error)
- func (p LabelPlugin) GetTorrentLabel(hash string) (string, error)
- func (p LabelPlugin) GetTorrentsLabels(state TorrentState, ids []string) (map[string]string, error)
- func (p LabelPlugin) RemoveLabel(label string) error
- func (p LabelPlugin) SetTorrentLabel(hash, label string) error
- type Options
- type Peer
- type RPCError
- type SerialMismatchError
- type SessionStatus
- type Settings
- type TorrentError
- type TorrentState
- type TorrentStatus
- type V2
- type V2Options
Constants ¶
const ( // DefaultReadWriteTimeout is the default timeout for I/O operations with the Deluge server. DefaultReadWriteTimeout = time.Second * 30 )
const Deluge2ProtocolVersion = 1
Deluge2ProtocolVersion is the protocol version used with Deluge v2+
Variables ¶
var ( // ErrAlreadyClosed is returned when connection is already closed. ErrAlreadyClosed = errors.New("connection is already closed") // ErrInvalidDictionaryResponse is returned when the expected dictionary as list is not received. ErrInvalidDictionaryResponse = errors.New("expected dictionary as list response") // ErrInvalidReturnValue is returned when the returned value received from server is invalid. ErrInvalidReturnValue = errors.New("invalid return value") )
Functions ¶
This section is empty.
Types ¶
type AuthLevel ¶ added in v0.5.4
type AuthLevel string
AuthLevel is an Auth Level string understood by Deluge
const ( AuthLevelNone AuthLevel = "NONE" AuthLevelReadonly AuthLevel = "READONLY" AuthLevelNormal AuthLevel = "NORMAL" AuthLevelAdmin AuthLevel = "ADMIN" AuthLevelDefault AuthLevel = AuthLevelNormal )
The auth level names, as defined in https://github.com/deluge-torrent/deluge/blob/deluge-2.0.3/deluge/core/authmanager.py#L33-L37
type Client ¶
type Client struct { DebugServerResponses []*bytes.Buffer // contains filtered or unexported fields }
Client is a Deluge RPC client.
func (*Client) AddTorrentFile ¶ added in v0.5.4
func (c *Client) AddTorrentFile(fileName, fileContentBase64 string, options *Options) (string, error)
AddTorrentFile adds a torrent via a base64 encoded file and returns the torrent hash.
func (*Client) AddTorrentMagnet ¶
AddTorrentMagnet adds a torrent via magnet URI and returns the torrent hash.
func (*Client) AddTorrentURL ¶ added in v0.2.1
AddTorrentURL adds a torrent via a URL and returns the torrent hash.
func (*Client) DaemonLogin ¶ added in v0.5.4
DaemonLogin performs login to the Deluge daemon.
func (*Client) DaemonVersion ¶
DaemonVersion returns the running daemon version.
func (*Client) DisablePlugin ¶ added in v0.5.6
DisablePlugin disables the plugin with the given name.
func (*Client) EnablePlugin ¶ added in v0.5.6
EnablePlugin enables the plugin with the given name.
func (*Client) ForceReannounce ¶ added in v0.5.4
ForceReannounce will reannounce torrent status to associated tracker(s).
func (*Client) GetAvailablePlugins ¶ added in v0.5.4
GetAvailablePlugins returns a list of available plugins.
func (*Client) GetEnabledPlugins ¶ added in v0.5.4
GetEnabledPlugins returns a list of enabled plugins.
func (*Client) GetFreeSpace ¶ added in v0.1.1
GetFreeSpace returns the available free space; path is optional.
func (*Client) GetLibtorrentVersion ¶ added in v0.5.4
GetLibtorrentVersion returns the libtorrent version.
func (*Client) GetListenPort ¶ added in v0.5.5
GetListenPort returns the listen port of the deluge daemon.
func (*Client) GetSessionStatus ¶ added in v0.5.5
func (c *Client) GetSessionStatus() (*SessionStatus, error)
GetSessionStatus retrieves session status and statistics.
func (*Client) LabelPlugin ¶ added in v0.5.4
func (c *Client) LabelPlugin() (*LabelPlugin, error)
LabelPlugin returns the label plugin if enabled or nil. An error is returned if enabled plugins could not be retrieved.
func (*Client) MethodsList ¶
MethodsList returns a list of available methods on server.
func (*Client) MoveStorage ¶ added in v0.2.1
MoveStorage will move the storage location of the group of torrents with the given IDs.
func (*Client) PauseTorrents ¶ added in v0.5.4
PauseTorrents pauses a group of torrents with the given IDs.
func (*Client) RemoveTorrent ¶ added in v0.5.4
RemoveTorrent removes a single torrent, returning true if successful. If `rmFiles` is set it also tries to delete all downloaded data for the specified torrent.
func (*Client) RemoveTorrents ¶ added in v0.5.4
func (c *Client) RemoveTorrents(ids []string, rmFiles bool) ([]TorrentError, error)
RemoveTorrents tries to remove multiple torrents at once. If `rmFiles` is set it also tries to delete all downloaded data for the specified torrents. If errors were encountered the returned list will be a list of TorrentErrors. On success an empty list of errors is returned.
The user should not rely on files being removed or torrents being removed from the session, just because no errors have been returned, as returned errors will primarily indicate that some of the supplied torrent hashes were invalid.
func (*Client) ResumeTorrents ¶ added in v0.5.4
ResumeTorrents resumes a group of torrents with the given IDs.
func (*Client) SessionState ¶ added in v0.2.1
SessionState returns the current session state.
func (*Client) SetTorrentOptions ¶ added in v0.5.4
SetTorrentOptions updates options for the torrent with the given hash.
func (*Client) SetTorrentTracker ¶ added in v0.5.4
SetTorrentTracker sets the primary tracker for the torrent with the given hash to be `trackerURL`.
func (*Client) TestListenPort ¶ added in v0.5.4
TestListenPort checks if the active port is open.
func (*Client) TorrentStatus ¶ added in v0.5.4
func (c *Client) TorrentStatus(hash string) (*TorrentStatus, error)
TorrentStatus returns the status of the torrent with specified hash.
func (*Client) TorrentsStatus ¶ added in v0.1.1
func (c *Client) TorrentsStatus(state TorrentState, hashes []string) (map[string]*TorrentStatus, error)
TorrentsStatus returns the status of torrents matching the specified state and list of hashes. Both state and list of hashes are optional.
type ClientV2 ¶ added in v0.5.4
type ClientV2 struct {
Client
}
func (*ClientV2) CreateAccount ¶ added in v0.5.4
CreateAccount creates a new Deluge user with the supplied username, password and permission level. The authenticated user must have an authLevel of ADMIN to succeed.
func (*ClientV2) KnownAccounts ¶ added in v0.5.4
KnownAccounts returns all known accounts, including password and permission levels.
func (*ClientV2) RemoveAccount ¶ added in v0.5.4
RemoveAccount will delete an existing username. The authenticated user must have an authLevel of ADMIN to succeed.
type DelugeClient ¶ added in v0.1.1
type DelugeClient interface { Connect() error Close() error DaemonLogin() error MethodsList() ([]string, error) DaemonVersion() (string, error) GetFreeSpace(string) (int64, error) GetLibtorrentVersion() (string, error) AddTorrentMagnet(magnetURI string, options *Options) (string, error) AddTorrentURL(url string, options *Options) (string, error) AddTorrentFile(fileName, fileContentBase64 string, options *Options) (string, error) RemoveTorrents(ids []string, rmFiles bool) ([]TorrentError, error) RemoveTorrent(id string, rmFiles bool) (bool, error) PauseTorrents(ids ...string) error ResumeTorrents(ids ...string) error TorrentsStatus(state TorrentState, ids []string) (map[string]*TorrentStatus, error) TorrentStatus(id string) (*TorrentStatus, error) MoveStorage(torrentIDs []string, dest string) error SetTorrentTracker(id, tracker string) error SetTorrentOptions(id string, options *Options) error SessionState() ([]string, error) ForceReannounce(ids []string) error GetAvailablePlugins() ([]string, error) GetEnabledPlugins() ([]string, error) EnablePlugin(name string) error DisablePlugin(name string) error TestListenPort() (bool, error) GetListenPort() (uint16, error) GetSessionStatus() (*SessionStatus, error) }
DelugeClient is an interface for v1.3 and v2 Deluge servers.
type DelugeResponse ¶
type DelugeResponse struct { // only in rpcError RPCError // contains filtered or unexported fields }
DelugeResponse is a response returned from a completed RPC call.
func (*DelugeResponse) IsError ¶
func (dr *DelugeResponse) IsError() bool
IsError returns true when the response is an error.
func (*DelugeResponse) String ¶
func (dr *DelugeResponse) String() string
type LabelPlugin ¶ added in v0.5.4
type LabelPlugin struct {
*Client
}
LabelPlugin exposes label plugin methods.
func (LabelPlugin) AddLabel ¶ added in v0.5.4
func (p LabelPlugin) AddLabel(label string) error
AddLabel adds a new label definition.
func (LabelPlugin) GetLabels ¶ added in v0.5.6
func (p LabelPlugin) GetLabels() ([]string, error)
GetLabels returns a list of the available labels that can be assigned to torrents.
func (LabelPlugin) GetTorrentLabel ¶ added in v0.5.4
func (p LabelPlugin) GetTorrentLabel(hash string) (string, error)
GetTorrentLabel returns the label of the specified torrent.
func (LabelPlugin) GetTorrentsLabels ¶ added in v0.5.4
func (p LabelPlugin) GetTorrentsLabels(state TorrentState, ids []string) (map[string]string, error)
GetTorrentsLabels filters torrents by state and/or IDs and returns their label.
func (LabelPlugin) RemoveLabel ¶ added in v0.5.4
func (p LabelPlugin) RemoveLabel(label string) error
RemoveLabel removes a label definition.
func (LabelPlugin) SetTorrentLabel ¶ added in v0.5.4
func (p LabelPlugin) SetTorrentLabel(hash, label string) error
SetTorrentLabel adds or replaces the label for the specified torrent.
type Options ¶ added in v0.2.1
type Options struct { MaxConnections *int MaxUploadSlots *int MaxUploadSpeed *int MaxDownloadSpeed *int PrioritizeFirstLastPieces *bool PreAllocateStorage *bool // v2-only but automatically converted to compact_allocation for v1 DownloadLocation *string // works for both v1 and v2 when sending options AutoManaged *bool StopAtRatio *bool StopRatio *float32 RemoveAtRatio *float32 MoveCompleted *bool MoveCompletedPath *string AddPaused *bool // V2 defines v2-only options V2 V2Options }
Options used when adding a torrent magnet/URL. Valid options for v2: https://github.com/deluge-torrent/deluge/blob/deluge-2.0.3/deluge/core/torrent.py#L167-L183 Valid options for v1: https://github.com/deluge-torrent/deluge/blob/1.3-stable/deluge/core/torrent.py#L83-L96
type Peer ¶ added in v0.1.1
type Peer struct { Client string IP string Progress float32 Seed int64 DownSpeed int64 UpSpeed int64 Country string }
Peer is a Deluge torrent peer.
type SerialMismatchError ¶ added in v0.1.1
SerialMismatchError is the error returned when server replied with an out-of-order response.
func (SerialMismatchError) Error ¶ added in v0.1.1
func (e SerialMismatchError) Error() string
type SessionStatus ¶ added in v0.5.5
type SessionStatus struct { HasIncomingConnections bool UploadRate float32 DownloadRate float32 PayloadUploadRate float32 PayloadDownloadRate float32 TotalDownload int64 TotalUpload int64 NumPeers int16 DhtNodes int16 }
SessionStatus contains basic session status and statistics.
type Settings ¶
type Settings struct { Hostname string Port uint Login string Password string Logger *log.Logger // ReadWriteTimeout is the timeout for read/write operations on the TCP stream. ReadWriteTimeout time.Duration // DebugServerResponses is used populate the DebugServerResponses slice on the client with // byte buffers containing the raw bytes as received from the Deluge server. DebugServerResponses bool }
Settings defines all settings for a Deluge client connection.
type TorrentError ¶ added in v0.5.4
type TorrentError struct { // ID is the hash of the torrent that experienced an error ID string Message string }
TorrentError is a tuple of a torrent id and an error message, returned by methods that manipulate many torrents at once.
func (TorrentError) Error ¶ added in v0.5.4
func (t TorrentError) Error() string
type TorrentState ¶ added in v0.5.4
type TorrentState string
const ( StateUnspecified TorrentState = "" StateActive TorrentState = "Active" StateAllocating TorrentState = "Allocating" StateChecking TorrentState = "Checking" StateDownloading TorrentState = "Downloading" StateSeeding TorrentState = "Seeding" StatePaused TorrentState = "Paused" StateError TorrentState = "Error" StateQueued TorrentState = "Queued" StateMoving TorrentState = "Moving" )
See all defined torrent states here: https://github.com/deluge-torrent/deluge/blob/deluge-2.0.3/deluge/common.py#L70-L78 Plus the special 'Active' state.
type TorrentStatus ¶ added in v0.1.1
type TorrentStatus struct { ActiveTime int64 CompletedTime int64 `rencode:"v2only"` TimeAdded float32 // most times an integer LastSeenComplete float32 `rencode:"v2only"` DistributedCopies float32 ETA float32 // most times an integer Progress float32 // max is 100 Ratio float32 IsFinished bool IsSeed bool Private bool SavePath string DownloadLocation string `rencode:"v2only"` DownloadPayloadRate int64 Name string NextAnnounce int64 NumPeers int64 NumPieces int64 NumSeeds int64 PieceLength int64 SeedingTime int64 State string TotalDone int64 TotalPeers int64 TotalSeeds int64 TotalSize int64 TrackerHost string TrackerStatus string UploadPayloadRate int64 Files []File Peers []Peer FilePriorities []int64 FileProgress []float32 }
TorrentStatus contains commonly used torrent attributes, as reported by the deluge server. The full list of potentially available attributes can be found here: https://github.com/deluge-torrent/deluge/blob/deluge-2.0.3/deluge/core/torrent.py#L1033-L1143 If a new field is added to this struct it should also be added to the statusKeys map.