Only check syno api when input name passed, and use torrent id to limit results. #1671

This commit is contained in:
Clinton Hall 2020-01-04 22:27:31 +13:00 committed by GitHub
commit 77650aa80b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -89,19 +89,26 @@ def parse_synods(args):
input_category = '' input_category = ''
input_name = os.getenv('TR_TORRENT_NAME') input_name = os.getenv('TR_TORRENT_NAME')
input_hash = os.getenv('TR_TORRENT_HASH') input_hash = os.getenv('TR_TORRENT_HASH')
res = core.TORRENT_CLASS.tasks_list(additional_param='detail') if not input_name: # No info passed. Assume manual download.
return input_directory, input_name, input_category, input_hash, input_id
input_id = 'dbid_'.format(os.getenv('TR_TORRENT_ID'))
#res = core.TORRENT_CLASS.tasks_list(additional_param='detail')
res = core.TORRENT_CLASS.tasks_info(input_id, additional_param='detail')
logger.debug('result from syno {0}'.format(res)) logger.debug('result from syno {0}'.format(res))
if res['success']: if res['success']:
try: try:
tasks = res['data']['tasks'] tasks = res['data']['tasks']
task = [ task for task in tasks if task['title'] == input_name ][0] task = [ task for task in tasks if task['id'] == input_id ][0]
input_id = task['id'] input_id = task['id']
input_directory = task['additional']['detail']['destination'] input_directory = task['additional']['detail']['destination']
except: except:
logger.error('unable to find download details in Synology DS') logger.error('unable to find download details in Synology DS')
#Syno paths appear to be relative. Let's test to see if the returned path exists, and if not append to /volume1/ #Syno paths appear to be relative. Let's test to see if the returned path exists, and if not append to /volume1/
if not os.path.isdir(input_directory) and os.path.isdir(os.path.join('/volume1/', input_directory)): if not os.path.isdir(input_directory):
input_directory = os.path.join('/volume1/', input_directory) for root in ['/volume1/', '/volume2/', '/volume3/', '/volume4/']:
if os.path.isdir(os.path.join(root, input_directory)):
input_directory = os.path.join(root, input_directory)
break
return input_directory, input_name, input_category, input_hash, input_id return input_directory, input_name, input_category, input_hash, input_id