Created
November 27, 2019 16:22
-
-
Save oltodosel/469a594190f57cf6af8b14c9e9865c12 to your computer and use it in GitHub Desktop.
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 python | |
import json | |
import requests | |
import os | |
# plugin for qBittorrent | |
# Enable web-interface. | |
# Check "Bypass authentication for localhost" | |
# cron | |
# */10 * * * * python3 ~/.scripts/qbittorrent_plugin.py | |
url = 'http://127.0.0.1:8080/' | |
# assign Uncategorized torrents with matching trackers to category | |
category_tracker = { | |
'pornlab': 'plab.site', | |
} | |
# stop seeding torrents exceeding ratio in category | |
category_stop_ratio = { | |
'pornlab' : 10, | |
'SnR' : 20, | |
} | |
# change category of torrents exceeding ratio in category | |
category_change_at_ratio = { | |
'pornlab' : ( 10, '1111' ) | |
} | |
# remove downloaded torrents exceeding ratio in category (files remain) | |
category_rm_ratio = { | |
'.doc' : 6, | |
'1111' : 0.01, | |
} | |
######################################################## | |
if url[-1] != '/': | |
url += '/' | |
data = requests.get(url + 'api/v2/sync/maindata').text | |
data = json.loads(data) | |
for torrent_id in data['torrents']: | |
for category, tracker in category_tracker.items(): | |
if tracker in data['torrents'][torrent_id]['tracker'] and \ | |
data['torrents'][torrent_id]['category'] == '': | |
r = requests.post(url + 'api/v2/torrents/setCategory', | |
data = {'category' : category, 'hashes' : torrent_id}) | |
for category, ratio in category_stop_ratio.items(): | |
if data['torrents'][torrent_id]['category'] == category and \ | |
float(data['torrents'][torrent_id]['ratio']) > ratio and \ | |
data['torrents'][torrent_id]['completed'] == data['torrents'][torrent_id]['size']: | |
r = requests.post(url + 'api/v2/torrents/pause', | |
data = {'hashes' : torrent_id}) | |
for category, ratio_category in category_change_at_ratio.items(): | |
if data['torrents'][torrent_id]['category'] == category and \ | |
float(data['torrents'][torrent_id]['ratio']) > ratio_category[0] and \ | |
data['torrents'][torrent_id]['completed'] == data['torrents'][torrent_id]['size']: | |
r = requests.post(url + 'api/v2/torrents/setCategory', | |
data = {'hashes' : torrent_id, 'category' : ratio_category[1]}) | |
for category, ratio in category_rm_ratio.items(): | |
if data['torrents'][torrent_id]['category'] == category and \ | |
float(data['torrents'][torrent_id]['ratio']) > ratio and \ | |
data['torrents'][torrent_id]['completed'] == data['torrents'][torrent_id]['size']: | |
r = requests.post(url + 'api/v2/torrents/delete', | |
data = {'deleteFiles' : 'false', 'hashes' : torrent_id}) | |
category_rm_ratio_bool = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment