torrent

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package torrent provides integration with various torrent clients for remote download management. vget doesn't download torrents directly - it dispatches jobs to existing torrent clients running on NAS devices or local machines.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected     = errors.New("not connected to torrent client")
	ErrAuthFailed       = errors.New("authentication failed")
	ErrTorrentNotFound  = errors.New("torrent not found")
	ErrDuplicateTorrent = errors.New("torrent already exists")
	ErrInvalidMagnet    = errors.New("invalid magnet link")
	ErrInvalidTorrent   = errors.New("invalid torrent file")
	ErrConnectionFailed = errors.New("failed to connect to torrent client")
)

Common errors

Functions

func IsMagnetLink(url string) bool

IsMagnetLink checks if a URL is a magnet link

func IsTorrentURL

func IsTorrentURL(url string) bool

IsTorrentURL checks if a URL points to a .torrent file

Types

type AddOptions

type AddOptions struct {
	// SavePath overrides the default download directory
	SavePath string

	// Paused starts the torrent in paused state
	Paused bool

	// Labels/Tags to apply (not all clients support this)
	Labels []string

	// Category (qBittorrent specific, but useful abstraction)
	Category string

	// DownloadSpeedLimit in bytes/sec (0 = unlimited)
	DownloadSpeedLimit int64

	// UploadSpeedLimit in bytes/sec (0 = unlimited)
	UploadSpeedLimit int64
}

AddOptions contains options for adding a torrent

type AddResult

type AddResult struct {
	ID        string // Client-specific ID
	Hash      string // InfoHash
	Name      string // Torrent name (may be empty if magnet hasn't resolved yet)
	Duplicate bool   // True if torrent was already in the client
}

AddResult contains the result of adding a torrent

type Client

type Client interface {
	// Name returns the client name (e.g., "transmission", "qbittorrent")
	Name() string

	// Connect establishes connection and authenticates with the client
	// Should be called before other operations
	Connect() error

	// Close cleans up any resources (e.g., logout)
	Close() error

	// AddMagnet adds a torrent via magnet link
	AddMagnet(magnetURL string, opts *AddOptions) (*AddResult, error)

	// AddTorrentURL adds a torrent via HTTP/HTTPS URL to a .torrent file
	AddTorrentURL(url string, opts *AddOptions) (*AddResult, error)

	// AddTorrentFile adds a torrent from a local .torrent file
	AddTorrentFile(path string, opts *AddOptions) (*AddResult, error)

	// GetTorrent retrieves info about a specific torrent by ID or hash
	GetTorrent(id string) (*TorrentInfo, error)

	// ListTorrents retrieves info about all torrents
	ListTorrents() ([]TorrentInfo, error)

	// RemoveTorrent removes a torrent
	// If deleteData is true, also deletes downloaded files
	RemoveTorrent(id string, deleteData bool) error

	// PauseTorrent pauses a torrent
	PauseTorrent(id string) error

	// ResumeTorrent resumes a paused torrent
	ResumeTorrent(id string) error
}

Client defines the interface for torrent client implementations

func NewClient

func NewClient(cfg *Config) (Client, error)

NewClient creates a new torrent client based on the config

type ClientType

type ClientType string

ClientType represents supported torrent client types

const (
	ClientTransmission ClientType = "transmission"
	ClientQBittorrent  ClientType = "qbittorrent"
	ClientSynology     ClientType = "synology"
)

type Config

type Config struct {
	Type     ClientType
	Host     string // hostname:port
	Username string
	Password string
	UseHTTPS bool
}

Config holds configuration for connecting to a torrent client

type QBittorrentClient

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

QBittorrentClient implements the Client interface for qBittorrent Web UI qBittorrent Web API: https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)

func NewQBittorrentClient

func NewQBittorrentClient(cfg *Config) *QBittorrentClient

NewQBittorrentClient creates a new qBittorrent client

func (*QBittorrentClient) AddMagnet

func (c *QBittorrentClient) AddMagnet(magnetURL string, opts *AddOptions) (*AddResult, error)

AddMagnet adds a torrent via magnet link

func (*QBittorrentClient) AddTorrentFile

func (c *QBittorrentClient) AddTorrentFile(path string, opts *AddOptions) (*AddResult, error)

AddTorrentFile adds a torrent from a local .torrent file

func (*QBittorrentClient) AddTorrentURL

func (c *QBittorrentClient) AddTorrentURL(torrentURL string, opts *AddOptions) (*AddResult, error)

AddTorrentURL adds a torrent via HTTP/HTTPS URL

func (*QBittorrentClient) Close

func (c *QBittorrentClient) Close() error

Close logs out from qBittorrent

func (*QBittorrentClient) Connect

func (c *QBittorrentClient) Connect() error

Connect authenticates with qBittorrent

func (*QBittorrentClient) GetTorrent

func (c *QBittorrentClient) GetTorrent(id string) (*TorrentInfo, error)

GetTorrent retrieves info about a specific torrent by hash

func (*QBittorrentClient) ListTorrents

func (c *QBittorrentClient) ListTorrents() ([]TorrentInfo, error)

ListTorrents retrieves info about all torrents

func (*QBittorrentClient) Name

func (c *QBittorrentClient) Name() string

func (*QBittorrentClient) PauseTorrent

func (c *QBittorrentClient) PauseTorrent(id string) error

PauseTorrent pauses a torrent

func (*QBittorrentClient) RemoveTorrent

func (c *QBittorrentClient) RemoveTorrent(id string, deleteData bool) error

RemoveTorrent removes a torrent

