Documentation
¶
Index ¶
- func ComputeTorrentHash(data []byte) (string, error)
- func ComputeTorrentHashWithPath(filePath string) (string, error)
- func GetTorrentFilesPath(directory string) ([]string, error)
- type DownloadTaskInfo
- type QbitClient
- func (q *QbitClient) AddTorrent(fileData []byte, category, tags string) error
- func (q *QbitClient) CanAddTorrent(ctx context.Context, fileSize int64) (bool, error)
- func (q *QbitClient) CheckTorrentExists(torrentHash string) (bool, error)
- func (q *QbitClient) DoRequestWithRetry(req *http.Request) (*http.Response, error)
- func (q *QbitClient) GetDiskSpace(c context.Context) (int64, error)
- func (q *QbitClient) GetLastAddedTorrentTime() (time.Time, error)
- func (q *QbitClient) ProcessSingleTorrentFile(ctx context.Context, filePath, category, tags string) error
- func (q *QbitClient) ProcessTorrentDirectory(ctx context.Context, directory string, category, tags string) error
- func (q *QbitClient) WaitAndAddTorrentSmart(ctx context.Context, fileData []byte, category, tags string, ...) error
- type QbitTorrentProperties
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeTorrentHash ¶
ComputeTorrentHash 计算种子的 SHA1 哈希值
Types ¶
type DownloadTaskInfo ¶ added in v0.1.0
type QbitClient ¶
type QbitClient struct {
BaseURL string
Username string
Password string
Client *http.Client
RateLimiter *time.Ticker
// contains filtered or unexported fields
}
func NewQbitClient ¶
func NewQbitClient(baseURL, username, password string, rateLimit time.Duration) (*QbitClient, error)
func (*QbitClient) AddTorrent ¶
func (q *QbitClient) AddTorrent(fileData []byte, category, tags string) error
func (*QbitClient) CanAddTorrent ¶
func (*QbitClient) CheckTorrentExists ¶
func (q *QbitClient) CheckTorrentExists(torrentHash string) (bool, error)
CheckTorrentExists 检查种子是否存在
func (*QbitClient) DoRequestWithRetry ¶ added in v0.0.8
func (*QbitClient) GetDiskSpace ¶
func (q *QbitClient) GetDiskSpace(c context.Context) (int64, error)
func (*QbitClient) GetLastAddedTorrentTime ¶
func (q *QbitClient) GetLastAddedTorrentTime() (time.Time, error)
func (*QbitClient) ProcessSingleTorrentFile ¶
func (q *QbitClient) ProcessSingleTorrentFile(ctx context.Context, filePath, category, tags string) error
func (*QbitClient) ProcessTorrentDirectory ¶
func (*QbitClient) WaitAndAddTorrentSmart ¶ added in v0.1.0
func (q *QbitClient) WaitAndAddTorrentSmart(ctx context.Context, fileData []byte, category, tags string, maxDuration time.Duration, sharedStats []DownloadTaskInfo, sharedRate int64) error
func (q *QbitClient) GetActiveDownloadTasks(ctx context.Context) ([]DownloadTaskInfo, int64, error) {
url := fmt.Sprintf("%s/api/v2/sync/maindata", q.BaseURL)
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return nil, 0, err
}
resp, err := q.Client.Do(req)
if err != nil {
return nil, 0, err
}
defer resp.Body.Close()
var data struct {
ServerState struct {
DownloadRate int64 `json:"dl_info_speed"`
} `json:"server_state"`
Torrents map[string]struct {
Name string `json:"name"`
AmountLeft int64 `json:"amount_left"`
DownloadSpeed int64 `json:"dlspeed"`
State string `json:"state"`
} `json:"torrents"`
}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, 0, err
}
var tasks []DownloadTaskInfo
for hash, t := range data.Torrents {
if t.AmountLeft > 0 && t.DownloadSpeed > 0 && strings.HasPrefix(t.State, "downloading") {
eta := time.Duration(float64(t.AmountLeft)/float64(t.DownloadSpeed)) * time.Second
tasks = append(tasks, DownloadTaskInfo{
Name: t.Name,
Hash: hash,
SizeLeft: t.AmountLeft,
DownloadSpeed: t.DownloadSpeed,
ETA: eta,
})
}
}
return tasks, data.ServerState.DownloadRate, nil
}
type QbitTorrentProperties ¶
type QbitTorrentProperties struct {
SavePath string `json:"save_path"`
CreationDate int64 `json:"creation_date"`
PieceSize int64 `json:"piece_size"`
Comment string `json:"comment"`
TotalWasted int64 `json:"total_wasted"`
TotalUploaded int64 `json:"total_uploaded"`
TotalUploadedSession int64 `json:"total_uploaded_session"`
TotalDownloaded int64 `json:"total_downloaded"`
TotalDownloadedSession int64 `json:"total_downloaded_session"`
UploadLimit int64 `json:"up_limit"`
DownloadLimit int64 `json:"dl_limit"`
TimeElapsed int64 `json:"time_elapsed"`
SeedingTime int64 `json:"seeding_time"`
NumConnections int `json:"nb_connections"`
NumConnectionsLimit int `json:"nb_connections_limit"`
AdditionDate int64 `json:"addition_date"`
CompletionDate int64 `json:"completion_date"`
CreatedBy string `json:"created_by"`
AverageDownloadSpeed int64 `json:"dl_speed_avg"`
DownloadSpeed int64 `json:"dl_speed"`
ETA int64 `json:"eta"`
LastSeen int64 `json:"last_seen"`
Peers int `json:"peers"`
PeersTotal int `json:"peers_total"`
PiecesHave int `json:"pieces_have"`
PiecesNum int `json:"pieces_num"`
Reannounce int64 `json:"reannounce"`
Seeds int `json:"seeds"`
SeedsTotal int `json:"seeds_total"`
TotalSize int64 `json:"total_size"`
AverageUploadSpeed int64 `json:"up_speed_avg"`
UploadSpeed int64 `json:"up_speed"`
IsPrivate bool `json:"isPrivate"`
}
Click to show internal directories.
Click to hide internal directories.