qbittorrent_api

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 12 Imported by: 0

README

qbittorrent-api

golang实现的基于qBittorrent Web API v4.1.x接口的库.

参考API文档 qBittorrent's Official Web API Documentation

使用

go get github.com/xiangyt/qbittorrent-api

快速入门

Documentation

Index

Constants

View Source
const (
	GoQBitVersion  = "v1.0.0"
	WebQBitVersion = "v4.4.3.1"
)
View Source
const (
	FilterSortPriority = "priority"
	FilterSortName     = "name"
	FilterSortProgress = "progress"
)
View Source
const (
	ContentLayoutOriginal    = "Original"    // 原始
	ContentLayoutSubFolder   = "Subfolder"   // 创建子文件夹
	ContentLayoutNoSubFolder = "NoSubfolder" // 不创建子文件夹
)

Variables

View Source
var (
	//ErrMissingRequiredParameters = errors.New("MissingRequiredParameters")
	ErrInvalidRequest       = errors.New("InvalidRequest")
	ErrUnauthorized         = errors.New("Unauthorized")
	ErrForbidden            = errors.New("Forbidden")
	ErrNotFound             = errors.New("NotFound")
	ErrMethodNotAllowed     = errors.New("MethodNotAllowed")
	ErrConflict             = errors.New("Conflict")
	ErrUnsupportedMediaType = errors.New("UnsupportedMediaType")
	ErrInternalServerError  = errors.New("InternalServerError")
)

Functions

This section is empty.

Types

type Category

type Category struct {
	Name         string `json:"name"`
	SavePath     string `json:"savePath"`
	DownloadPath string `json:"download_path"`
}

type Client

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

func NewClient

func NewClient(host string, opts ...Option) *Client

func (*Client) AddTags added in v1.0.1

func (t *Client) AddTags(tags []string, ts ...*Torrent) error

AddTags Add one or more tags to one or more torrents. Note: Tags that do not exist will be created on-the-fly.

param tags: tag name or list of tags param torrent_hashes: single torrent hash or list of torrent hashes. Or “all“ for all torrents.

func (*Client) AddTagsByHashes added in v1.0.1

func (t *Client) AddTagsByHashes(tags, hashes []string) error

func (*Client) AddTagsForAll added in v1.0.1

func (t *Client) AddTagsForAll(tags []string) error

func (*Client) BottomPriority added in v1.0.1

func (t *Client) BottomPriority(ts ...*Torrent) error

BottomPriority Set torrent as highest priority. Torrent Queuing must be enabled. 移动到队列底部

func (*Client) BottomPriorityByHashes added in v1.0.1

func (t *Client) BottomPriorityByHashes(hashes []string) error

func (*Client) CreateCategory added in v1.0.1

func (t *Client) CreateCategory(category Category) error

CreateCategory Create a new torrent category. param name: name for new category param save_path: location to save torrents for this category (added in Web API 2.1.0) param download_path: download location for torrents with this category param enable_download_path: True or False to enable or disable download path

func (*Client) CreateTags added in v1.0.1

func (t *Client) CreateTags(tags ...string) error

CreateTags Create one or more tags.

func (*Client) DecreasePriority added in v1.0.1

func (t *Client) DecreasePriority(ts ...*Torrent) error

DecreasePriority Decrease the priority of a torrent. Torrent Queuing must be enabled. 向下移动队列

func (*Client) DecreasePriorityByHashes added in v1.0.1

func (t *Client) DecreasePriorityByHashes(hashes []string) error

func (*Client) Delete added in v1.0.1

func (t *Client) Delete(deleteFiles bool, ts ...*Torrent) error

Delete Remove a torrent from qBittorrent and optionally delete its files. param delete_files: True to delete the torrent's files param torrent_hashes: single torrent hash or list of torrent hashes. Or “all“ for all torrents. return: None

func (*Client) DeleteAll added in v1.0.1

func (t *Client) DeleteAll(deleteFiles bool) error

func (*Client) DeleteByHashes added in v1.0.1

func (t *Client) DeleteByHashes(deleteFiles bool, hashes []string) error

func (*Client) DeleteTags added in v1.0.1

func (t *Client) DeleteTags(tags ...string) error

DeleteTags Delete one or more tags.

func (*Client) DownloadFromFile added in v1.0.1

func (t *Client) DownloadFromFile(cfg TorrentDLConfig) error
func (t *Client) DownloadFromLink(cfg MagnetDLConfig) error

