Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib3
- import json
- rule = {}
- def addRule(a,b,c,d,e):
- rule.update({a: {'SeedTime': b, 'Ratio': c, 'DeleteFiles': d, 'Match': e}})
- ############################################################################################
- # Note: This script works locally on host machine in conjunction with qBittorrent WebUI to remove torrents from
- # specific categories that match the set rules. Make sure "Bypass authentication" in qBittorrent settings is enabled for script to work.
- #
- # **EXAMPLE RULE**
- # Category = 'Test_2' <----- # Category name in qBittorrent. If you are using subcategories, use 'CategoryName/SubCategoryName'
- # SeedTime = 168*60*60 <---- (168Hours)*60*60 - Torrent will be removed when this many seconds of active seed time is reached
- # Ratio = '999.99' <-------- Torrent will be removed when this number is reached
- # DeleteFiles = 'True' <---- (True | False) Set to remove or keep files on torrent removal
- # Match = '1' <------------ '1': Match SeedTime & Ratio | '2': Match SeedTime | '3': Match Ratio | '4': Match either one
- # addRule(Category,SeedTime,Ratio,DeleteFiles,Match) <-----Keep this line the sam
- ############################################################################################
- ############################################################################################
- #EDIT BELOW THIS LINE - COPY EXAMPLE RULES AND CREATE YOUR OWN. EDIT TO YOUR LIKING
- ############################################################################################
- url = "http://localhost:8080" #url to qBittorrent WebUI
- #Make sure the rules are set to your liking before turning off testMode to prevent accidently deleting files.
- testMode = 'on' # 'off' | 'on' :Takes action if 'off', shows what would happen if 'on'. Default: on
- ############################################################################################
- Category = 'Example 1' # If you are using subcategories, use 'CategoryName/SubCategoryName'
- SeedTime = 24*60*60 # (Measured in seconds) Change first number to change amount of hours (24*60*60 = 24Hours)
- Ratio = '2.00'
- DeleteFiles = 'False' # 'True' | 'False' :Delete files when rule is matched
- Match = '1' # '1': Match SeedTime & Ratio | '2': Match SeedTime | '3': Match Ratio | '4': Match either one
- addRule(Category,SeedTime,Ratio,DeleteFiles,Match) #Don't edit this line but be sure to include it when making new rules
- Category = 'Example 2'
- SeedTime = 24*60*60
- Ratio = '2.00'
- DeleteFiles = 'False'
- Match = '1'
- addRule(Category,SeedTime,Ratio,DeleteFiles,Match)
- Category = 'Example 3'
- SeedTime = 24*60*60
- Ratio = '2.00'
- DeleteFiles = 'False'
- Match = '1'
- addRule(Category,SeedTime,Ratio,DeleteFiles,Match)
- # Nothing further below needs to be edited
- ############################################################################################
- # Cheat Sheet (Days|Hours)
- # 1|24, 2|48, 3|72, 4|96, 5|120, 6|144, 7|168, ... 14|336, 21|504, 28|672
- ############################################################################################
- ############################################################################################
- def grabTorrents():
- global torrents
- http = urllib3.PoolManager()
- r = http.request('GET', url+'/api/v2/torrents/info', fields={'filter': 'all'})
- r.close()
- torrents = json.loads(r.data.decode('utf-8'))
- def hashGrab(hash):
- global hashinfo
- http = urllib3.PoolManager()
- r = http.request('GET', url + '/api/v2/torrents/properties', fields={'hash': hash})
- r.close()
- hashinfo = json.loads(r.data.decode('utf-8'))
- return hashinfo
- def grabCategory(data):
- output = []
- for i in range(len(torrents)):
- if (torrents[i].get('category'))==data:
- output.append(torrents[i])
- return (output)
- def removeTorrent(hash,deleteFiles):
- http = urllib3.PoolManager()
- r = http.request('GET', url + '/api/v2/torrents/delete', fields={'hashes': hash,'deleteFiles': deleteFiles})
- r.close()
- def checkRules():
- for i in rule:
- for rulematch in grabCategory(i):
- hash = (rulematch.get('hash'))
- ratio = str(rulematch.get('ratio'))
- ratio = float((str(ratio)[:4]))
- name = (rulematch.get('name'))
- seedingtime = (hashGrab(hash).get('seeding_time'))
- rRatio = (float(rule.get(i).get('Ratio')))
- rSeedTime = (rule.get(i).get('SeedTime'))
- rDeleteFiles = (rule.get(i).get('DeleteFiles'))
- rMatch = (rule.get(i).get('Match'))
- if ratio > rRatio:
- ratiomatch = True
- else:
- ratiomatch = False
- if seedingtime > rSeedTime:
- seedmatch = True
- else:
- seedmatch = False
- if rMatch == '1': # '1': Match SeedTime & Ratio
- if seedmatch == True and ratiomatch == True:
- if testMode == 'off':
- removeTorrent(hash, rDeleteFiles)
- else:
- print ('Category: '+i+' | '+'Match = '+rMatch+' | Match SeedTime & Ratio\n'+'Removing torrent | Delete files = '+rDeleteFiles)
- print ('Torrent Name: '+name+'\nTime Seeded: '+str(seedingtime)+' / '+str(rSeedTime)+'\nRatio: '+str(ratio)+' / '+str(rRatio))
- print ('_____________________________________________________________________')
- elif rMatch == '2': # '2': Match SeedTime
- if seedmatch == True:
- if testMode == 'off':
- removeTorrent(hash, rDeleteFiles)
- elif testMode == 'on':
- print ('Category: '+i+' | '+'Match = '+rMatch+' | Match SeedTime\n'+'Removing torrent | Delete files = '+rDeleteFiles)
- print ('Torrent Name: '+name+'\nTime Seeded: '+str(seedingtime)+' / '+str(rSeedTime)+'\nRatio: '+str(ratio)+' / '+str(rRatio))
- print ('_____________________________________________________________________')
- elif rMatch == '3': # '3': Match Ratio
- if ratiomatch == True:
- if testMode == 'off':
- removeTorrent(hash, rDeleteFiles)
- else:
- print ('Category: '+i+' | '+'Match = '+rMatch+' | Match Ratio\n'+'Removing torrent | Delete files = '+rDeleteFiles)
- print ('Torrent Name: '+name+'\nTime Seeded: '+str(seedingtime)+' / '+str(rSeedTime)+'\nRatio: '+str(ratio)+' / '+str(rRatio))
- print ('_____________________________________________________________________')
- elif rMatch == '4': # '4': Match either one
- if ratiomatch == True or seedmatch == True:
- if testMode == 'off':
- removeTorrent(hash, rDeleteFiles)
- else:
- print ('Category: '+i+' | '+'Match = '+rMatch+' | Match SeedTime or Ratio\n'+'Removing torrent | Delete files = '+rDeleteFiles)
- print ('Torrent Name: '+name+'\nTime Seeded: '+str(seedingtime)+' / '+str(rSeedTime)+'\nRatio: '+str(ratio)+' / '+str(rRatio))
- print ('_____________________________________________________________________')
- def TestModePause():
- if testMode=='on':
- import sys
- v = (sys.version_info[0])
- if (v==2):
- print("\nTest Mode Enabled: PAUSING | No actions taken")
- raw_input('...Press ENTER to continue')
- elif v==3:
- print("\nTest Mode Enabled: PAUSING | No actions taken")
- input('...Press any key to continue')
- grabTorrents()
- checkRules()
- TestModePause()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement