Skip to content

Commit

Permalink
feat: add recheck command (#93)
Browse files Browse the repository at this point in the history
* feat: add recheck command

* check if file exists before globbing

fixes #89

* fix: revert changes on torrent_add

* fix: command helper text

* docs: add recheck command

---------

Co-authored-by: Ludvig Lundgren <[email protected]>
  • Loading branch information
aca and ludviglundgren authored Aug 19, 2024
1 parent 81a4c06 commit 19bd729
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
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
}

0 comments on commit 19bd729

Please sign in to comment.