DownloadFromLink Add one or more torrents by URLs and/or torrent files.

:raises UnsupportedMediaType415Error: if file is not a valid torrent file :raises TorrentFileNotFoundError: if a torrent file doesn't exist :raises TorrentFilePermissionError: if read permission is denied to torrent file

:return: “Ok.“ for success and “Fails.“ for failure

func (*Client) EditCategory added in v1.0.1

func (t *Client) EditCategory(category Category) error

EditCategory Edit an existing category.

func (*Client) GetAllCategories added in v1.0.1

func (t *Client) GetAllCategories() ([]*Category, error)

GetAllCategories Retrieve all category definitions.

func (*Client) GetAllTags added in v1.0.1

func (t *Client) GetAllTags() ([]string, error)

GetAllTags Retrieve all category definitions.

func (*Client) GetAllTorrentFiles added in v1.0.1

func (t *Client) GetAllTorrentFiles(torrent *Torrent) ([]*TorrentFile, error)

GetAllTorrentFiles Get torrent contents.

func (*Client) GetAllTorrentFilesByHash added in v1.0.1

func (t *Client) GetAllTorrentFilesByHash(hash string) ([]*TorrentFile, error)

GetAllTorrentFilesByHash Get torrent contents.

func (*Client) IncreasePriority added in v1.0.1

func (t *Client) IncreasePriority(ts ...*Torrent) error

IncreasePriority Increase the priority of a torrent. Torrent Queuing must be enabled. 向上移动队列

func (*Client) IncreasePriorityByHashes added in v1.0.1

func (t *Client) IncreasePriorityByHashes(hashes []string) error

func (*Client) IsLoggedIn added in v1.0.1

func (a *Client) IsLoggedIn() bool

func (*Client) Login added in v1.0.1

func (a *Client) Login(username, password string) error

func (*Client) Logout added in v1.0.1

func (a *Client) Logout()

func (*Client) Pause added in v1.0.1

func (t *Client) Pause(ts ...*Torrent) error

Pause pause one or more torrents in qBittorrent.

func (*Client) PauseAll added in v1.0.1

func (t *Client) PauseAll() error

PauseAll pause all torrents in qBittorrent.

func (*Client) PauseByHashes added in v1.0.1

func (t *Client) PauseByHashes(hashes []string) error

PauseByHashes pause torrents in qBittorrent by hashes.

func (*Client) ReAnnounce added in v1.0.1

func (t *Client) ReAnnounce(ts ...*Torrent) error

ReAnnounce a torrent in qBittorrent.

func (*Client) ReAnnounceAll added in v1.0.1

func (t *Client) ReAnnounceAll() error

func (*Client) ReAnnounceByHashes added in v1.0.1

func (t *Client) ReAnnounceByHashes(hashes []string) error

func (*Client) Recheck added in v1.0.1

func (t *Client) Recheck(ts ...*Torrent) error

Recheck a torrent in qBittorrent.

func (*Client) RecheckAll added in v1.0.1

func (t *Client) RecheckAll() error

func (*Client) RecheckByHashes added in v1.0.1

func (t *Client) RecheckByHashes(hashes []string) error

func (*Client) RemoveCategories added in v1.0.1

func (t *Client) RemoveCategories(categories []string) error

RemoveCategories Delete one or more categories.

func (*Client) RemoveTags added in v1.0.1

func (t *Client) RemoveTags(tags []string) error

RemoveTags Remove one or more tags to one or more torrents.

func (*Client) RemoveTagsByHashes added in v1.0.1

func (t *Client) RemoveTagsByHashes(tags, hashes []string) error

func (*Client) RemoveTagsForAll added in v1.0.1

func (t *Client) RemoveTagsForAll(tags []string) error

func (*Client) Resume added in v1.0.1

func (t *Client) Resume(ts ...*Torrent) error

Resume resume one or more torrents in qBittorrent.

func (*Client) ResumeAll added in v1.0.1

func (t *Client) ResumeAll() error

ResumeAll resume all torrents in qBittorrent.

func (*Client) ResumeByHashes added in v1.0.1

func (t *Client) ResumeByHashes(hashes []string) error

ResumeByHashes resume torrents in qBittorrent by hashes.

func (*Client) SetCategory added in v1.0.1

func (t *Client) SetCategory(category string, ts ...*Torrent) error

SetCategory Set a category for one or more torrents.

