Skip to content

Commit

Permalink
Merge pull request #1 from LedyBacer/main
Browse files Browse the repository at this point in the history
feat: add feature for pause/resume torrents
  • Loading branch information
uraid authored Dec 31, 2023
2 parents 6c92fb1 + be2101e commit cfb73aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ Set Download/Upload limit in KB/s. Set `-1` for unlimited
- Playback Start: `-D 1024 -U 1024`
- Playback Stop: `-D -1 -U -1`

### Stop all torrents
**Triggers:**
- Playback Start
- Playback Stop

**Arguments:**
- Playback Start: `--stop`
- Playback Stop: `--start`

### Verify this setting is enabled
`Settings -> Notifications & Newsletters -> (Show Advanced) Allow Playback Stop Notifications Exceeding Watched Percent.`

Expand Down
36 changes: 29 additions & 7 deletions qbitorrent_throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,45 @@ def throttle_upload(self, rate):

self.log_msg("[+] Sucessfully set max upload rate")
return True

def pause_all_torrents(self):
self.qbt_client.torrents_pause(torrent_hashes='all')
self.log_msg("[+] All torrents paused")
return True

def resume_all_torrents(self):
self.qbt_client.torrents_resume(torrent_hashes='all')
self.log_msg("[+] All torrents resumed")
return True

def main():
parser = argparse.ArgumentParser()
parser.add_argument("-D", "--maxdownload", type=int, required=True, help="Set max download speed [KBs]")
parser.add_argument("-U", "--maxupload", type=int, required=True, help="Set max upload speed [KBs]")
parser.add_argument("-D", "--maxdownload", type=int, required=False, help="Set max download speed [KBs]")
parser.add_argument("-U", "--maxupload", type=int, required=False, help="Set max upload speed [KBs]")
parser.add_argument("--stop", action='store_true', help="Stop all torrents")
parser.add_argument("--start", action='store_true', help="Start all torrents")

args = parser.parse_args()
throttle_obj = throttle()

if not throttle_obj.check_connection():
return False

if args.stop:
if not throttle_obj.pause_all_torrents():
return False

if not throttle_obj.throttle_download(args.maxdownload):
return False
if args.start:
if not throttle_obj.resume_all_torrents():
return False

if not throttle_obj.throttle_upload(args.maxupload):
return False
if args.maxdownload is not None:
if not throttle_obj.throttle_download(args.maxdownload):
return False

if args.maxupload is not None:
if not throttle_obj.throttle_upload(args.maxupload):
return False

if __name__ == "__main__":
main()
main()

0 comments on commit cfb73aa

Please sign in to comment.