diff --git a/README.md b/README.md index 0af1f39..fa3abbe 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ A cli to manage qBittorrent. Add torrents, categories, tags, reannounce and impo * [List](#list-2) * [Pause](#pause) * [Reannounce](#reannounce) + * [Recheck](#recheck) * [Remove](#remove) * [Resume](#resume) * [Tracker](#tracker) @@ -806,6 +807,27 @@ Global Flags: --config string config file (default is $HOME/.config/qbt/.qbt.toml) ``` +### Recheck + +```text +Rechecks torrents indicated by hash(es). + +Usage: + qbt torrent recheck [flags] + +Examples: + qbt torrent recheck --hashes HASH + qbt torrent recheck --hashes HASH1,HASH2 + + +Flags: + --hashes strings Add hashes as comma separated list + -h, --help help for recheck + +Global Flags: + --config string config file (default is $HOME/.config/qbt/.qbt.toml) +``` + ### Remove ```text diff --git a/cmd/torrent.go b/cmd/torrent.go index cb5c656..a85f50a 100644 --- a/cmd/torrent.go +++ b/cmd/torrent.go @@ -21,6 +21,7 @@ func RunTorrent() *cobra.Command { command.AddCommand(RunTorrentList()) command.AddCommand(RunTorrentPause()) command.AddCommand(RunTorrentReannounce()) + command.AddCommand(RunTorrentRecheck()) command.AddCommand(RunTorrentRemove()) command.AddCommand(RunTorrentResume()) command.AddCommand(RunTorrentTracker()) diff --git a/cmd/torrent_recheck.go b/cmd/torrent_recheck.go new file mode 100644 index 0000000..82b23c8 --- /dev/null +++ b/cmd/torrent_recheck.go @@ -0,0 +1,69 @@ +package cmd + +import ( + "fmt" + "log" + "os" + + "github.com/ludviglundgren/qbittorrent-cli/internal/config" + + "github.com/autobrr/go-qbittorrent" + "github.com/spf13/cobra" +) + +// RunTorrentRecheck cmd to recheck torrents +func RunTorrentRecheck() *cobra.Command { + var ( + hashes []string + ) + + var command = &cobra.Command{ + Use: "recheck", + Short: "Recheck specified torrent(s)", + Long: `Rechecks torrents indicated by hash(es).`, + Example: ` qbt torrent recheck --hashes HASH + qbt torrent recheck --hashes HASH1,HASH2 +`, + } + + command.Flags().StringSliceVar(&hashes, "hashes", []string{}, "Add hashes as comma separated list") + + command.Run = func(cmd *cobra.Command, args []string) { + if len(hashes) == 0 { + log.Println("No torrents found to recheck") + return + } + + config.InitConfig() + + qbtSettings := qbittorrent.Config{ + Host: config.Qbit.Addr, + Username: config.Qbit.Login, + Password: config.Qbit.Password, + BasicUser: config.Qbit.BasicUser, + BasicPass: config.Qbit.BasicPass, + } + + qb := qbittorrent.NewClient(qbtSettings) + + ctx := cmd.Context() + + if err := qb.LoginCtx(ctx); err != nil { + fmt.Fprintf(os.Stderr, "connection failed: %v\n", err) + os.Exit(1) + } + + err := batchRequests(hashes, func(start, end int) error { + return qb.RecheckCtx(ctx, hashes[start:end]) + }) + if err != nil { + fmt.Fprintf(os.Stderr, "ERROR: could not recheck torrents: %v\n", err) + os.Exit(1) + return + } + + log.Printf("torrent(s) successfully recheckd") + } + + return command +}