func (*Client) SetCategoryByHashes added in v1.0.1

func (t *Client) SetCategoryByHashes(category string, hashes []string) error

func (*Client) SetCategoryForAll added in v1.0.1

func (t *Client) SetCategoryForAll(category string) error

func (*Client) SetFilePriority added in v1.0.1

func (t *Client) SetFilePriority(hash string, tfs []*TorrentFile, priority FilePriority) error

func (*Client) ToggleFirstLastPiecePriority added in v1.0.1

func (t *Client) ToggleFirstLastPiecePriority(ts ...*Torrent) error

ToggleFirstLastPiecePriority Increase the priority of a torrent. Torrent Queuing must be enabled. 选中/取消 先下载首尾文件块

func (*Client) ToggleFirstLastPiecePriorityByHashes added in v1.0.1

func (t *Client) ToggleFirstLastPiecePriorityByHashes(hashes []string) error

func (*Client) ToggleFirstLastPiecePriorityForAll added in v1.0.1

func (t *Client) ToggleFirstLastPiecePriorityForAll() error

func (*Client) ToggleSequentialDownload added in v1.0.1

func (t *Client) ToggleSequentialDownload(ts ...*Torrent) error

ToggleSequentialDownload Increase the priority of a torrent. Torrent Queuing must be enabled. 选中/取消 按顺序下载

func (*Client) ToggleSequentialDownloadByHashes added in v1.0.1

func (t *Client) ToggleSequentialDownloadByHashes(hashes []string) error

func (*Client) ToggleSequentialDownloadForAll added in v1.0.1

func (t *Client) ToggleSequentialDownloadForAll() error

func (*Client) TopPriority added in v1.0.1

func (t *Client) TopPriority(ts ...*Torrent) error

TopPriority Set torrent as highest priority. Torrent Queuing must be enabled. 移动到队列顶部

func (*Client) TopPriorityByHashes added in v1.0.1

func (t *Client) TopPriorityByHashes(hashes []string) error

func (*Client) Torrents added in v1.0.1

func (t *Client) Torrents(params *Filter) ([]*Torrent, error)

Torrents Retrieves list of info for torrents. Note: “hashes“ introduced in Web API 2.0.1

@param status_filter: Filter list by all, downloading, completed, paused, active, inactive, resumed

stalled, stalled_uploading and stalled_downloading added in Web API 2.4.1

@param category: Filter list by category @param sort: Sort list by any property returned @param reverse: Reverse sorting @param limit: Limit length of list @param offset: Start of list (if < 0, offset from end of list) @param torrent_hashes: Filter list by hash (separate multiple hashes with a '|') @param tag: Filter list by tag (empty string means "untagged"; no "tag" param means "any tag"; added in Web API 2.8.3) @return: :class:`TorrentInfoList` - `<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list>`_ noqa: E501

func (*Client) Version added in v1.0.1

func (a *Client) Version() (string, error)

type ContentLayout

type ContentLayout = string

type DownloadBaseConfig added in v1.0.1

type DownloadBaseConfig struct {
	SavePath           string        `json:"savepath"`           // 保存文件到:
	Category           string        `json:"category"`           // 分类:
	Tags               []string      `json:"tags"`               // 标签
	SkipChecking       bool          `json:"skip_checking"`      // 跳过哈希校验
	Paused             bool          `json:"paused"`             // 开始 Torrent
	ContentLayout      ContentLayout `json:"contentLayout"`      // 内容布局:
	Rename             string        `json:"rename"`             // 重命名 torrent
	UpLimit            int           `json:"upLimit"`            // 限制上传速率 bytes/second
	DlLimit            int           `json:"dlLimit"`            // 限制下载速率 bytes/second
	AutoTMM            bool          `json:"autoTMM"`            // 自动 Torrent 管理
	SequentialDownload bool          `json:"sequentialDownload"` // 按顺序下载
	FirstLastPiecePrio bool          `json:"firstLastPiecePrio"` // 先下载首尾文件块

}

