rtorrent

package module
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 7 Imported by: 1

README

go-rtorrent

GoDoc Coverage Status MIT license

rTorrent XMLRPC Bindings for Go (golang)

Fork of github.com/mrobinsn/go-rtorrent.

Documentation

GoDoc

Features

  • Get IP, Name, Up/Down totals
  • Get torrents within a view
  • Get torrent by hash
  • Get files for torrents
  • Set the label on a torrent
  • Add a torrent by URL or by metadata
  • Delete a torrent (including files)

Installation

To install the package, run go get github.com/autobrr/go-rtorrent

To use it in application, import "github.com/autobrr/go-rtorrent"

Library Usage

client := rtorrent.NewClient(rtorrent.Config{Addr: "http://my-rtorrent.com/RPC2"})
name, _ := client.Name(context.Background())
fmt.Printf("My rTorrent's name: %v", name)

You can connect to a server using Basic Authentication by adding User and Pass to the config:

client := rtorrent.NewClient(rtorrent.Config{Addr: "http://my-rtorrent.com/RPC2", BasicUser: "user", BasicPass: "pass"})

Contributing

Pull requests are welcome, please ensure you add relevant tests for any new/changed functionality.

Documentation

Index

Constants

View Source
const (
	// ViewMain represents the "main" view, containing all torrents
	ViewMain View = "main"
	// ViewStarted represents the "started" view, containing only torrents that have been started
	ViewStarted View = "started"
	// ViewStopped represents the "stopped" view, containing only torrents that have been stopped
	ViewStopped View = "stopped"
	// ViewHashing represents the "hashing" view, containing only torrents that are currently hashing
	ViewHashing View = "hashing"
	// ViewSeeding represents the "seeding" view, containing only torrents that are currently seeding
	ViewSeeding View = "seeding"

	// DName represents the name of a "Downloading Items"
	DName Field = "d.name"
	// DLabel represents the label of a "Downloading Item"
	DLabel Field = "d.custom1"
	// DSizeInBytes represents the size in bytes of a "Downloading Item"
	DSizeInBytes Field = "d.size_bytes"
	// DHash represents the hash of a "Downloading Item"
	DHash Field = "d.hash"
	// DBasePath represents the base path of a "Downloading Item"
	DBasePath Field = "d.base_path"
	// DDirectory represents the directory of a "Downloading Item"
	DDirectory Field = "d.directory"
	// DIsActive represents whether a "Downloading Item" is active or not
	DIsActive Field = "d.is_active"
	// DRatio represents the ratio of a "Downloading Item"
	DRatio Field = "d.ratio"
	// DComplete represents whether the "Downloading Item" is complete or not
	DComplete Field = "d.complete"
	// DCompletedBytes represents the total of completed bytes of the "Downloading Item"
	DCompletedBytes Field = "d.completed_bytes"
	// DDownRate represents the download rate of the "Downloading Item"
	DDownRate Field = "d.down.rate"
	// DUpRate represents the upload rate of the "Downloading Item"
	DUpRate Field = "d.up.rate"
	// DCreationTime represents the date the torrent was created
	DCreationTime Field = "d.creation_date"
	// DFinishedTime represents the date the torrent finished downloading
	DFinishedTime Field = "d.timestamp.finished"
	// DStartedTime represents the date the torrent started downloading
	DStartedTime Field = "d.timestamp.started"

	// FPath represents the path of a "File Item"
	FPath Field = "f.path"
	// FSizeInBytes represents the size in bytes of a "File Item"
	FSizeInBytes Field = "f.size_bytes"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is used to communicate with a remote rTorrent instance

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a new instance of `Client`

func (*Client) Add

func (r *Client) Add(ctx context.Context, url string, extraArgs ...*FieldValue) error

Add adds a new torrent by URL and starts the torrent

extraArgs can be any valid rTorrent rpc command. For instance:

Adds the Torrent by URL and sets the label on the torrent

Add("some-url", "d.custom1.set=\"my-label\"")

Or:

Add("some-url", DLabel.SetValue("my-label"))

Adds the Torrent by URL and sets the label as well as base path

Add("some-url", "d.custom1.set=\"my-label\"", "d.base_path=\"/some/valid/path\"")

Or:

Add("some-url", DLabel.SetValue("my-label"), DBasePath.SetValue("/some/valid/path"))

func (*Client) AddStopped

func (r *Client) AddStopped(ctx context.Context, url string, extraArgs ...*FieldValue) error

AddStopped adds a new torrent by URL in a stopped state

extraArgs can be any valid rTorrent rpc command. For instance:

Adds the Torrent by URL (stopped) and sets the label on the torrent

AddStopped("some-url", &FieldValue{"d.custom1", "my-label"})

Or:

AddStopped("some-url", DLabel.SetValue("my-label"))

Adds the Torrent by URL (stopped) and sets the label and base path

AddStopped("some-url", &FieldValue{"d.custom1", "my-label"}, &FiedValue{"d.base_path", "/some/valid/path"})

Or:

AddStopped("some-url", DLabel.SetValue("my-label"), DBasePath.SetValue("/some/valid/path"))

func (*Client) AddTorrent

func (r *Client) AddTorrent(ctx context.Context, data []byte, extraArgs ...*FieldValue) error

AddTorrent adds a new torrent by the torrent files data and starts the torrent

extraArgs can be any valid rTorrent rpc command. For instance:

Adds the Torrent file and sets the label on the torrent

Add(fileData, "d.custom1.set=\"my-label\"")

Or:

AddTorrent(fileData, DLabel.SetValue("my-label"))

Adds the Torrent file and sets the label and base path

Add(fileData, "d.custom1.set=\"my-label\"", "d.base_path=\"/some/valid/path\"")

Or:

AddTorrent(fileData, DLabel.SetValue("my-label"), DBasePath.SetValue("/some/valid/path"))

func (*Client) AddTorrentStopped

func (r *Client) AddTorrentStopped(ctx context.Context, data []byte, extraArgs ...*FieldValue) error

AddTorrentStopped adds a new torrent by the torrent files data but does not start the torrent

extraArgs can be any valid rTorrent rpc command. For instance:

Adds the Torrent file (stopped) and sets the label on the torrent

AddTorrentStopped(fileData, "d.custom1.set=\"my-label\"")

Or:

AddTorrentStopped(fileData, DLabel.SetValue("my-label"))

Adds the Torrent file and (stopped) sets the label and base path

AddTorrentStopped(fileData, "d.custom1.set=\"my-label\"", "d.base_path=\"/some/valid/path\"")

Or:

AddTorrentStopped(fileData, DLabel.SetValue("my-label"), DBasePath.SetValue("/some/valid/path"))

func (*Client) CloseTorrent

func (r *Client) CloseTorrent(ctx context.Context, t Torrent) error

CloseTorrent closes the torrent

func (*Client) Delete

func (r *Client) Delete(ctx context.Context, t Torrent) error

Delete removes the torrent

func (*Client) DownRate

func (r *Client) DownRate(ctx context.Context) (int, error)

DownRate returns the current download rate reported by this Client instance (bytes/s)

func (*Client) DownTotal

func (r *Client) DownTotal(ctx context.Context) (int, error)

DownTotal returns the total downloaded metric reported by this Client instance (bytes)

func (*Client) GetFiles

func (r *Client) GetFiles(ctx context.Context, t Torrent) ([]File, error)

GetFiles returns all the files for a given `Torrent`

func (*Client) GetStatus

func (r *Client) GetStatus(ctx context.Context, t Torrent) (Status, error)

GetStatus returns the Status for a given Torrent

func (*Client) GetTorrent

func (r *Client) GetTorrent(ctx context.Context, hash string) (Torrent, error)

GetTorrent returns the torrent identified by the given hash

func (*Client) GetTorrents

func (r *Client) GetTorrents(ctx context.Context, view View) ([]Torrent, error)

GetTorrents returns all the torrents reported by this Client instance

func (*Client) IP

func (r *Client) IP(ctx context.Context) (string, error)

IP returns the IP reported by this Client instance

func (*Client) IsActive

func (r *Client) IsActive(ctx context.Context, t Torrent) (bool, error)

IsActive checks if the torrent is active

func (*Client) IsOpen

func (r *Client) IsOpen(ctx context.Context, t Torrent) (bool, error)

IsOpen checks if the torrent is open

func (*Client) Name

func (r *Client) Name(ctx context.Context) (string, error)

Name returns the name reported by this Client instance

func (*Client) OpenTorrent

func (r *Client) OpenTorrent(ctx context.Context, t Torrent) error

OpenTorrent opens the torrent

func (*Client) PauseTorrent

func (r *Client) PauseTorrent(ctx context.Context, t Torrent) error

PauseTorrent pauses the torrent

func (*Client) ResumeTorrent

func (r *Client) ResumeTorrent(ctx context.Context, t Torrent) error

ResumeTorrent resumes the torrent

func (*Client) SetLabel

func (r *Client) SetLabel(ctx context.Context, t Torrent, newLabel string) error

SetLabel sets the label on the given Torrent

func (*Client) StartTorrent

func (r *Client) StartTorrent(ctx context.Context, t Torrent) error

StartTorrent starts the torrent

func (*Client) State

func (r *Client) State(ctx context.Context, t Torrent) (int, error)

State returns the state that the torrent is into It returns: 0 for stopped, 1 for started/paused

func (*Client) StopTorrent

func (r *Client) StopTorrent(ctx context.Context, t Torrent) error

StopTorrent stops the torrent

func (*Client) UpRate

func (r *Client) UpRate(ctx context.Context) (int, error)

UpRate returns the current upload rate reported by this Client instance (bytes/s)

func (*Client) UpTotal

func (r *Client) UpTotal(ctx context.Context) (int, error)

UpTotal returns the total uploaded metric reported by this Client instance (bytes)

type Config

type Config struct {
	Addr          string
	TLSSkipVerify bool

	BasicUser string
	BasicPass string

	Log *log.Logger
}

type Field

type Field string

Field represents an attribute on a Client entity that can be queried or set

func (Field) Cmd

func (f Field) Cmd() string

Cmd returns the representation of the field which allows it to be used a command with Client

func (Field) Query

func (f Field) Query() string

Query converts the field to a string which allows it to be queried Example:

DName.Query() // returns "d.name="

func (Field) SetValue

func (f Field) SetValue(value string) *FieldValue

SetValue returns a FieldValue struct which can be used to set the field on a particular item in rTorrent to the specified value

type FieldValue

type FieldValue struct {
	Field Field
	Value string
}

FieldValue contains the Field and Value of an attribute on a rTorrent

func (*FieldValue) String

func (f *FieldValue) String() string

type File

type File struct {
	Path string
	Size int
}

File represents a file in rTorrent

func (*File) Pretty

func (f *File) Pretty() string

Pretty returns a formatted string representing this File

type Status

type Status struct {
	Completed      bool
	CompletedBytes int
	DownRate       int
	UpRate         int
	Ratio          float64
	Size           int
}

Status represents the status of a torrent

type Torrent

type Torrent struct {
	Hash      string
	Name      string
	Path      string
	Size      int
	Label     string
	Completed bool
	Ratio     float64
	Created   time.Time
	Started   time.Time
	Finished  time.Time
}

Torrent represents a torrent in rTorrent

func (*Torrent) Pretty

func (t *Torrent) Pretty() string

Pretty returns a formatted string representing this Torrent

type View

type View string

View represents a "view" within Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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