Skip to content

Instantly share code, notes, and snippets.

@l1pz
Created April 3, 2020 13:00
Show Gist options
  • Save l1pz/a79f22b06f4b5e31ec03cbead385e2f9 to your computer and use it in GitHub Desktop.
Save l1pz/a79f22b06f4b5e31ec03cbead385e2f9 to your computer and use it in GitHub Desktop.
qBittorrent - download next torrent after the recent one finished moving
#!/usr/bin/env python3
import requests
import json
import random
authUrl = 'http://yourwebuiurl/api/v2/auth/'
torrentsUrl = 'http://yourwebuiurl/api/v2/torrents/'
cookies = {'SID': 'nologin'}
def login():
method = 'login'
credentials = {
'username': 'username',
'password': 'password$'
}
request = requests.post(authUrl+method, data=credentials)
cookies['SID'] = request.cookies['SID']
def getList():
method = 'info'
request = requests.post(torrentsUrl+method, cookies=cookies)
return json.loads(request.text)
def filterList(list, criteria):
return [t for t in list if t['state'] == criteria]
def startRandomTorrent(list):
method = 'resume'
randomTorrent = random.choice(list)
print(randomTorrent['name'], randomTorrent['hash'])
hashes = {'hashes': randomTorrent['hash']}
requests.post(torrentsUrl+method, data=hashes, cookies=cookies)
def main():
login()
torrentList = getList()
if len(filterList(torrentList, 'moving')) == 0:
startRandomTorrent(filterList(torrentList, 'pausedDL'))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment