Bug fix: Handle public trackers only using DHT

This commit is contained in:
Jon 2021-11-27 15:10:29 -05:00
parent e4c2b948be
commit ac61eb093e
No known key found for this signature in database
GPG key ID: 9665BA6CF5DC2671

View file

@ -203,12 +203,12 @@ def get_category(path):
category = '' category = ''
return category return category
category = '' category = ''
logger.warning('No categories matched. Check your config.yml file. - Setting category to NULL') logger.warning(f'No categories matched for the save path {path}. Check your config.yml file. - Setting category to NULL')
return category return category
#Get tags from config file based on keyword #Get tags from config file based on keyword
def get_tags(urls): def get_tags(urls):
if 'tags' in cfg and cfg["tags"] != None: if 'tags' in cfg and cfg["tags"] != None and urls:
tag_path = cfg['tags'] tag_path = cfg['tags']
for i, f in tag_path.items(): for i, f in tag_path.items():
for url in urls: for url in urls:
@ -219,7 +219,7 @@ def get_tags(urls):
tag = ('','') tag = ('','')
return tag return tag
tag = ('','') tag = ('','')
logger.warning('No tags matched. Check your config.yml file. Setting tag to NULL') logger.warning(f'No tags matched for {urls}. Check your config.yml file. Setting tag to NULL')
return tag return tag
@ -266,6 +266,8 @@ def get_torrent_info(t_list):
save_path = torrent.save_path save_path = torrent.save_path
category = get_category(save_path) category = get_category(save_path)
is_complete = False is_complete = False
msg = None
status = None
if torrent.name in torrentdict: if torrent.name in torrentdict:
t_count = torrentdict[torrent.name]['count'] + 1 t_count = torrentdict[torrent.name]['count'] + 1
msg_list = torrentdict[torrent.name]['msg'] msg_list = torrentdict[torrent.name]['msg']
@ -278,9 +280,12 @@ def get_torrent_info(t_list):
status_list = [] status_list = []
is_complete = torrent.state_enum.is_complete is_complete = torrent.state_enum.is_complete
first_hash = torrent.hash first_hash = torrent.hash
msg,status = [(x.msg,x.status) for x in torrent.trackers if x.url.startswith('http')][0] try:
msg_list.append(msg) msg,status = [(x.msg,x.status) for x in torrent.trackers if x.url.startswith('http')][0]
status_list.append(status) except IndexError:
pass
if msg != None: msg_list.append(msg)
if status != None: status_list.append(status)
torrentattr = {'Category': category, 'save_path': save_path, 'count': t_count, 'msg': msg_list, 'status': status_list, 'is_complete': is_complete, 'first_hash':first_hash} torrentattr = {'Category': category, 'save_path': save_path, 'count': t_count, 'msg': msg_list, 'status': status_list, 'is_complete': is_complete, 'first_hash':first_hash}
torrentdict[torrent.name] = torrentattr torrentdict[torrent.name] = torrentattr
return torrentdict return torrentdict
@ -406,21 +411,22 @@ def set_category():
num_cat = 0 num_cat = 0
for torrent in torrent_list: for torrent in torrent_list:
if torrent.category == '': if torrent.category == '':
for x in torrent.trackers: new_cat = get_category(torrent.save_path)
if x.url.startswith('http'): try:
t_url = trunc_val(x.url, '/') t_url = [trunc_val(x.url, '/') for x in torrent.trackers if x.url.startswith('http')][0]
new_cat = get_category(torrent.save_path) except IndexError:
if dry_run: t_url = None
logger.dryrun(util.insert_space(f'Torrent Name: {torrent.name}',3)) if dry_run:
logger.dryrun(util.insert_space(f'New Category: {new_cat}',3)) logger.dryrun(util.insert_space(f'Torrent Name: {torrent.name}',3))
logger.dryrun(util.insert_space(f'Tracker: {t_url}',8)) logger.dryrun(util.insert_space(f'New Category: {new_cat}',3))
num_cat += 1 logger.dryrun(util.insert_space(f'Tracker: {t_url}',8))
else: num_cat += 1
logger.info(util.insert_space(f'- Torrent Name: {torrent.name}',1)) else:
logger.info(util.insert_space(f'-- New Category: {new_cat}',5)) logger.info(util.insert_space(f'- Torrent Name: {torrent.name}',1))
logger.info(util.insert_space(f'-- Tracker: {t_url}',5)) logger.info(util.insert_space(f'-- New Category: {new_cat}',5))
torrent.set_category(category=new_cat) logger.info(util.insert_space(f'-- Tracker: {t_url}',5))
num_cat += 1 torrent.set_category(category=new_cat)
num_cat += 1
if dry_run: if dry_run:
if num_cat >= 1: if num_cat >= 1:
logger.dryrun(f'Did not update {num_cat} new categories.') logger.dryrun(f'Did not update {num_cat} new categories.')
@ -440,17 +446,18 @@ def set_tags():
for torrent in torrent_list: for torrent in torrent_list:
if torrent.tags == '' or ('cross-seed' in torrent.tags and len([e for e in torrent.tags.split(",") if not 'noHL' in e]) == 1): if torrent.tags == '' or ('cross-seed' in torrent.tags and len([e for e in torrent.tags.split(",") if not 'noHL' in e]) == 1):
new_tag,t_url = get_tags([x.url for x in torrent.trackers if x.url.startswith('http')]) new_tag,t_url = get_tags([x.url for x in torrent.trackers if x.url.startswith('http')])
if dry_run: if new_tag:
logger.dryrun(util.insert_space(f'Torrent Name: {torrent.name}',3)) if dry_run:
logger.dryrun(util.insert_space(f'New Tag: {new_tag}',8)) logger.dryrun(util.insert_space(f'Torrent Name: {torrent.name}',3))
logger.dryrun(util.insert_space(f'Tracker: {t_url}',8)) logger.dryrun(util.insert_space(f'New Tag: {new_tag}',8))
num_tags += 1 logger.dryrun(util.insert_space(f'Tracker: {t_url}',8))
else: num_tags += 1
logger.info(util.insert_space(f'Torrent Name: {torrent.name}',3)) else:
logger.info(util.insert_space(f'New Tag: {new_tag}',8)) logger.info(util.insert_space(f'Torrent Name: {torrent.name}',3))
logger.info(util.insert_space(f'Tracker: {t_url}',8)) logger.info(util.insert_space(f'New Tag: {new_tag}',8))
torrent.add_tags(tags=new_tag) logger.info(util.insert_space(f'Tracker: {t_url}',8))
num_tags += 1 torrent.add_tags(tags=new_tag)
num_tags += 1
if dry_run: if dry_run:
if num_tags >= 1: if num_tags >= 1:
logger.dryrun(f'Did not update {num_tags} new tags.') logger.dryrun(f'Did not update {num_tags} new tags.')