DownloadBaseConfig :param save_path: location to save the torrent data :param cookie: cookie to retrieve torrents by URL :param category: category to assign to torrent(s) :param is_skip_checking: skip hash checking :param is_paused: True to start torrent(s) paused :param is_root_folder: True or False to create root folder (superseded by content_layout with v4.3.2) :param rename: new name for torrent(s) :param upload_limit: upload limit in bytes/second :param download_limit: download limit in bytes/second :param use_auto_torrent_management: True or False to use automatic torrent management :param is_sequential_download: True or False for sequential download :param is_first_last_piece_priority: True or False for first and last piece download priority :param tags: tag(s) to assign to torrent(s) (added in Web API 2.6.2) :param content_layout: Original, Subfolder, or NoSubfolder to control filesystem structure for content (added in Web API 2.7) :param ratio_limit: share limit as ratio of upload amt over download amt; e.g. 0.5 or 2.0 (added in Web API 2.8.1) :param seeding_time_limit: number of minutes to seed torrent (added in Web API 2.8.1) :param download_path: location to download torrent content before moving to save_path (added in Web API 2.8.4) :param use_download_path: whether the download_path should be used...defaults to True if download_path is specified (added in Web API 2.8.4)

type FilePriority

type FilePriority = int
const (
	FilePriorityDoNotDL FilePriority = 0 // Do not download
	FilePriorityNormal  FilePriority = 1 // Normal priority
	FilePriorityHigh    FilePriority = 6 // High priority
	FilePriorityMaximal FilePriority = 7 // Maximal priority
)

type Filter

type Filter struct {
	StatusFilter TorrentState `json:"filter"`
	Category     string       `json:"category"`
	Sort         FilterSort   `json:"sort"`
	Reverse      bool         `json:"reverse"`
	Limit        int          `json:"limit"`
	Offset       int          `json:"offset"`
	Hashes       []string     `json:"torrent_hashes"`
	Tag          string       `json:"tag"`
}

Filter param status_filter: Filter list by all, downloading, completed, paused, active, inactive, resumed

stalled, stalled_uploading and stalled_downloading added in Web API 2.4.1

param category: Filter list by category param sort: Sort list by any property returned param reverse: Reverse sorting param limit: Limit length of list param offset: Start of list (if < 0, offset from end of list) param torrent_hashes: Filter list by hash (separate multiple hashes with a '|') param tag: Filter list by tag (empty string means "untagged"; no "tag" param means "any tag"; added in Web API 2.8.3)

type FilterSort

type FilterSort = string

type MagnetDLConfig

type MagnetDLConfig struct {
	Urls []string `json:"urls"`
	DownloadBaseConfig
}

MagnetDLConfig :param urls: single instance or an iterable of URLs (http://, https://, magnet: and bc://bt/)

type Option

type Option func(client *Client)

func WithAuth

func WithAuth(username, password string) Option

type Torrent

type Torrent struct {
	AddedOn                int          `json:"added_on"`
	AmountLeft             int64        `json:"amount_left"`
	AutoTmm                bool         `json:"auto_tmm"`
	Availability           float64      `json:"availability"`
	Category               string       `json:"category"`
	Completed              int64        `json:"completed"`
	CompletionOn           int          `json:"completion_on"`
	ContentPath            string       `json:"content_path"`
	DlLimit                int          `json:"dl_limit"`
	DlSpeed                int          `json:"dlspeed"`
	DownloadPath           string       `json:"download_path"`
	Downloaded             int64        `json:"downloaded"`
	DownloadedSession      int          `json:"downloaded_session"`
	Eta                    int          `json:"eta"`
	FirstLastPiecePriority bool         `json:"f_l_piece_prio"`
	ForceStart             bool         `json:"force_start"`
	Hash                   string       `json:"hash"`
	InfoHashV1             string       `json:"infohash_v1"`
	InfoHashV2             string       `json:"infohash_v2"`
	LastActivity           int          `json:"last_activity"`
	MagnetUri              string       `json:"magnet_uri"`
	MaxRatio               int          `json:"max_ratio"`
	MaxSeedingTime         int          `json:"max_seeding_time"`
	Name                   string       `json:"name"`
	NumComplete            int          `json:"num_complete"`
	NumIncomplete          int          `json:"num_incomplete"`
	NumLeechs              int          `json:"num_leechs"`
	NumSeeds               int          `json:"num_seeds"`
	Priority               int          `json:"priority"`
	Progress               float64      `json:"progress"`
	Ratio                  float64      `json:"ratio"`
	RatioLimit             int          `json:"ratio_limit"`
	SavePath               string       `json:"save_path"`
	SeedingTime            int          `json:"seeding_time"`
	SeedingTimeLimit       int          `json:"seeding_time_limit"`
	SeenComplete           int          `json:"seen_complete"`
	SequentialDownload     bool         `json:"seq_dl"`
	Size                   int64        `json:"size"`
	State                  TorrentState `json:"state"`
	SuperSeeding           bool         `json:"super_seeding"`
	Tags                   string       `json:"tags"`
	TimeActive             int          `json:"time_active"`
	TotalSize              int64        `json:"total_size"`
	Tracker                string       `json:"tracker"`
	TrackersCount          int          `json:"trackers_count"`
	UpLimit                int          `json:"up_limit"`
	Uploaded               int64        `json:"uploaded"`
	UploadedSession        int          `json:"uploaded_session"`
	UpSpeed                int          `json:"upspeed"`
}

func (Torrent) IsChecking

func (t Torrent) IsChecking() bool

func (Torrent) IsComplete

func (t Torrent) IsComplete() bool

func (Torrent) IsDownloading

func (t Torrent) IsDownloading() bool

func (Torrent) IsErrored

func (t Torrent) IsErrored() bool

func (Torrent) IsPaused

func (t Torrent) IsPaused() bool

func (Torrent) IsUploading

func (t Torrent) IsUploading() bool

type TorrentDLConfig

type TorrentDLConfig struct {
	File string `json:"file"`
	DownloadBaseConfig
}

TorrentDLConfig :param torrent_files: several options are available to send torrent files to qBittorrent:

  • single instance of bytes: useful if torrent file already read from disk or downloaded from internet.
  • single instance of file handle to torrent file: use open(<filepath>, 'rb') to open the torrent file.
  • single instance of a filepath to torrent file: e.g. '/home/user/torrent_filename.torrent'
  • an iterable of the single instances above to send more than one torrent file
  • dictionary with key/value pairs of torrent name and single instance of above object Note: The torrent name in a dictionary is useful to identify which torrent file errored. qBittorrent provides back that name in the error text. If a torrent name is not provided, then the name of the file will be used. And in the case of bytes (or if filename cannot be determined), the value 'torrent__n' will be used

type TorrentFile

type TorrentFile struct {
	Index        int          `json:"index"`        // File index
	Name         string       `json:"name"`         // File name (including relative path)
	Size         int64        `json:"size"`         // File size (bytes)
	Progress     float64      `json:"progress"`     // File progress (percentage/100)
	Priority     FilePriority `json:"priority"`     // File priority. See possible values here below
	IsSeed       bool         `json:"is_seed"`      // True if file is seeding/complete
	PieceRange   []int        `json:"piece_range"`  // The first number is the starting piece index and the second number is the ending piece index (inclusive)
	Availability float64      `json:"availability"` // Percentage of file pieces currently available (percentage/100)
}

type TorrentFiles

type TorrentFiles []*TorrentFile

func (TorrentFiles) Filter added in v1.0.1

func (tfs TorrentFiles) Filter(fn func(tf *TorrentFile) bool) TorrentFiles

func (TorrentFiles) Len

func (tfs TorrentFiles) Len() int

func (TorrentFiles) Less

func (tfs TorrentFiles) Less(i, j int) bool

func (TorrentFiles) Swap

func (tfs TorrentFiles) Swap(i, j int)

type TorrentState added in v1.0.1

type TorrentState = string
const (
	StateError                  TorrentState = "error"
	StateMissingFiles           TorrentState = "missingFiles"
	StateUploading              TorrentState = "uploading"
	StatePausedUpload           TorrentState = "pausedUP"
	StateQueuedUpload           TorrentState = "queuedUP"
	StateStalledUpload          TorrentState = "stalledUP"
	StateCheckingUpload         TorrentState = "checkingUP"
	StateForcedUpload           TorrentState = "forcedUP"
	StateAllocating             TorrentState = "allocating"
	StateDownloading            TorrentState = "downloading"
	StateMetadataDownload       TorrentState = "metaDL"
	StateForcedMetadataDownload TorrentState = "forcedMetaDL"
	StatePausedDownload         TorrentState = "pausedDL"
	StateQueuedDownload         TorrentState = "queuedDL"
	StateForcedDownload         TorrentState = "forcedDL"
	StateStalledDownload        TorrentState = "stalledDL"
	StateCheckingDownload       TorrentState = "checkingDL"
	StateCheckingResumeData     TorrentState = "checkingResumeData"
	StateMoving                 TorrentState = "moving"
	StateUnknown                TorrentState = "unknown"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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