-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
81a4c06
commit 19bd729
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |