Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add recheck command #93

Merged
merged 7 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
69 changes: 69 additions & 0 deletions cmd/torrent_recheck.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading