client

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	STATES        = []string{"seeding", "downloading", "completed", "paused", "checking", "error", "unknown"}
	STATE_FILTERS = []string{"_all", "_active", "_done", "_undone"}
	Registry      = []*RegInfo{}
)
View Source
var TrackerValidityInfos = []*TrackerValidityInfoStruct{
	{TRACKER_VALIDITY_OK, "ok", ""},
	{TRACKER_VALIDITY_VIOLATE_RULE, "violate_rule",
		"Torrent is currently exceeding the simultaneous downloading / seeding clients number limit"},
	{TRACKER_VALIDITY_INVALID_AUTH, "invalid_auth", "Tracker url passkey or authkey is required or invalid"},
	{TRACKER_VALIDITY_NOT_EXIST, "not_exist", "Torrent is not registered in the tracker(s)"},
}

all tracker validity status infos. the array index is also the status value.

Functions

func ClientExists

func ClientExists(name string) bool

func DeleteTorrentsAuto added in v0.1.10

func DeleteTorrentsAuto(clientInstance Client, infoHashes []string) (err error)

Delete torrents from client. If torrent has no other xseed torrent (with same content path), delete files; Otherwise preserve files.

func Exit added in v0.1.6

func Exit()

called by main codes on program exit. clean resources

func GenerateNameWithMeta

func GenerateNameWithMeta(name string, meta map[string]int64) string

func GenerateTorrentTagFromCategory added in v0.1.2

func GenerateTorrentTagFromCategory(category string) string

func GenerateTorrentTagFromMetadata added in v0.1.5

func GenerateTorrentTagFromMetadata(name string, value int64) string

func GenerateTorrentTagFromSite

func GenerateTorrentTagFromSite(site string) string

func IsSubstituteTag added in v0.1.5

func IsSubstituteTag(tag string) bool

func IsValidInfoHash added in v0.1.2

func IsValidInfoHash(infoHash string) bool

func IsValidInfoHashOrStateFilter added in v0.1.2

func IsValidInfoHashOrStateFilter(stateFilter string) bool

func IsValidStateFilter added in v0.1.10

func IsValidStateFilter(stateFilter string) bool

func ParseMetaFromName

func ParseMetaFromName(fullname string) (name string, meta map[string]int64)

func PrintDummyStatus added in v0.1.10

func PrintDummyStatus(f io.Writer, name string, info string)

func PrintTorrentFiles added in v0.1.1

func PrintTorrentFiles(files []*TorrentContentFile, showRaw bool)

func PrintTorrentTrackers added in v0.1.1

func PrintTorrentTrackers(trackers TorrentTrackers)

func PrintTorrents

func PrintTorrents(output io.Writer, torrents []*Torrent, filter string, showSum int64, dense bool)

showSum: 0 - no; 1 - yes; 2 - sum only

func Purge added in v0.1.6

func Purge(clientName string)

Purge client cache

func Register

func Register(regInfo *RegInfo)

func SelectTorrents added in v0.1.1

func SelectTorrents(clientInstance Client, category string, tag string, filter string,
	hashOrStateFilters ...string) ([]string, error)

Query torrents that meet criterion and return infoHashes. Specially, return nil slice if all torrents selected. If all hashOrStateFilters is plain info-hash and all other conditions empty, just return hashOrStateFilters,nil. category: "none" is a special value to select uncategoried torrents. tag: comma-separated list, a torrent matches if it has any tag that in the list; specially, "none" means untagged torrents.

Types

type Client

