Allow multiple categories

This commit is contained in:
Jon 2021-09-26 16:23:50 -04:00
parent 2a6f3b2ed2
commit 2df0bf441d
No known key found for this signature in database
GPG key ID: 9665BA6CF5DC2671
2 changed files with 52 additions and 42 deletions

View file

@ -38,11 +38,18 @@ tags:
#Tag Movies/Series that are not hard linked
nohardlinks:
# Mandatory Movie/Series Variable required to use this function
# Mandatory to fill out directory parameter above to use this function (root_dir/remote_dir)
Movie:
#Mandatory category var: Category name of your completed-movies in qbit
category: movies-completed
# This variable should be set to your category name of your completed movies/completed series in qbit. Acceptable variable can be any category you would like to tag if there are no hardlinks found
movies-completed:
#<OPTIONAL> cleanup var: WARNING!! Setting this as true Will remove and delete contents of any torrents that are in paused state and has the NoHL tag
cleanup: false
#<OPTIONAL> max_ratio var: Will set the torrent Maximum share ratio until torrent is stopped from seeding/uploading
max_ratio: 4.0
#<OPTIONAL> seeding time var: Will set the torrent Maximum seeding time (min) until torrent is stopped from seeding
max_seeding_time: 86400
#Can have additional categories set with separate ratio/seeding times defined.
series-completed:
#<OPTIONAL> cleanup var: WARNING!! Setting this as true Will remove and delete contents of any torrents that are in paused state and has the NoHL tag
cleanup: false
#<OPTIONAL> max_ratio var: Will set the torrent Maximum share ratio until torrent is stopped from seeding/uploading

View file

@ -485,15 +485,16 @@ def tag_nohardlinks():
else:
remote_path = root_path
if 'Movie' in nohardlinks:
for category in nohardlinks:
t_count = 0 #counter for the number of torrents that has no hard links
t_del = 0 #counter for the number of torrents that has no hard links and meets the criteria for ratio limit/seed limit for deletion
t_del_cs = 0 #counter for the number of torrents that has no hard links and meets the criteria for ratio limit/seed limit for deletion including cross-seeds
n_info = ''
tdel_dict = {} #dictionary to track the torrent names and content path that meet the deletion criteria
if 'category' not in nohardlinks['Movie']:
logger.error('category not defined in config inside the nohardlinks/Movies variable. Please make sure to fill out category in nohardlinks Movie section.')
torrent_list = client.torrents.info(category=nohardlinks['Movie']['category'],filter='completed')
torrent_list = client.torrents.info(category=category,filter='completed')
if len(torrent_list) == 0:
logger.error('The category ('+category+') defined in config.yml inside the nohardlinks section does not match any category in qbittorrent. Please make sure the category defined in config matches with one in qbittorrent.')
continue
for torrent in torrent_list:
if args.dry_run != 'dry_run':
torrent.resume()
@ -505,17 +506,21 @@ def tag_nohardlinks():
t_count += 1
n_info += (f'\n - Torrent Name: {torrent.name} has no hard links found.')
n_info += (' Adding tags noHL.')
#set the max seeding time for the torrent
if ('max_seeding_time' in nohardlinks['Movie']):
seeding_time_limit = nohardlinks['Movie']['max_seeding_time']
n_info += (' \n Setting max seed time to ' + str(seeding_time_limit) + '.')
if(nohardlinks[category] != None):
#set the max seeding time for the torrent
if ('max_seeding_time' in nohardlinks[category]):
seeding_time_limit = nohardlinks[category]['max_seeding_time']
n_info += (' \n Setting max seed time to ' + str(seeding_time_limit) + '.')
else:
seeding_time_limit = -2
#set the max ratio for the torrent
if ('max_ratio' in nohardlinks[category]):
ratio_limit = nohardlinks[category]['max_ratio']
n_info += (' \n Setting max ratio to ' + str(ratio_limit)+ '.')
else:
ratio_limit = -2
else:
seeding_time_limit = -2
#set the max ratio for the torrent
if ('max_ratio' in nohardlinks['Movie']):
ratio_limit = nohardlinks['Movie']['max_ratio']
n_info += (' \n Setting max ratio to ' + str(ratio_limit)+ '.')
else:
ratio_limit = -2
if args.dry_run != 'dry_run':
#set the tag for no hard links
@ -524,29 +529,30 @@ def tag_nohardlinks():
#Cleans up previously tagged noHL torrents
else:
# Deletes torrent with data if cleanup is set to true and meets the ratio/seeding requirements
if ('cleanup' in nohardlinks['Movie'] and nohardlinks['Movie']['cleanup'] and torrent.state_enum.is_paused):
t_del += 1
n_info += (f'\n - Torrent Name: {torrent.name} has no hard links found and meets ratio/seeding requirements.')
tdel_dict[torrent.name] = torrent['content_path'].replace(root_path,remote_path)
if args.dry_run == 'dry_run':
n_info += (' \n Cleanup flag set to true. NOT Deleting torrent + contents.')
else:
n_info += (' \n Cleanup flag set to true. Deleting torrent + contents.')
#loop through torrent list again for cleanup purposes
if ('cleanup' in nohardlinks['Movie'] and nohardlinks['Movie']['cleanup']):
for torrent in torrent_list:
if torrent.name in tdel_dict.keys() and 'noHL' in torrent.tags:
#Double check that the content path is the same before we delete anything
if torrent['content_path'].replace(root_path,remote_path) == tdel_dict[torrent.name]:
t_del_cs += 1
if args.dry_run != 'dry_run':
if (os.path.exists(torrent['content_path'].replace(root_path,remote_path))):
torrent.delete(hash=torrent.hash, delete_files=True)
if(nohardlinks[category] != None):
# Deletes torrent with data if cleanup is set to true and meets the ratio/seeding requirements
if ('cleanup' in nohardlinks[category] and nohardlinks[category]['cleanup'] and torrent.state_enum.is_paused and len(nohardlinks[category])>0):
t_del += 1
n_info += (f'\n - Torrent Name: {torrent.name} has no hard links found and meets ratio/seeding requirements.')
tdel_dict[torrent.name] = torrent['content_path'].replace(root_path,remote_path)
if args.dry_run == 'dry_run':
n_info += (' \n Cleanup flag set to true. NOT Deleting torrent + contents.')
else:
torrent.delete(hash=torrent.hash, delete_files=False)
n_info += (' \n Cleanup flag set to true. Deleting torrent + contents.')
if(nohardlinks[category] != None):
#loop through torrent list again for cleanup purposes
if ('cleanup' in nohardlinks[category] and nohardlinks[category]['cleanup']):
for torrent in torrent_list:
if torrent.name in tdel_dict.keys() and 'noHL' in torrent.tags:
#Double check that the content path is the same before we delete anything
if torrent['content_path'].replace(root_path,remote_path) == tdel_dict[torrent.name]:
t_del_cs += 1
if args.dry_run != 'dry_run':
if (os.path.exists(torrent['content_path'].replace(root_path,remote_path))):
torrent.delete(hash=torrent.hash, delete_files=True)
else:
torrent.delete(hash=torrent.hash, delete_files=False)
#Checks to see if previous noHL tagged torrents now have hard links.
@ -579,9 +585,6 @@ def tag_nohardlinks():
else:
logger.info('No torrents to tag with no hard links.')
if 'Series' in nohardlinks:
print ('Not yet implemented')
#will check if there are any hard links if it passes a file or folder
def nohardlink(file):