deluge

package module
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MIT Imports: 11 Imported by: 3

README

Deluge

Simple library to do specific things with Deluge Web UI API.

Pretty much only gets a list of active transfers. Has a lot of boiler plate for other features. I had no use for more than an active transfer list, and all the meta data for each transfer.

Pull requests and feedback welcomed!

package main

import (
	"log"
	"time"
	"golift.io/deluge"
)

func main() {
	config := deluge.Config{
		URL:      "http://127.0.0.1:8112",
		Password: "superSe(re7",
	}
	server, err := deluge.New(context.TODO(), &config)
	if err != nil {
		log.Fatal(err)
	}
	// This is the only method available for retrieving data.
	transfers, err := server.GetXfers()
	if err != nil {
		log.Fatal(err)
	}
	for _, xfer := range transfers {
		log.Println(xfer.Name)
	}
}

Documentation

Index

Constants

View Source
const (
	AuthLogin      = "auth.login"
	AddMagnet      = "core.add_torrent_magnet"
	AddTorrentURL  = "core.add_torrent_url"
	AddTorrentFile = "core.add_torrent_file"
	GetTorrentStat = "core.get_torrent_status"
	GetAllTorrents = "core.get_torrents_status"
	HostStatus     = "web.get_host_status"
	GeHosts        = "web.get_hosts"
)

Deluge WebUI methods.

Variables

View Source
var (
	ErrInvalidVersion = fmt.Errorf("invalid data returned while checking version")
	ErrDelugeError    = fmt.Errorf("deluge error")
	ErrAuthFailed     = fmt.Errorf("authentication failed")
)

Custom errors.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	ID   string
	Addr string
	Prot string
}

Backend holds a WebUI's backend server data.

type Bool added in v0.9.2

type Bool bool

Bool provides a container and unmarshalling for fields that may be boolean or numbers or strings in the WebUI API.

func (*Bool) UnmarshalJSON added in v0.9.2

func (bit *Bool) UnmarshalJSON(b []byte) error

UnmarshalJSON parses fields that may be numbers or booleans. https://stackoverflow.com/questions/30856454/how-to-unmarshall-both-0-and-false-as-bool-from-json/56832346#56832346

type Config

type Config struct {
	URL      string       `json:"url" toml:"url" xml:"url" yaml:"url"`
	Password string       `json:"password" toml:"password" xml:"password" yaml:"password"`
	HTTPPass string       `json:"http_pass" toml:"http_pass" xml:"http_pass" yaml:"http_pass"`
	HTTPUser string       `json:"http_user" toml:"http_user" xml:"http_user" yaml:"http_user"`
	Version  string       `json:"version" toml:"version" xml:"version" yaml:"version"`
	Client   *http.Client `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Config is the data needed to poll Deluge.

type Deluge

type Deluge struct {
	Version  string             // Currently unused, for display purposes only.
	Backends map[string]Backend // Currently unused, for display purposes only.
	// contains filtered or unexported fields
}

Deluge is what you get for providing a password. Version and Backends are only filled if you call New().

func New

func New(ctx context.Context, config *Config) (*Deluge, error)

New creates a http.Client with authenticated cookies. Used to make additional, authenticated requests to the APIs.

func NewNoAuth added in v0.9.3

func NewNoAuth(config *Config) (*Deluge, error)

NewNoAuth returns a Deluge object without authenticating or trying to connect.

func (Deluge) DelReq

func (d Deluge) DelReq(ctx context.Context, method string, params interface{}) (*http.Request, error)

DelReq is a small helper function that adds headers and marshals the json.

func (*Deluge) Get

func (d *Deluge) Get(ctx context.Context, method string, params interface{}) (*Response, error)

Get a response from Deluge.

func (*Deluge) GetXfers

func (d *Deluge) GetXfers() (map[string]*XferStatus, error)

GetXfers gets all the Transfers from Deluge.

func (*Deluge) GetXfersCompat

func (d *Deluge) GetXfersCompat() (map[string]*XferStatusCompat, error)

GetXfersCompat gets all the Transfers from Deluge 1.x or 2.x. Depend on what you're actually trying to do, this is likely the best method to use. This will return a combined struct hat has data for Deluge 1 and Deluge 2. All of the data for either version will be made available with this method.

func (*Deluge) GetXfersCompatContext added in v0.10.0

func (d *Deluge) GetXfersCompatContext(ctx context.Context) (map[string]*XferStatusCompat, error)

func (*Deluge) GetXfersContext added in v0.10.0

func (d *Deluge) GetXfersContext(ctx context.Context) (map[string]*XferStatus, error)

func (*Deluge) Login

func (d *Deluge) Login() error

Login sets the cookie jar with authentication information.

func (*Deluge) LoginContext added in v0.10.0

func (d *Deluge) LoginContext(ctx context.Context) error

LoginContext sets the cookie jar with authentication information.

type Response

type Response struct {
	ID     int64           `json:"id"`
	Result json.RawMessage `json:"result"`
	Error  struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

Response from Deluge.

type XferStatus

type XferStatus struct {
	Comment             string  `json:"comment"`
	ActiveTime          int64   `json:"active_time"`
	IsSeed              bool    `json:"is_seed"`
	Hash                string  `json:"hash"`
	UploadPayloadRate   int64   `json:"upload_payload_rate"`
	MoveCompletedPath   string  `json:"move_completed_path"`
	Private             bool    `json:"private"`
	TotalPayloadUpload  int64   `json:"total_payload_upload"`
	Paused              bool    `json:"paused"`
	SeedRank            int64   `json:"seed_rank"`
	SeedingTime         int64   `json:"seeding_time"`
	MaxUploadSlots      int64   `json:"max_upload_slots"`
	PrioritizeFirstLast bool    `json:"prioritize_first_last"`
	DistributedCopies   float64 `json:"distributed_copies"`
	DownloadPayloadRate int64   `json:"download_payload_rate"`
	Message             string  `json:"message"`
	NumPeers            int64   `json:"num_peers"`
	MaxDownloadSpeed    int64   `json:"max_download_speed"`
	MaxConnections      int64   `json:"max_connections"`
	Compact             bool    `json:"compact"`
	Ratio               float64 `json:"ratio"`
	TotalPeers          int64   `json:"total_peers"`
	TotalSize           int64   `json:"total_size"`
	TotalWanted         int64   `json:"total_wanted"`
	State               string  `json:"state"`
	FilePriorities      []int   `json:"file_priorities"`
	Label               string  `json:"label"`
	MaxUploadSpeed      int64   `json:"max_upload_speed"`
	RemoveAtRatio       bool    `json:"remove_at_ratio"`
	Tracker             string  `json:"tracker"`
	SavePath            string  `json:"save_path"`
	Progress            float64 `json:"progress"`
	TimeAdded           float64 `json:"time_added"`
	TrackerHost         string  `json:"tracker_host"`
	TotalUploaded       int64   `json:"total_uploaded"`
	Files               []struct {
		Index  int64  `json:"index"`
		Path   string `json:"path"`
		Offset int64  `json:"offset"`
		Size   int64  `json:"size"`
	} `json:"files"`
	TotalDone           int64         `json:"total_done"`
	NumPieces           int64         `json:"num_pieces"`
	TrackerStatus       string        `json:"tracker_status"`
	TotalSeeds          int64         `json:"total_seeds"`
	MoveOnCompleted     Bool          `json:"move_on_completed"`
	NextAnnounce        int64         `json:"next_announce"`
	StopAtRatio         bool          `json:"stop_at_ratio"`
	FileProgress        []float64     `json:"file_progress"`
	MoveCompleted       Bool          `json:"move_completed"`
	PieceLength         int64         `json:"piece_length"`
	AllTimeDownload     int64         `json:"all_time_download"`
	MoveOnCompletedPath string        `json:"move_on_completed_path"`
	NumSeeds            int64         `json:"num_seeds"`
	Peers               []interface{} `json:"peers"`
	Name                string        `json:"name"`
	Trackers            []struct {
		MinAnnounce  interface{} `json:"min_announce"`
		NextAnnounce interface{} `json:"next_announce"`
		SendStats    bool        `json:"send_stats"`
		Verified     bool        `json:"verified"`
		CompleteSent bool        `json:"complete_sent"`
		StartSent    bool        `json:"start_sent"`
		Updating     bool        `json:"updating"`
		Fails        int64       `json:"fails"`
		FailLimit    int64       `json:"fail_limit"`
		Source       int64       `json:"source"`
		Tier         int64       `json:"tier"`
		URL          string      `json:"url"`
	} `json:"trackers"`
	TotalPayloadDownload int64       `json:"total_payload_download"`
	IsAutoManaged        bool        `json:"is_auto_managed"`
	SeedsPeersRatio      float64     `json:"seeds_peers_ratio"`
	Queue                int64       `json:"queue"`
	NumFiles             int64       `json:"num_files"`
	Eta                  json.Number `json:"eta"`
	StopRatio            float64     `json:"stop_ratio"`
	IsFinished           bool        `json:"is_finished"`
}

XferStatus is the Deluge 1.0 WebUI API layout for Active Transfers.

type XferStatus2

type XferStatus2 struct {
	ActiveTime                float64 `json:"active_time"`
	SeedingTime               float64 `json:"seeding_time"`
	FinishedTime              float64 `json:"finished_time"`
	AllTimeDownload           float64 `json:"all_time_download"`
	StorageMode               string  `json:"storage_mode"`
	DistributedCopies         float64 `json:"distributed_copies"`
	DownloadPayloadRate       float64 `json:"download_payload_rate"`
	FilePriorities            []int   `json:"file_priorities"`
	Hash                      string  `json:"hash"`
	AutoManaged               bool    `json:"auto_managed"`
	IsAutoManaged             bool    `json:"is_auto_managed"`
	IsFinished                bool    `json:"is_finished"`
	MaxConnections            float64 `json:"max_connections"`
	MaxDownloadSpeed          float64 `json:"max_download_speed"`
	MaxUploadSlots            float64 `json:"max_upload_slots"`
	MaxUploadSpeed            float64 `json:"max_upload_speed"`
	Message                   string  `json:"message"`
	MoveOnCompletedPath       string  `json:"move_on_completed_path"`
	MoveOnCompleted           Bool    `json:"move_on_completed"`
	MoveCompletedPath         string  `json:"move_completed_path"`
	MoveCompleted             Bool    `json:"move_completed"`
	NextAnnounce              float64 `json:"next_announce"`
	NumPeers                  int64   `json:"num_peers"`
	NumSeeds                  int64   `json:"num_seeds"`
	Owner                     string  `json:"owner"`
	Paused                    bool    `json:"paused"`
	PrioritizeFirstLast       bool    `json:"prioritize_first_last"`
	PrioritizeFirstLastPieces bool    `json:"prioritize_first_last_pieces"`
	SequentialDownload        bool    `json:"sequential_download"`
	Progress                  float64 `json:"progress"`
	Shared                    bool    `json:"shared"`
	RemoveAtRatio             bool    `json:"remove_at_ratio"`
	SavePath                  string  `json:"save_path"`
	DownloadLocation          string  `json:"download_location"`
	SeedsPeersRatio           float64 `json:"seeds_peers_ratio"`
	SeedRank                  int     `json:"seed_rank"`
	State                     string  `json:"state"`
	StopAtRatio               Bool    `json:"stop_at_ratio"`
	StopRatio                 float64 `json:"stop_ratio"`
	TimeAdded                 float64 `json:"time_added"`
	TotalDone                 float64 `json:"total_done"`
	TotalPayloadDownload      float64 `json:"total_payload_download"`
	TotalPayloadUpload        float64 `json:"total_payload_upload"`
	TotalPeers                int64   `json:"total_peers"`
	TotalSeeds                float64 `json:"total_seeds"`
	TotalUploaded             float64 `json:"total_uploaded"`
	TotalWanted               float64 `json:"total_wanted"`
	TotalRemaining            float64 `json:"total_remaining"`
	Tracker                   string  `json:"tracker"`
	TrackerHost               string  `json:"tracker_host"`
	Trackers                  []struct {
		NextAnnounce     interface{}   `json:"next_announce"`
		MinAnnounce      interface{}   `json:"min_announce"`
		Endpoints        []interface{} `json:"endpoints"`
		Updating         bool          `json:"updating"`
		StartSent        bool          `json:"start_sent"`
		CompleteSent     bool          `json:"complete_sent"`
		SendStats        bool          `json:"send_stats"`
		Verified         bool          `json:"verified"`
		Tier             int           `json:"tier"`
		FailLimit        int           `json:"fail_limit"`
		Source           int           `json:"source"`
		ScrapeIncomplete float64       `json:"scrape_incomplete"`
		ScrapeComplete   float64       `json:"scrape_complete"`
		ScrapeDownloaded float64       `json:"scrape_downloaded"`
		Fails            int64         `json:"fails"`
		URL              string        `json:"url"`
		Trackerid        string        `json:"trackerid"`
		Message          string        `json:"message"`
		LastError        struct {
			Value    int    `json:"value"`
			Category string `json:"category"`
		} `json:"last_error"`
	} `json:"trackers"`
	TrackerStatus     string      `json:"tracker_status"`
	UploadPayloadRate float64     `json:"upload_payload_rate"`
	Comment           string      `json:"comment"`
	Creator           string      `json:"creator"`
	NumFiles          float64     `json:"num_files"`
	NumPieces         float64     `json:"num_pieces"`
	PieceLength       float64     `json:"piece_length"`
	Private           bool        `json:"private"`
	TotalSize         float64     `json:"total_size"`
	Eta               json.Number `json:"eta"`
	FileProgress      []float64   `json:"file_progress"`
	Files             []struct {
		Index  int64  `json:"index"`
		Path   string `json:"path"`
		Size   int64  `json:"size"`
		Offset int64  `json:"offset"`
	} `json:"files"`
	OrigFiles []struct {
		Index  int64  `json:"index"`
		Path   string `json:"path"`
		Size   int64  `json:"size"`
		Offset int64  `json:"offset"`
	} `json:"orig_files"`
	IsSeed            bool          `json:"is_seed"`
	Peers             []interface{} `json:"peers"`
	Queue             int           `json:"queue"`
	Ratio             float64       `json:"ratio"`
	CompletedTime     float64       `json:"completed_time"`
	LastSeenComplete  float64       `json:"last_seen_complete"`
	Name              string        `json:"name"`
	Pieces            interface{}   `json:"pieces"`
	SeedMode          bool          `json:"seed_mode"`
	SuperSeeding      bool          `json:"super_seeding"`
	TimeSinceDownload float64       `json:"time_since_download"`
	TimeSinceUpload   float64       `json:"time_since_upload"`
	TimeSinceTransfer float64       `json:"time_since_transfer"`
}

XferStatus2 is the Deluge 2.0 WebUI API layout for Active Transfers.

type XferStatusCompat

type XferStatusCompat struct {
	ActiveTime                float64     `json:"active_time"`
	SeedingTime               float64     `json:"seeding_time"`
	FinishedTime              float64     `json:"finished_time"`
	AllTimeDownload           float64     `json:"all_time_download"`
	StorageMode               string      `json:"storage_mode"`
	DistributedCopies         float64     `json:"distributed_copies"`
	DownloadPayloadRate       float64     `json:"download_payload_rate"`
	FilePriorities            []int       `json:"file_priorities"`
	Hash                      string      `json:"hash"`
	AutoManaged               bool        `json:"auto_managed"`
	IsAutoManaged             bool        `json:"is_auto_managed"`
	IsFinished                bool        `json:"is_finished"`
	MaxConnections            float64     `json:"max_connections"`
	MaxDownloadSpeed          float64     `json:"max_download_speed"`
	MaxUploadSlots            float64     `json:"max_upload_slots"`
	MaxUploadSpeed            float64     `json:"max_upload_speed"`
	Message                   string      `json:"message"`
	MoveOnCompletedPath       string      `json:"move_on_completed_path"`
	MoveOnCompleted           Bool        `json:"move_on_completed"`
	MoveCompletedPath         string      `json:"move_completed_path"`
	MoveCompleted             Bool        `json:"move_completed"`
	NextAnnounce              float64     `json:"next_announce"`
	NumPeers                  int64       `json:"num_peers"`
	NumSeeds                  int64       `json:"num_seeds"`
	Owner                     string      `json:"owner"`
	Paused                    bool        `json:"paused"`
	PrioritizeFirstLast       bool        `json:"prioritize_first_last"`
	PrioritizeFirstLastPieces bool        `json:"prioritize_first_last_pieces"`
	SequentialDownload        bool        `json:"sequential_download"`
	Progress                  float64     `json:"progress"`
	Shared                    bool        `json:"shared"`
	RemoveAtRatio             bool        `json:"remove_at_ratio"`
	SavePath                  string      `json:"save_path"`
	DownloadLocation          string      `json:"download_location"`
	SeedsPeersRatio           float64     `json:"seeds_peers_ratio"`
	SeedRank                  int         `json:"seed_rank"`
	State                     string      `json:"state"`
	StopAtRatio               Bool        `json:"stop_at_ratio"`
	StopRatio                 float64     `json:"stop_ratio"`
	TimeAdded                 float64     `json:"time_added"`
	TotalDone                 float64     `json:"total_done"`
	TotalPayloadDownload      float64     `json:"total_payload_download"`
	TotalPayloadUpload        float64     `json:"total_payload_upload"`
	TotalPeers                int64       `json:"total_peers"`
	TotalSeeds                float64     `json:"total_seeds"`
	TotalUploaded             float64     `json:"total_uploaded"`
	TotalWanted               float64     `json:"total_wanted"`
	TotalRemaining            float64     `json:"total_remaining"`
	Tracker                   string      `json:"tracker"`
	TrackerHost               string      `json:"tracker_host"`
	TrackerStatus             string      `json:"tracker_status"`
	UploadPayloadRate         float64     `json:"upload_payload_rate"`
	Comment                   string      `json:"comment"`
	Creator                   string      `json:"creator"`
	NumFiles                  float64     `json:"num_files"`
	NumPieces                 float64     `json:"num_pieces"`
	PieceLength               float64     `json:"piece_length"`
	Private                   bool        `json:"private"`
	TotalSize                 float64     `json:"total_size"`
	Eta                       json.Number `json:"eta"`
	FileProgress              []float64   `json:"file_progress"`
	Files                     []struct {
		Index  int64  `json:"index"`
		Path   string `json:"path"`
		Size   int64  `json:"size"`
		Offset int64  `json:"offset"`
	} `json:"files"`
	OrigFiles []struct {
		Index  int64  `json:"index"`
		Path   string `json:"path"`
		Size   int64  `json:"size"`
		Offset int64  `json:"offset"`
	} `json:"orig_files"`
	IsSeed            bool          `json:"is_seed"`
	Peers             []interface{} `json:"peers"`
	Queue             int64         `json:"queue"`
	Ratio             float64       `json:"ratio"`
	CompletedTime     float64       `json:"completed_time"`
	LastSeenComplete  float64       `json:"last_seen_complete"`
	Name              string        `json:"name"`
	Pieces            interface{}   `json:"pieces"`
	SeedMode          bool          `json:"seed_mode"`
	SuperSeeding      bool          `json:"super_seeding"`
	TimeSinceDownload float64       `json:"time_since_download"`
	TimeSinceUpload   float64       `json:"time_since_upload"`
	TimeSinceTransfer float64       `json:"time_since_transfer"`
	Label             string        `json:"label"`
	Trackers          []struct {
		NextAnnounce     interface{}   `json:"next_announce"`
		MinAnnounce      interface{}   `json:"min_announce"`
		Endpoints        []interface{} `json:"endpoints"`
		Updating         bool          `json:"updating"`
		CompleteSent     bool          `json:"complete_sent"`
		SendStats        bool          `json:"send_stats"`
		StartSent        bool          `json:"start_sent"`
		Verified         bool          `json:"verified"`
		FailLimit        int64         `json:"fail_limit"`
		Fails            int64         `json:"fails"`
		Source           float64       `json:"source"`
		Tier             float64       `json:"tier"`
		ScrapeIncomplete float64       `json:"scrape_incomplete"`
		ScrapeComplete   float64       `json:"scrape_complete"`
		ScrapeDownloaded float64       `json:"scrape_downloaded"`
		URL              string        `json:"url"`
		Trackerid        string        `json:"trackerid"`
		Message          string        `json:"message"`
		LastError        struct {
			Value    int    `json:"value"`
			Category string `json:"category"`
		} `json:"last_error"`
	} `json:"trackers"`
}

XferStatusCompat is a compatible struct for Deluge 1 and 2 API data.

Jump to

Keyboard shortcuts

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