type Client interface {
	// download / export .torrent file for a torrent in client
	ExportTorrentFile(infoHash string) ([]byte, error)
	GetTorrent(infoHash string) (*Torrent, error)
	// category: "none" is a special value to select uncategoried torrents.
	// stateFilter: _all|_active|_done|_undone, or any state value (possibly with a _ prefix)
	GetTorrents(stateFilter string, category string, showAll bool) ([]*Torrent, error)
	GetTorrentsByContentPath(contentPath string) ([]*Torrent, error)
	AddTorrent(torrentContent []byte, option *TorrentOption, meta map[string]int64) error
	ModifyTorrent(infoHash string, option *TorrentOption, meta map[string]int64) error
	DeleteTorrents(infoHashes []string, deleteFiles bool) error
	PauseTorrents(infoHashes []string) error
	ResumeTorrents(infoHashes []string) error
	RecheckTorrents(infoHashes []string) error
	ReannounceTorrents(infoHashes []string) error
	AddTagsToTorrents(infoHashes []string, tags []string) error
	RemoveTagsFromTorrents(infoHashes []string, tags []string) error
	SetTorrentsSavePath(infoHashes []string, savePath string) error
	PauseAllTorrents() error
	ResumeAllTorrents() error
	RecheckAllTorrents() error
	ReannounceAllTorrents() error
	AddTagsToAllTorrents(tags []string) error
	RemoveTagsFromAllTorrents(tags []string) error
	SetAllTorrentsSavePath(savePath string) error
	GetTags() ([]string, error)
	CreateTags(tags ...string) error
	DeleteTags(tags ...string) error
	// create category if not existed, edit category if already exists
	MakeCategory(category string, savePath string) error
	DeleteCategories(categories []string) error
	GetCategories() ([]*TorrentCategory, error)
	SetTorrentsCatetory(infoHashes []string, category string) error
	SetAllTorrentsCatetory(category string) error
	SetTorrentsShareLimits(infoHashes []string, ratioLimit float64, seedingTimeLimit int64) error
	SetAllTorrentsShareLimits(ratioLimit float64, seedingTimeLimit int64) error
	TorrentRootPathExists(rootFolder string) bool
	GetTorrentContents(infoHash string) ([]*TorrentContentFile, error)
	PurgeCache()
	GetStatus() (*Status, error)
	GetName() string
	GetClientConfig() *config.ClientConfigStruct
	SetConfig(variable string, value string) error
	GetConfig(variable string) (string, error)
	GetTorrentTrackers(infoHash string) (TorrentTrackers, error)
	EditTorrentTracker(infoHash string, oldTracker string, newTracker string, replaceHost bool) error
	AddTorrentTrackers(infoHash string, trackers []string, oldTracker string, removeExisting bool) error
	RemoveTorrentTrackers(infoHash string, trackers []string) error
	// QB only, priority: 0	Do not download; 1	Normal priority; 6	High priority; 7	Maximal priority
	SetFilePriority(infoHash string, fileIndexes []int64, priority int64) error
	Cached() bool
	Close()
}

func CreateClient

func CreateClient(name string) (Client, error)

type ClientCreator

type ClientCreator func(*RegInfo) (Client, error)

type RegInfo

type RegInfo struct {
	Name    string
	Creator func(string, *config.ClientConfigStruct, *config.ConfigStruct) (Client, error)
}

func Find

func Find(name string) (*RegInfo, error)

type Status

type Status struct {
	FreeSpaceOnDisk           int64 // -1 means unknown
	UnfinishedSize            int64
	UnfinishedDownloadingSize int64
	DownloadSpeed             int64
	UploadSpeed               int64
	DownloadSpeedLimit        int64 // <= 0 means no limit
	UploadSpeedLimit          int64 // <= 0 means no limit
	NoAdd                     bool  // if true, brush and other tasks will NOT add any torrent to client
	NoDel                     bool  // if true, brush and other tasks will NOT delete any torrent from client
}

func (*Status) Print added in v0.1.10

func (cs *Status) Print(f io.Writer, name string, additionalInfo string)

type Torrent

type Torrent struct {
	InfoHash           string
	Name               string
	TrackerDomain      string // e.g. tracker.m-team.cc
	TrackerBaseDomain  string // e.g. m-team.cc
	Tracker            string
	State              string // simplified state: seeding|downloading|completed|paused|checking|error|unknown
	LowLevelState      string // original state value returned by bt client
	Atime              int64  // timestamp torrent added
	Ctime              int64  // timestamp torrent completed. <=0 if not completed.
	ActivityTime       int64  // timestamp of torrent latest activity (a chunk being downloaded / uploaded)
	Category           string
	SavePath           string
	ContentPath        string
	Tags               []string
	Downloaded         int64
	DownloadSpeed      int64
	DownloadSpeedLimit int64 // -1 means no limit
	Uploaded           int64
	UploadSpeed        int64
	UploadedSpeedLimit int64 // -1 means no limit
	Size               int64 // size of torrent files that selected for downloading
	SizeTotal          int64 // Total size of all file in the torrent (including unselected ones)
	SizeCompleted      int64
	Seeders            int64 // Cnt of seeders (including self client, if it's seeding), returned by tracker
	Leechers           int64
	Meta               map[string]int64
}

@todo: considering changing it to interface

func FilterTorrentsXseed added in v0.1.10

func FilterTorrentsXseed(clientInstance Client, torrents []*Torrent) (
	torrentsNoXseed, torrentsXseed []*Torrent, err error)

Separate client torrents into 2 groups: torrentsNoXseed and torrentsXseed. The first ones does NOT have any other xseed torrent of same content path, or all xseed torrents themselves are also in the group. The second ones has other xseed torrent of same content path.

func QueryTorrents added in v0.1.1

func QueryTorrents(clientInstance Client, category string, tag string, filter string,
	hashOrStateFilters ...string) ([]*Torrent, error)

Parse and return torrents that meet criterion. tag: comma-separated list, a torrent matches if it has any tag that in the list; specially, "none" means untagged torrents.

func (*Torrent) GetCategoryFromTag added in v0.1.2

func (torrent *Torrent) GetCategoryFromTag() string

func (*Torrent) GetMetaFromTag added in v0.1.2

func (torrent *Torrent) GetMetaFromTag(meta string) string

func (*Torrent) GetMetadataFromTags added in v0.1.5

func (torrent *Torrent) GetMetadataFromTags() map[string]int64

func (*Torrent) GetSiteFromTag

func (torrent *Torrent) GetSiteFromTag() string

func (*Torrent) HasAnyTag added in v0.1.10

func (torrent *Torrent) HasAnyTag(tags string) bool

Return true if torrent has any tag in the tags. tags: comma-separated tag list.

func (*Torrent) HasTag

func (torrent *Torrent) HasTag(tag string) bool

func (*Torrent) IsComplete

func (torrent *Torrent) IsComplete() bool

func (*Torrent) IsFull

func (torrent *Torrent) IsFull() bool

func (*Torrent) IsFullComplete

func (torrent *Torrent) IsFullComplete() bool

func (*Torrent) MatchFilter added in v0.1.10

func (torrent *Torrent) MatchFilter(filter string) bool

func (*Torrent) MatchFiltersOr added in v0.1.10

func (torrent *Torrent) MatchFiltersOr(filters []string) bool

func (*Torrent) MatchStateFilter added in v0.1.1

func (torrent *Torrent) MatchStateFilter(stateFilter string) bool

func (*Torrent) MatchTracker added in v0.1.10

func (torrent *Torrent) MatchTracker(tracker string) bool

Matches if torrent tracker's url or domain == tracker. Specially, if tracker is "none", matches if torrent does NOT have a (working) tracker.

func (*Torrent) Print added in v0.1.9

func (torrent *Torrent) Print()

func (*Torrent) RemoveSubstituteTags added in v0.1.5

func (torrent *Torrent) RemoveSubstituteTags()

func (*Torrent) StateIconText added in v0.1.5

func (torrent *Torrent) StateIconText() string

type TorrentCategory added in v0.1.5

type TorrentCategory struct {
	Name     string `json:"name"`
	SavePath string `json:"savePath"`
}

type TorrentContentFile

type TorrentContentFile struct {
	Index    int64
	Path     string // full file path
	Size     int64
	Progress float64 // [0, 1]
	Ignored  bool    // true if file is ignored (excluded from downloading)
	Complete bool    // true if file is fullly downloaded
}

type TorrentOption

type TorrentOption struct {
	Name               string // if not empty, set name of torrent in client to this value
	Category           string
	SavePath           string
	Tags               []string
	RemoveTags         []string // used only in ModifyTorrent
	DownloadSpeedLimit int64
	UploadSpeedLimit   int64
	RatioLimit         float64 // If > 0, will stop seeding after ratio (up/dl) exceeds this value
	SeedingTimeLimit   int64   // If > 0, will stop seeding after be seeded for this time (seconds)
	SkipChecking       bool
	Pause              bool
	Resume             bool // use only in ModifyTorrent, to start a paused torrent
	SequentialDownload bool // qb only
}

type TorrentTracker added in v0.1.1

type TorrentTracker struct {
	Status string //working|notcontacted|error|updating|disabled|unknown
	Url    string
	Msg    string
}

func (*TorrentTracker) SpeculateTrackerValidity added in v0.1.10

func (tracker *TorrentTracker) SpeculateTrackerValidity() TrackerValidity

type TorrentTrackers added in v0.1.5

type TorrentTrackers []TorrentTracker

func (TorrentTrackers) FindIndex added in v0.1.5

func (trackers TorrentTrackers) FindIndex(hostOrUrl string) int

return index or -1

func (TorrentTrackers) SpeculateTrackerValidity added in v0.1.10

func (trackers TorrentTrackers) SpeculateTrackerValidity() TrackerValidity

type TrackerValidity added in v0.1.10

type TrackerValidity int64

种子 tracker 合法性(validity)状态. > 0 值 表示已知类型的异常状态。 数字越大,异常状态严重程度越高。0 值表示正常(未识别出已知的异常)。

const (
	TRACKER_VALIDITY_OK           TrackerValidity = iota // 正常(未识别出已知的异常状态)
	TRACKER_VALIDITY_VIOLATE_RULE                        // 不符合做种规则(例如超过同时做种设备数量限制)
	TRACKER_VALIDITY_INVALID_AUTH                        // authkey / passkey 不正确
	TRACKER_VALIDITY_NOT_EXIST                           // 种子在站点里不存在或已被删除
)

type TrackerValidityInfoStruct added in v0.1.10

type TrackerValidityInfoStruct = struct {
	Value TrackerValidity
	Name  string
	Desc  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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