Skip to content

Commit

Permalink
add support for qb sequentialDownload flag when adding new torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
sagan committed Feb 14, 2024
1 parent bf1eea3 commit 0d04736
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type TorrentOption struct {
SkipChecking bool
Pause bool
Resume bool // use only in ModifyTorrent, to start a paused torrent
SequentialDownload bool // qb only
}

type TorrentCategory struct {
Expand Down
6 changes: 6 additions & 0 deletions client/qbittorrent/qbittorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func (qbclient *Client) AddTorrent(torrentContent []byte, option *client.Torrent
if option.SkipChecking {
mp.WriteField("skip_checking", "true")
}
if option.SequentialDownload {
mp.WriteField("sequentialDownload", "true")
}
}
resp, err := qbclient.HttpClient.Post(qbclient.ClientConfig.Url+"api/v2/torrents/add",
mp.FormDataContentType(), body)
Expand Down Expand Up @@ -514,6 +517,9 @@ func (qbclient *Client) ModifyTorrent(infoHash string,
}
}

// @todo: apply option.SequentialDownload using qb toggleSequentialDownload.
// However, we must know current sequentialDownload status in ahead.

if option.Category != "" && option.Category != qbtorrent.Category {
data := url.Values{
"hashes": {infoHash},
Expand Down
27 changes: 16 additions & 11 deletions cmd/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ var command = &cobra.Command{
}

var (
addCategoryAuto = false
addPaused = false
skipCheck = false
addCategory = ""
defaultSite = ""
addTags = ""
savePath = ""
addCategoryAuto = false
addPaused = false
skipCheck = false
sequentialDownload = false
addCategory = ""
defaultSite = ""
addTags = ""
savePath = ""
)

func init() {
command.Flags().BoolVarP(&skipCheck, "skip-check", "", false, "Skip hash checking when adding torrents")
command.Flags().BoolVarP(&addPaused, "add-paused", "", false, "Add torrents to client in paused state")
command.Flags().BoolVarP(&addCategoryAuto, "add-category-auto", "", false, "Automatically set category of added torrent to corresponding sitename")
command.Flags().BoolVarP(&addCategoryAuto, "add-category-auto", "", false,
"Automatically set category of added torrent to corresponding sitename")
command.Flags().BoolVarP(&sequentialDownload, "sequential-download", "", false,
"(qbittorrent only) Enable sequential download")
command.Flags().StringVarP(&addCategory, "add-category", "", "", "Set category of added torrents")
command.Flags().StringVarP(&savePath, "add-save-path", "", "", "Set save path of added torrents")
command.Flags().StringVarP(&defaultSite, "site", "", "", "Set default site of torrents")
Expand All @@ -58,9 +62,10 @@ func add(cmd *cobra.Command, args []string) error {
siteInstanceMap := map[string]site.Site{}
errorCnt := int64(0)
option := &client.TorrentOption{
Pause: addPaused,
SavePath: savePath,
SkipChecking: skipCheck,
Pause: addPaused,
SavePath: savePath,
SkipChecking: skipCheck,
SequentialDownload: sequentialDownload,
}
var fixedTags []string
if addTags != "" {
Expand Down
38 changes: 22 additions & 16 deletions cmd/addlocal/addlocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@ It's possible to use "*" wildcard in filename to match multiple torrents. e.g.:
}

var (
paused = false
skipCheck = false
renameAdded = false
deleteAdded = false
addCategoryAuto = false
defaultSite = ""
rename = ""
addCategory = ""
addTags = ""
savePath = ""
paused = false
skipCheck = false
renameAdded = false
deleteAdded = false
addCategoryAuto = false
sequentialDownload = false
defaultSite = ""
rename = ""
addCategory = ""
addTags = ""
savePath = ""
)

func init() {
command.Flags().BoolVarP(&skipCheck, "skip-check", "", false, "Skip hash checking when adding torrents")
command.Flags().BoolVarP(&renameAdded, "rename-added", "", false, "Rename successfully added torrents to .added extension")
command.Flags().BoolVarP(&renameAdded, "rename-added", "", false,
"Rename successfully added torrents to .added extension")
command.Flags().BoolVarP(&deleteAdded, "delete-added", "", false, "Delete successfully added torrents")
command.Flags().BoolVarP(&paused, "add-paused", "", false, "Add torrents to client in paused state")
command.Flags().BoolVarP(&addCategoryAuto, "add-category-auto", "", false, "Automatically set category of added torrent to corresponding sitename")
command.Flags().BoolVarP(&addCategoryAuto, "add-category-auto", "", false,
"Automatically set category of added torrent to corresponding sitename")
command.Flags().BoolVarP(&sequentialDownload, "sequential-download", "", false,
"(qbittorrent only) Enable sequential download")
command.Flags().StringVarP(&savePath, "add-save-path", "", "", "Set save path of added torrents")
command.Flags().StringVarP(&defaultSite, "site", "", "", "Set default site of torrents")
command.Flags().StringVarP(&addCategory, "add-category", "", "", "Manually set category of added torrents")
Expand All @@ -73,10 +78,11 @@ func addlocal(cmd *cobra.Command, args []string) error {
return fmt.Errorf("--rename flag can only be used with exact one torrent file arg")
}
option := &client.TorrentOption{
Pause: paused,
SavePath: savePath,
SkipChecking: skipCheck,
Name: rename,
Pause: paused,
SavePath: savePath,
SkipChecking: skipCheck,
SequentialDownload: sequentialDownload,
Name: rename,
}
var fixedTags []string
if addTags != "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var pureFlags = []string{
"raw",
"rename-added",
"one-page",
"sequential-download",
"show-files",
"show-info-hash-only",
"show-names-only",
Expand Down

0 comments on commit 0d04736

Please sign in to comment.