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 ¶
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 ¶
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 ¶
AddTorrentURL adds a torrent via a URL and returns the torrent hash.
func (*Client) DaemonLogin ¶
DaemonLogin performs login to the Deluge daemon.
func (*Client) DaemonVersion ¶
DaemonVersion returns the running daemon version.
func (*Client) DisablePlugin ¶
DisablePlugin disables the plugin with the given name.
func (*Client) EnablePlugin ¶
EnablePlugin enables the plugin with the given name.
func (*Client) ForceReannounce ¶
ForceReannounce will reannounce torrent status to associated tracker(s).
func (*Client) GetAvailablePlugins ¶
GetAvailablePlugins returns a list of available plugins.
func (*Client) GetEnabledPlugins ¶
GetEnabledPlugins returns a list of enabled plugins.
func (*Client) GetFreeSpace ¶
GetFreeSpace returns the available free space; path is optional.
func (*Client) GetLibtorrentVersion ¶
GetLibtorrentVersion returns the libtorrent version.
func (*Client) GetListenPort ¶
GetListenPort returns the listen port of the deluge daemon.
func (*Client) GetSessionStatus ¶
func (c *Client) GetSessionStatus() (*SessionStatus, error)
GetSessionStatus retrieves session status and statistics.
func (*Client) LabelPlugin ¶
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 ¶
MoveStorage will move the storage location of the group of torrents with the given IDs.
func (*Client) PauseTorrents ¶
PauseTorrents pauses a group of torrents with the given IDs.
func (*Client) RemoveTorrent ¶
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 ¶
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 ¶
ResumeTorrents resumes a group of torrents with the given IDs.
func (*Client) SessionState ¶
SessionState returns the current session state.
func (*Client) SetTorrentOptions ¶
SetTorrentOptions updates options for the torrent with the given hash.
func (*Client) SetTorrentTracker ¶
SetTorrentTracker sets the primary tracker for the torrent with the given hash to be `trackerURL`.
func (*Client) TestListenPort ¶
TestListenPort checks if the active port is open.
func (*Client) TorrentStatus ¶
func (c *Client) TorrentStatus(hash string) (*TorrentStatus, error)
TorrentStatus returns the status of the torrent with specified hash.
func (*Client) TorrentsStatus ¶
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 ¶
type ClientV2 struct {
Client
}
func (*ClientV2) CreateAccount ¶
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 ¶
KnownAccounts returns all known accounts, including password and permission levels.
func (*ClientV2) RemoveAccount ¶
RemoveAccount will delete an existing username. The authenticated user must have an authLevel of ADMIN to succeed.
type DelugeClient ¶
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 ¶
type LabelPlugin struct {
*Client
}
LabelPlugin exposes label plugin methods.
func (LabelPlugin) AddLabel ¶
func (p LabelPlugin) AddLabel(label string) error
AddLabel adds a new label definition.
func (LabelPlugin) GetLabels ¶
func (p LabelPlugin) GetLabels() ([]string, error)
GetLabels returns a list of the available labels that can be assigned to torrents.
func (LabelPlugin) GetTorrentLabel ¶
func (p LabelPlugin) GetTorrentLabel(hash string) (string, error)
GetTorrentLabel returns the label of the specified torrent.
func (LabelPlugin) GetTorrentsLabels ¶
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 ¶
func (p LabelPlugin) RemoveLabel(label string) error
RemoveLabel removes a label definition.
func (LabelPlugin) SetTorrentLabel ¶
func (p LabelPlugin) SetTorrentLabel(hash, label string) error
SetTorrentLabel adds or replaces the label for the specified torrent.
type Options ¶
type Options struct { MaxConnections *int MaxUploadSlots *int MaxUploadSpeed *int MaxDownloadSpeed *int PrioritizeFirstLastPieces *bool PreAllocateStorage *bool // compact_allocation for v1 DownloadLocation *string 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 ¶
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 ¶
SerialMismatchError is the error returned when server replied with an out-of-order response.
func (SerialMismatchError) Error ¶
func (e SerialMismatchError) Error() string
type SessionStatus ¶
type SessionStatus struct { HasIncomingConnections bool UploadRate float32 DownloadRate float32 PayloadUploadRate float32 PayloadDownloadRate float32 TotalDownload int32 TotalUpload int32 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 ¶
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 ¶
func (t TorrentError) Error() string
type TorrentState ¶
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 ¶
type TorrentStatus struct { ActiveTime int64 CompletedTime int64 `rencode:"v2only"` TimeAdded float32 // most times an integer DistributedCopies float32 ETA float32 // most times an integer Progress float32 // max is 100 Ratio float32 IsFinished bool IsSeed bool Private bool 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 TotalUploaded int64 TotalPayloadDownload int64 TotalPayloadUpload 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.