func (*QBittorrentClient) ResumeTorrent

func (c *QBittorrentClient) ResumeTorrent(id string) error

ResumeTorrent resumes a paused torrent

type SynologyClient

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

SynologyClient implements the Client interface for Synology Download Station Synology Download Station API: https://global.download.synology.com/download/Document/Software/DeveloperGuide/Package/DownloadStation/All/enu/Synology_Download_Station_Web_API.pdf

func NewSynologyClient

func NewSynologyClient(cfg *Config) *SynologyClient

NewSynologyClient creates a new Synology Download Station client

func (*SynologyClient) AddMagnet

func (c *SynologyClient) AddMagnet(magnetURL string, opts *AddOptions) (*AddResult, error)

AddMagnet adds a torrent via magnet link

func (*SynologyClient) AddTorrentFile

func (c *SynologyClient) AddTorrentFile(path string, opts *AddOptions) (*AddResult, error)

AddTorrentFile adds a torrent from a local .torrent file

func (*SynologyClient) AddTorrentURL

func (c *SynologyClient) AddTorrentURL(torrentURL string, opts *AddOptions) (*AddResult, error)

AddTorrentURL adds a torrent via HTTP/HTTPS URL

func (*SynologyClient) Close

func (c *SynologyClient) Close() error

Close logs out from Synology DSM

func (*SynologyClient) Connect

func (c *SynologyClient) Connect() error

Connect authenticates with Synology DSM

func (*SynologyClient) GetTorrent

func (c *SynologyClient) GetTorrent(id string) (*TorrentInfo, error)

GetTorrent retrieves info about a specific torrent by ID

func (*SynologyClient) ListTorrents

func (c *SynologyClient) ListTorrents() ([]TorrentInfo, error)

ListTorrents retrieves info about all torrents

func (*SynologyClient) Name

func (c *SynologyClient) Name() string

func (*SynologyClient) PauseTorrent

func (c *SynologyClient) PauseTorrent(id string) error

PauseTorrent pauses a torrent

func (*SynologyClient) RemoveTorrent

func (c *SynologyClient) RemoveTorrent(id string, deleteData bool) error

RemoveTorrent removes a torrent

func (*SynologyClient) ResumeTorrent

func (c *SynologyClient) ResumeTorrent(id string) error

ResumeTorrent resumes a paused torrent

type TorrentInfo

type TorrentInfo struct {
	ID            string       // Client-specific ID (hash or numeric)
	Hash          string       // InfoHash
	Name          string       // Torrent name
	State         TorrentState // Current state
	Progress      float64      // Download progress (0.0 - 1.0)
	Size          int64        // Total size in bytes
	Downloaded    int64        // Downloaded bytes
	Uploaded      int64        // Uploaded bytes
	DownloadSpeed int64        // Current download speed (bytes/sec)
	UploadSpeed   int64        // Current upload speed (bytes/sec)
	Ratio         float64      // Upload/Download ratio
	ETA           int64        // Estimated time remaining (seconds), -1 if unknown
	SavePath      string       // Download location
	Error         string       // Error message if State == StateError
}

TorrentInfo contains information about a torrent

type TorrentState

type TorrentState int

TorrentState represents the current state of a torrent

const (
	StateStopped TorrentState = iota
	StateQueued
	StateDownloading
	StateSeeding
	StatePaused
	StateChecking
	StateError
	StateUnknown
)

func (TorrentState) String

func (s TorrentState) String() string

type TransmissionClient

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

TransmissionClient implements the Client interface for Transmission daemon Transmission RPC specification: https://github.com/transmission/transmission/blob/main/docs/rpc-spec.md

func NewTransmissionClient

func NewTransmissionClient(cfg *Config) *TransmissionClient

NewTransmissionClient creates a new Transmission client

func (*TransmissionClient) AddMagnet

func (c *TransmissionClient) AddMagnet(magnetURL string, opts *AddOptions) (*AddResult, error)

AddMagnet adds a torrent via magnet link

func (*TransmissionClient) AddTorrentFile

func (c *TransmissionClient) AddTorrentFile(path string, opts *AddOptions) (*AddResult, error)

AddTorrentFile adds a torrent from a local .torrent file

func (*TransmissionClient) AddTorrentURL

func (c *TransmissionClient) AddTorrentURL(url string, opts *AddOptions) (*AddResult, error)

AddTorrentURL adds a torrent via HTTP/HTTPS URL

func (*TransmissionClient) Close

func (c *TransmissionClient) Close() error

func (*TransmissionClient) Connect

func (c *TransmissionClient) Connect() error

Connect establishes connection and gets session ID

func (*TransmissionClient) GetTorrent

func (c *TransmissionClient) GetTorrent(id string) (*TorrentInfo, error)

GetTorrent retrieves info about a specific torrent

func (*TransmissionClient) ListTorrents

func (c *TransmissionClient) ListTorrents() ([]TorrentInfo, error)

ListTorrents retrieves info about all torrents

func (*TransmissionClient) Name

func (c *TransmissionClient) Name() string

func (*TransmissionClient) PauseTorrent

func (c *TransmissionClient) PauseTorrent(id string) error

PauseTorrent pauses a torrent

func (*TransmissionClient) RemoveTorrent

func (c *TransmissionClient) RemoveTorrent(id string, deleteData bool) error

RemoveTorrent removes a torrent

func (*TransmissionClient) ResumeTorrent

func (c *TransmissionClient) ResumeTorrent(id string) error

ResumeTorrent resumes a paused torrent

Jump to

Keyboard shortcuts

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