mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-09 21:36:52 +08:00
Bug fix - rem_unregistered_torrents and recheck
- Checks to see if original torrent is completed in order to recheck - Checks to see if all duplicate torrents are not registered and will delete torrent and contents if true
This commit is contained in:
parent
16180d4ea9
commit
3f13a618ec
1 changed files with 32 additions and 14 deletions
|
@ -145,18 +145,26 @@ def get_tags(url):
|
||||||
|
|
||||||
|
|
||||||
# Will create a 2D Dictionary with the torrent name as the key
|
# Will create a 2D Dictionary with the torrent name as the key
|
||||||
# torrentdict = {'TorrentName1' : {'Category':'TV', 'save_path':'/data/torrents/TV'},
|
# torrentdict = {'TorrentName1' : {'Category':'TV', 'save_path':'/data/torrents/TV', 'count':1, 'msg':'[]'},
|
||||||
# 'TorrentName2' : {'Category':'Movies', 'save_path':'/data/torrents/Movies'}}
|
# 'TorrentName2' : {'Category':'Movies', 'save_path':'/data/torrents/Movies'}, 'count':2, 'msg':'[]'}
|
||||||
def get_torrent_info(t_list):
|
def get_torrent_info(t_list):
|
||||||
torrentdict = {}
|
torrentdict = {}
|
||||||
for torrent in t_list:
|
for torrent in t_list:
|
||||||
save_path = torrent.save_path
|
save_path = torrent.save_path
|
||||||
category = get_category(save_path)
|
category = get_category(save_path)
|
||||||
if torrent.name in torrentdict:
|
if torrent.name in torrentdict:
|
||||||
|
#Only count if original torrent is complete
|
||||||
|
if(torrent.state_enum.is_complete):
|
||||||
t_count = torrentdict[torrent.name]['count'] + 1
|
t_count = torrentdict[torrent.name]['count'] + 1
|
||||||
|
else:
|
||||||
|
t_count = torrentdict[torrent.name]['count']
|
||||||
|
msg_list = torrentdict[torrent.name]['msg']
|
||||||
else:
|
else:
|
||||||
t_count = 1
|
t_count = 1
|
||||||
torrentattr = {'Category': category, 'save_path': save_path, 'count': t_count}
|
msg_list = []
|
||||||
|
msg = [x.msg for x in torrent.trackers if x.url.startswith('http')][0]
|
||||||
|
msg_list.append(msg)
|
||||||
|
torrentattr = {'Category': category, 'save_path': save_path, 'count': t_count, 'msg': msg_list}
|
||||||
logger.debug(torrent.name, t_count)
|
logger.debug(torrent.name, t_count)
|
||||||
torrentdict[torrent.name] = torrentattr
|
torrentdict[torrent.name] = torrentattr
|
||||||
return torrentdict
|
return torrentdict
|
||||||
|
@ -170,7 +178,6 @@ def recheck():
|
||||||
#Tag the torrents
|
#Tag the torrents
|
||||||
new_tag = [get_tags(x.url) for x in torrent.trackers if x.url.startswith('http')]
|
new_tag = [get_tags(x.url) for x in torrent.trackers if x.url.startswith('http')]
|
||||||
torrent.add_tags(tags=new_tag)
|
torrent.add_tags(tags=new_tag)
|
||||||
#print(f'{torrent.hash[-6:]}: {torrent.name} ({torrent.state}) {torrent.progress}')
|
|
||||||
#Resume torrent if completed
|
#Resume torrent if completed
|
||||||
if torrent.progress == 1:
|
if torrent.progress == 1:
|
||||||
if args.dry_run == 'dry_run':
|
if args.dry_run == 'dry_run':
|
||||||
|
@ -200,7 +207,7 @@ def cross_seed():
|
||||||
dir_cs = os.path.join(cfg['directory']['cross_seed'], '')
|
dir_cs = os.path.join(cfg['directory']['cross_seed'], '')
|
||||||
dir_cs_out = os.path.join(dir_cs,'qbit_manage_added')
|
dir_cs_out = os.path.join(dir_cs,'qbit_manage_added')
|
||||||
os.makedirs(dir_cs_out,exist_ok=True)
|
os.makedirs(dir_cs_out,exist_ok=True)
|
||||||
torrent_list = client.torrents.info()
|
torrent_list = client.torrents.info(sort='added_on',reverse=True)
|
||||||
torrentdict = get_torrent_info(torrent_list)
|
torrentdict = get_torrent_info(torrent_list)
|
||||||
for file in cs_files:
|
for file in cs_files:
|
||||||
t_name = file.split(']', 2)[2].split('.torrent')[0]
|
t_name = file.split(']', 2)[2].split('.torrent')[0]
|
||||||
|
@ -254,7 +261,7 @@ def cross_seed():
|
||||||
def update_category():
|
def update_category():
|
||||||
if args.manage == 'manage' or args.cat_update == 'cat_update':
|
if args.manage == 'manage' or args.cat_update == 'cat_update':
|
||||||
num_cat = 0
|
num_cat = 0
|
||||||
torrent_list = client.torrents.info()
|
torrent_list = client.torrents.info(sort='added_on',reverse=True)
|
||||||
for torrent in torrent_list:
|
for torrent in torrent_list:
|
||||||
if torrent.category == '':
|
if torrent.category == '':
|
||||||
for x in torrent.trackers:
|
for x in torrent.trackers:
|
||||||
|
@ -287,7 +294,7 @@ def update_category():
|
||||||
def update_tags():
|
def update_tags():
|
||||||
if args.manage == 'manage' or args.tag_update == 'tag_update':
|
if args.manage == 'manage' or args.tag_update == 'tag_update':
|
||||||
num_tags = 0
|
num_tags = 0
|
||||||
torrent_list = client.torrents.info()
|
torrent_list = client.torrents.info(sort='added_on',reverse=True)
|
||||||
for torrent in torrent_list:
|
for torrent in torrent_list:
|
||||||
if torrent.tags == '':
|
if torrent.tags == '':
|
||||||
for x in torrent.trackers:
|
for x in torrent.trackers:
|
||||||
|
@ -319,13 +326,14 @@ def update_tags():
|
||||||
|
|
||||||
def rem_unregistered():
|
def rem_unregistered():
|
||||||
if args.manage == 'manage' or args.rem_unregistered == 'rem_unregistered':
|
if args.manage == 'manage' or args.rem_unregistered == 'rem_unregistered':
|
||||||
torrent_list = client.torrents.info()
|
torrent_list = client.torrents.info(sort='added_on',reverse=True)
|
||||||
torrentdict = get_torrent_info(torrent_list)
|
torrentdict = get_torrent_info(torrent_list)
|
||||||
rem_unr = 0
|
rem_unr = 0
|
||||||
del_tor = 0
|
del_tor = 0
|
||||||
for torrent in torrent_list:
|
for torrent in torrent_list:
|
||||||
t_name = torrent.name
|
t_name = torrent.name
|
||||||
t_count = torrentdict[t_name]['count']
|
t_count = torrentdict[t_name]['count']
|
||||||
|
t_msg = torrentdict[t_name]['msg']
|
||||||
for x in torrent.trackers:
|
for x in torrent.trackers:
|
||||||
if x.url.startswith('http'):
|
if x.url.startswith('http'):
|
||||||
t_url = trunc_val(x.url, '/')
|
t_url = trunc_val(x.url, '/')
|
||||||
|
@ -340,12 +348,22 @@ def rem_unregistered():
|
||||||
if 'Unregistered torrent' in x.msg or 'Torrent is not found' in x.msg:
|
if 'Unregistered torrent' in x.msg or 'Torrent is not found' in x.msg:
|
||||||
if t_count > 1:
|
if t_count > 1:
|
||||||
if args.dry_run == 'dry_run':
|
if args.dry_run == 'dry_run':
|
||||||
|
if '' in t_msg:
|
||||||
logger.dryrun(n_info)
|
logger.dryrun(n_info)
|
||||||
rem_unr += 1
|
rem_unr += 1
|
||||||
else:
|
else:
|
||||||
|
logger.dryrun(n_d_info)
|
||||||
|
del_tor += 1
|
||||||
|
else:
|
||||||
|
# Checks if any of the original torrents are working
|
||||||
|
if '' in t_msg:
|
||||||
logger.info(n_info)
|
logger.info(n_info)
|
||||||
torrent.delete(hash=torrent.hash, delete_files=False)
|
torrent.delete(hash=torrent.hash, delete_files=False)
|
||||||
rem_unr += 1
|
rem_unr += 1
|
||||||
|
else:
|
||||||
|
logger.info(n_d_info)
|
||||||
|
torrent.delete(hash=torrent.hash, delete_files=True)
|
||||||
|
del_tor += 1
|
||||||
else:
|
else:
|
||||||
if args.dry_run == 'dry_run':
|
if args.dry_run == 'dry_run':
|
||||||
logger.dryrun(n_d_info)
|
logger.dryrun(n_d_info)
|
||||||
|
|
Loading…
Add table
Reference in a new issue