Merge pull request #8 from StuffAnThings/develop

Bug Fix: Allow Updating tags with multiple tracker urls
This commit is contained in:
Visorask 2021-03-10 19:42:46 -06:00 committed by GitHub
commit d3ec78956f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -125,21 +125,20 @@ def get_category(path):
if f in path: if f in path:
category = i category = i
return category return category
else: category = ''
category = '' logger.warning('No categories matched. Check your config.yml file. - Setting category to NULL')
logger.warning('No categories matched. Check your config.yml file. - Setting tag to NULL') return category
return category
def get_tags(url): def get_tags(urls):
tag_path = cfg['tags'] tag_path = cfg['tags']
for i, f in tag_path.items(): for i, f in tag_path.items():
if i in url: for url in urls:
tag = f if i in url:
return tag tag = f
else: if tag: return tag,trunc_val(url, '/')
tag = '' tag = ''
logger.warning('No tags matched. Check your config.yml file. Setting tag to NULL') logger.warning('No tags matched. Check your config.yml file. Setting tag to NULL')
return tag return tag
@ -173,7 +172,7 @@ def recheck():
torrent_sorted_list = client.torrents.info(status_filter='paused',sort='size') torrent_sorted_list = client.torrents.info(status_filter='paused',sort='size')
torrentdict = get_torrent_info(client.torrents.info(sort='added_on',reverse=True)) torrentdict = get_torrent_info(client.torrents.info(sort='added_on',reverse=True))
for torrent in torrent_sorted_list: for torrent in torrent_sorted_list:
new_tag = [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 torrent.tags == '': torrent.add_tags(tags=new_tag) if torrent.tags == '': torrent.add_tags(tags=new_tag)
#Resume torrent if completed #Resume torrent if completed
if torrent.progress == 1: if torrent.progress == 1:
@ -296,21 +295,18 @@ def update_tags():
torrent_list = client.torrents.info(sort='added_on',reverse=True) 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: new_tag,t_url = get_tags([x.url for x in torrent.trackers if x.url.startswith('http')])
if x.url.startswith('http'): if args.dry_run == 'dry_run':
t_url = trunc_val(x.url, '/') logger.dryrun(f'\n - Torrent Name: {torrent.name}'
new_tag = get_tags(x.url) f'\n - New Tag: {new_tag}'
if args.dry_run == 'dry_run': f'\n - Tracker: {t_url}')
logger.dryrun(f'\n - Torrent Name: {torrent.name}' num_tags += 1
f'\n - New Tag: {new_tag}' else:
f'\n - Tracker: {t_url}') logger.info(f'\n - Torrent Name: {torrent.name}'
num_tags += 1 f'\n - New Tag: {new_tag}'
else: f'\n - Tracker: {t_url}')
logger.info(f'\n - Torrent Name: {torrent.name}' torrent.add_tags(tags=new_tag)
f'\n - New Tag: {new_tag}' num_tags += 1
f'\n - Tracker: {t_url}')
torrent.add_tags(tags=new_tag)
num_tags += 1
if args.dry_run == 'dry_run': if args.dry_run == '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.')