Created
April 3, 2020 13:00
-
-
Save l1pz/a79f22b06f4b5e31ec03cbead385e2f9 to your computer and use it in GitHub Desktop.
qBittorrent - download next torrent after the recent one finished moving
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
#!/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