diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 30589755..54f513f7 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -124,7 +124,7 @@
Usenet - Sabnzbd NZBget Black Hole + Sabnzbd NZBget Black Hole
@@ -192,7 +192,7 @@
Torrents - Black Hole Transmission uTorrent + Black Hole Transmission uTorrent (Beta)
diff --git a/headphones/searcher.py b/headphones/searcher.py index 32aa5974..ecc92acb 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -705,13 +705,8 @@ def send_to_downloader(data, bestqual, album): else: file_or_url = bestqual[2] - torrentid = utorrent.addTorrent(file_or_url) - - if not torrentid: - logger.error("Error sending torrent to uTorrent. Are you sure it's running?") - return - - folder_name = utorrent.getTorrentFolder(torrentid) + folder_name = utorrent.addTorrent(bestqual[2],bestqual[0]) + if folder_name: logger.info('Torrent folder name: %s' % folder_name) else: diff --git a/headphones/utorrent.py b/headphones/utorrent.py index 97fe1219..e8fb4809 100644 --- a/headphones/utorrent.py +++ b/headphones/utorrent.py @@ -14,6 +14,7 @@ # along with Headphones. If not, see . import re +import os import time import base64 import headphones @@ -28,67 +29,13 @@ from headphones import logger, notifiers, request # TODO: Store the session id so we don't need to make 2 calls # Store torrent id so we can check up on it -def addTorrent(link): - if link.startswith("magnet") or link.startswith("http") or link.endswith(".torrent"): - method = None - params = {'action':'add-url', 's':link} - files = None - else: - method = "post" - params = {'action':'add-file'} - files = {'torrent_file':{'music.torrent', link}} - - response = torrentAction(method,params,files) - - if not response: - return False - - print response - - if response['result'] == 'success': - if 'torrent-added' in response['arguments']: - name = response['arguments']['torrent-added']['name'] - retid = response['arguments']['torrent-added']['id'] - elif 'torrent-duplicate' in response['arguments']: - name = response['arguments']['torrent-duplicate']['name'] - retid = response['arguments']['torrent-duplicate']['id'] - else: - name = link - retid = False - - logger.info(u"Torrent sent to Transmission successfully") - return retid - - else: - logger.info('Transmission returned status %s' % response['result']) - return False - -def getTorrentFolder(torrentid): - method = 'torrent-get' - arguments = { 'ids': torrentid, 'fields': ['name','percentDone']} - - response = torrentAction(method, arguments) - percentdone = response['arguments']['torrents'][0]['percentDone'] - torrent_folder_name = response['arguments']['torrents'][0]['name'] - - tries = 1 - - while percentdone == 0 and tries <10: - tries+=1 - time.sleep(5) - response = torrentAction(method, arguments) - percentdone = response['arguments']['torrents'][0]['percentDone'] - - torrent_folder_name = response['arguments']['torrents'][0]['name'] - - return torrent_folder_name - -def torrentAction(method=None, params=None, files=None): +def addTorrent(link, title): host = headphones.UTORRENT_HOST username = headphones.UTORRENT_USERNAME password = headphones.UTORRENT_PASSWORD + label = headphones.UTORRENT_LABEL token = '' if not host.startswith('http'): @@ -106,11 +53,44 @@ def torrentAction(method=None, params=None, files=None): auth = (username, password) if username and password else None token_request = request.request_response(host + 'token.html', auth=auth) token = re.findall('(.*?) 1: + folder = os.path.basename(torrent[26]) + tor_hash = torrent[0] + params = {'action':'setprops', 'hash':tor_hash,'s':'label', 'v':label} + response = request.request_json(host, params=params, auth=auth, cookies=cookies) + break + else: + time.sleep(5) + tries += 1 + + return folder + +