-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Feature: add torrent selection for Pause & Resume commands #33
Feature: add torrent selection for Pause & Resume commands #33
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! But i do see one problem tho. The pause and resume previously used the "all" flag but with the refactor it does not. There's limits on how much you can send to the api - so say you have 1000+ torrents running then that will be a lot of hashes in one go and it will probably fail.
This is true for all methods touching all.
The "all" param is a built in feature of the qbit api where it handles the ids on the backend instead of sending all the ids.
I have implemented a batch function in another repo that mitigates this. I'll share that during the day so you can implement it where necessary 🙂
Turns out the batch function was in this repo all along 🙈 Check this: https://github.com/ludviglundgren/qbittorrent-cli/blob/develop/cmd/compare.go#L106-L121 // Split the slice into batches of 20 items.
batch := 20
for i := 0; i < len(duplicateTorrents); i += batch {
j := i + batch
if j > len(duplicateTorrents) {
j = len(duplicateTorrents)
}
qbCompare.SetTag(duplicateTorrents[i:j], "duplicate")
// sleep before next request
time.Sleep(time.Second * 1)
} This grabs 20 items and runs the setTag in this case. And adds a sleep to be a bit nicer to qbit and not hammer it too hard. Could probably be lowered to 500ms as well but this gives some margin. It will take some time to run on 1000+ torrents but rather that than breaking things. |
I've added the batching technique to all the commands, used the "all" endpoint for pause/resume/remove when applicable (when user uses I repeated the batching loop for all three commands and contemplated making some sort of batching method with a function pointer to use for the request, but I restrained myself lol. Let me know what you think! +squashed commits |
8caeb76
to
052ab0d
Compare
Awesome! 😄 Hehe yeah, sure that would be nice but a some copying is better than over-engineering 😄 Do you have more changes in mind in other PRs, or can I go ahead and release this? |
You can go ahead and release this! 😄 |
Great! If you're interested in other tools related to qbit and torrents, my other project is autobrr. We have a growing Discord server that you're more than welcome to join 🙂 |
Sorry to ask in old thread, but im trying to pause via name but it always fails, even tho its the whole name. How should this be used? Hashes works, the whole hash, would be nice to have like a minimum of 5 (?!) letters/numbers? |
Added the same functionality from newly merged Remove command to Pause & Resume commands.
Same
--hashes --names --all
flags added to both Pause & Resume.Also did a bit of refactoring of the code to search for torrents using name or hash prefixes, and made it into a method for the qbittorrent client in
methods.go
to be universally used on all of the commands mentioned.GetTorrentsByPrefixes
accepts a string list of terms to search for, and boolean flags to check against either hashes, names, or both.( I intend to add categories + tags into these commands with separate functions later :) )