Skip to content

Instantly share code, notes, and snippets.

@oltodosel
Created November 27, 2019 16:26
Show Gist options
  • Save oltodosel/566e051191f3a58b905db2cc6980656f to your computer and use it in GitHub Desktop.
Save oltodosel/566e051191f3a58b905db2cc6980656f to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import json
import requests
import os
import time
# plugin for qBittorrent to filter out files in torrents by name or extension
# Enable web-interface.
# Check "Bypass authentication for localhost"
url = 'http://127.0.0.1:8080/'
torrent_hashes = '''
65c5d8a71a7b824acf39232f8068647cdaaff159
6b887370d8b52925d436d1bfec040df84c8dd645
'''
# ignorecase
block_extensions = ['psd']
# ignorecase # not in dir names
block_words_in_filenames = []
########################################################
if url[-1] != '/':
url += '/'
for torrent_hash in [ x.strip() for x in torrent_hashes.split('\n') if len(x.strip()) != 0 ]:
data = requests.get(url + 'api/v2/torrents/files?hash=%s' % torrent_hash).text
data = json.loads(data)
for file_id, file_data in enumerate(data):
for ext in block_extensions:
if file_data['name'].lower()[-len(ext):] == ext.lower():
print(file_data['name'])
r = requests.post(url + 'api/v2/torrents/filePrio',
data = {'hash' : torrent_hash, 'id' : str(file_id), 'priority' : '0'})
# without pauses qBittorent can choke on requests
time.sleep(0.05)
for word in block_words_in_filenames:
if word.lower() in file_data['name'].rsplit('/', 1)[1].lower():
print(file_data['name'])
r = requests.post(url + 'api/v2/torrents/filePrio',
data = {'hash' : torrent_hash, 'id' : str(file_id), 'priority' : '0'})
# without pauses qBittorent can choke on requests
time.sleep(0.05)
@talanov
Copy link

talanov commented Aug 6, 2023

Hey, for those who still need it: I've made some updates to the script, including automatically fetching the torrent list and some other QoL improvements: https://gist.github.com/talanov/29bacef1ba1cb7aa89caa4c0bc9cb9bd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment