Раскладка файлов после распознавния

This commit is contained in:
2026-06-14 14:53:40 +03:00
parent 91c501624a
commit 9c1b178e46
19 changed files with 3001 additions and 38 deletions
+30
View File
@@ -54,6 +54,13 @@ type Torrent struct {
InfohashV2 string `json:"infohash_v2"`
}
// File — элемент /torrents/files: путь файла относительно content_path и
// его размер.
type File struct {
Name string `json:"name"`
Size int64 `json:"size"`
}
// AddRequest — параметры добавления торрента.
type AddRequest struct {
URLs []string // magnet/URL-ссылки
@@ -217,3 +224,26 @@ func (c *Client) Torrents(ctx context.Context, category string) ([]Torrent, erro
}
return ts, nil
}
// Files возвращает список файлов торрента (имена относительно content_path и
// размеры). Нужен распознаванию как один из сигналов.
func (c *Client) Files(ctx context.Context, hash string) ([]File, error) {
resp, err := c.do(ctx, func() (*http.Request, error) {
u := c.endpoint("/api/v2/torrents/files?hash=" + url.QueryEscape(hash))
return http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
})
if err != nil {
return nil, fmt.Errorf("qbittorrent files: %w", err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<10))
return nil, fmt.Errorf("qbittorrent files: status %d body %q",
resp.StatusCode, strings.TrimSpace(string(body)))
}
var fs []File
if err := json.NewDecoder(resp.Body).Decode(&fs); err != nil {
return nil, fmt.Errorf("decode qbittorrent files: %w", err)
}
return fs, nil
}