From 138d01db4afda367559759e6b7720372e1b7409d Mon Sep 17 00:00:00 2001 From: doucheymcdoucherson Date: Sat, 15 Jun 2019 00:03:03 -0700 Subject: [PATCH] deluge udpate --- data/interfaces/default/config.html | 7 ++- headphones/config.py | 1 + headphones/deluge.py | 80 ++++++++--------------------- headphones/searcher.py | 8 --- headphones/webserve.py | 1 + 5 files changed, 28 insertions(+), 69 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index d09f3a7d..13aaeb9b 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -317,7 +317,7 @@ Black Hole Transmission uTorrent (Beta) - Deluge (Beta) + Deluge QBitTorrent
@@ -438,6 +438,11 @@ Labels shouldn't contain spaces (requires Label plugin) +
+ + + Directory where Deluge should download to +
diff --git a/headphones/config.py b/headphones/config.py index 7a8b93fc..9ac8f95f 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -79,6 +79,7 @@ _CONFIG_DEFINITIONS = { 'DELUGE_PASSWORD': (str, 'Deluge', ''), 'DELUGE_LABEL': (str, 'Deluge', ''), 'DELUGE_DONE_DIRECTORY': (str, 'Deluge', ''), + 'DELUGE_DOWNLOAD_DIRECTORY': (str, 'Deluge', ''), 'DELUGE_PAUSED': (int, 'Deluge', 0), 'DESTINATION_DIR': (str, 'General', ''), 'DETECT_BITRATE': (int, 'General', 0), diff --git a/headphones/deluge.py b/headphones/deluge.py index 6b0a13f6..0bfb43ae 100644 --- a/headphones/deluge.py +++ b/headphones/deluge.py @@ -466,13 +466,30 @@ def _add_torrent_url(result): def _add_torrent_file(result): logger.debug('Deluge: Adding file') + + options = {} + + if headphones.CONFIG.DELUGE_DOWNLOAD_DIRECTORY: + options['download_location'] = headphones.CONFIG.DELUGE_DOWNLOAD_DIRECTORY + + if headphones.CONFIG.DELUGE_DONE_DIRECTORY or headphones.CONFIG.DOWNLOAD_TORRENT_DIR: + options['move_completed'] = 1 + if headphones.CONFIG.DELUGE_DONE_DIRECTORY: + options['move_completed_path'] = headphones.CONFIG.DELUGE_DONE_DIRECTORY + else: + options['move_completed_path'] = headphones.CONFIG.DOWNLOAD_TORRENT_DIR + + if headphones.CONFIG.DELUGE_PAUSED: + options['add_paused'] = headphones.CONFIG.DELUGE_PAUSED + if not any(delugeweb_auth): _get_auth() try: # content is torrent file contents that needs to be encoded to base64 post_data = json.dumps({"method": "core.add_torrent_file", "params": [result['name'] + '.torrent', - b64encode(result['content'].encode('utf8')), {}], + b64encode(result['content'].encode('utf8')), + options], "id": 2}) response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, verify=deluge_verify_cert, headers=headers) @@ -486,7 +503,8 @@ def _add_torrent_file(result): logger.debug('Deluge: There was a decoding issue, let\'s try again') post_data = json.dumps({"method": "core.add_torrent_file", "params": [result['name'].decode('utf8') + '.torrent', - b64encode(result['content']), {}], + b64encode(result['content']), + options], "id": 22}) response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, verify=deluge_verify_cert, headers=headers) @@ -585,61 +603,3 @@ def setSeedRatio(result): return None -def setTorrentPath(result): - logger.debug('Deluge: Setting download path') - if not any(delugeweb_auth): - _get_auth() - - try: - if headphones.CONFIG.DELUGE_DONE_DIRECTORY or headphones.CONFIG.DOWNLOAD_TORRENT_DIR: - post_data = json.dumps({"method": "core.set_torrent_move_completed", - "params": [result['hash'], True], - "id": 7}) - response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, - verify=deluge_verify_cert, headers=headers) - - if headphones.CONFIG.DELUGE_DONE_DIRECTORY: - move_to = headphones.CONFIG.DELUGE_DONE_DIRECTORY - else: - move_to = headphones.CONFIG.DOWNLOAD_TORRENT_DIR - - if not os.path.exists(move_to): - logger.debug('Deluge: %s directory doesn\'t exist, let\'s create it' % move_to) - os.makedirs(move_to) - post_data = json.dumps({"method": "core.set_torrent_move_completed_path", - "params": [result['hash'], move_to], - "id": 8}) - response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, - verify=deluge_verify_cert, headers=headers) - - return not json.loads(response.text)['error'] - - return True - except Exception as e: - logger.error('Deluge: Setting torrent move-to directory failed: %s' % str(e)) - formatted_lines = traceback.format_exc().splitlines() - logger.error('; '.join(formatted_lines)) - return None - - -def setTorrentPause(result): - logger.debug('Deluge: Pausing torrent') - if not any(delugeweb_auth): - _get_auth() - - try: - if headphones.CONFIG.DELUGE_PAUSED: - post_data = json.dumps({"method": "core.pause_torrent", - "params": [[result['hash']]], - "id": 9}) - response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, - verify=deluge_verify_cert, headers=headers) - - return not json.loads(response.text)['error'] - - return True - except Exception as e: - logger.error('Deluge: Setting torrent paused failed: %s' % str(e)) - formatted_lines = traceback.format_exc().splitlines() - logger.error('; '.join(formatted_lines)) - return None diff --git a/headphones/searcher.py b/headphones/searcher.py index 1e51dc58..77fe7b80 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -943,10 +943,6 @@ def send_to_downloader(data, bestqual, album): logger.error("Error sending torrent to Deluge. Are you sure it's running? Maybe the torrent already exists?") return - # This pauses the torrent right after it is added - if headphones.CONFIG.DELUGE_PAUSED: - deluge.setTorrentPause({'hash': torrentid}) - # Set Label if headphones.CONFIG.DELUGE_LABEL: deluge.setTorrentLabel({'hash': torrentid}) @@ -956,10 +952,6 @@ def send_to_downloader(data, bestqual, album): if seed_ratio is not None: deluge.setSeedRatio({'hash': torrentid, 'ratio': seed_ratio}) - # Set move-to directory - if headphones.CONFIG.DELUGE_DONE_DIRECTORY or headphones.CONFIG.DOWNLOAD_TORRENT_DIR: - deluge.setTorrentPath({'hash': torrentid}) - # Get folder name from Deluge, it's usually the torrent name folder_name = deluge.getTorrentFolder({'hash': torrentid}) if folder_name: diff --git a/headphones/webserve.py b/headphones/webserve.py index 9e2f1979..61a4274a 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1187,6 +1187,7 @@ class WebInterface(object): "deluge_password": headphones.CONFIG.DELUGE_PASSWORD, "deluge_label": headphones.CONFIG.DELUGE_LABEL, "deluge_done_directory": headphones.CONFIG.DELUGE_DONE_DIRECTORY, + "deluge_download_directory": headphones.CONFIG.DELUGE_DOWNLOAD_DIRECTORY, "deluge_paused": checked(headphones.CONFIG.DELUGE_PAUSED), "utorrent_host": headphones.CONFIG.UTORRENT_HOST, "utorrent_username": headphones.CONFIG.UTORRENT_USERNAME,