diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 3a7b4204..30589755 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -192,7 +192,7 @@
Torrents - Black Hole Transmission + Black Hole Transmission uTorrent
@@ -239,6 +239,10 @@
+
+ + +
diff --git a/headphones/__init__.py b/headphones/__init__.py index b354291b..2d4e9290 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -154,6 +154,7 @@ TRANSMISSION_PASSWORD = None UTORRENT_HOST = None UTORRENT_USERNAME = None UTORRENT_PASSWORD = None +UTORRENT_LABEL = None NEWZNAB = False NEWZNAB_HOST = None @@ -346,7 +347,7 @@ def initialize(): RUTRACKER, RUTRACKER_USER, RUTRACKER_PASSWORD, WHATCD, WHATCD_USERNAME, WHATCD_PASSWORD, DOWNLOAD_TORRENT_DIR, \ LIBRARYSCAN, LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, UPDATE_DB_INTERVAL, MB_IGNORE_AGE, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, HEADPHONES_INDEXER, NZBMATRIX, TRANSMISSION_HOST, TRANSMISSION_USERNAME, TRANSMISSION_PASSWORD, \ - UTORRENT_HOST, UTORRENT_USERNAME, UTORRENT_PASSWORD, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ + UTORRENT_HOST, UTORRENT_USERNAME, UTORRENT_PASSWORD, UTORRENT_LABEL, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NZBSRUS, NZBSRUS_UID, NZBSRUS_APIKEY, OMGWTFNZBS, OMGWTFNZBS_UID, OMGWTFNZBS_APIKEY, \ NZB_DOWNLOADER, TORRENT_DOWNLOADER, PREFERRED_WORDS, REQUIRED_WORDS, IGNORED_WORDS, LASTFM_USERNAME, \ INTERFACE, FOLDER_PERMISSIONS, FILE_PERMISSIONS, ENCODERFOLDER, ENCODER_PATH, ENCODER, XLDPROFILE, BITRATE, SAMPLINGFREQUENCY, \ @@ -511,6 +512,7 @@ def initialize(): UTORRENT_HOST = check_setting_str(CFG, 'uTorrent', 'utorrent_host', '') UTORRENT_USERNAME = check_setting_str(CFG, 'uTorrent', 'utorrent_username', '') UTORRENT_PASSWORD = check_setting_str(CFG, 'uTorrent', 'utorrent_password', '') + UTORRENT_LABEL = check_setting_str(CFG, 'uTorrent', 'utorrent_label', '') NEWZNAB = bool(check_setting_int(CFG, 'Newznab', 'newznab', 0)) NEWZNAB_HOST = check_setting_str(CFG, 'Newznab', 'newznab_host', '') @@ -941,6 +943,7 @@ def config_write(): new_config['uTorrent']['utorrent_host'] = UTORRENT_HOST new_config['uTorrent']['utorrent_username'] = UTORRENT_USERNAME new_config['uTorrent']['utorrent_password'] = UTORRENT_PASSWORD + new_config['uTorrent']['utorrent_label'] = UTORRENT_LABEL new_config['Newznab'] = {} new_config['Newznab']['newznab'] = int(NEWZNAB) diff --git a/headphones/utorrent.py b/headphones/utorrent.py index fca5f5e3..5b870ea2 100644 --- a/headphones/utorrent.py +++ b/headphones/utorrent.py @@ -12,3 +12,98 @@ # # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . + +import re +import time +import base64 +import headphones + +import simplejson as json + +from headphones import logger, notifiers, request + +# This is just a simple script to send torrents to transmission. The +# intention is to turn this into a class where we can check the state +# of the download, set the download dir, etc. +# 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): + method = 'torrent-add' + arguments = {'filename': link, 'download-dir': headphones.DOWNLOAD_TORRENT_DIR} + + response = torrentAction(method,arguments) + + if not response: + return False + + 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, arguments): + + host = headphones.UTORRENT_HOST + username = headphones.UTORRENT_USERNAME + password = headphones.UTORRENT_PASSWORD + token = '' + + if not host.startswith('http'): + host = 'http://' + host + + if host.endswith('/'): + host = host[:-1] + + if host.endswith('/gui'): + host = host + '/' + else: + host = host + '/gui/' + + # Retrieve session id + auth = (username, password) if username and password else None + token_request = request.request_response(host + 'token.html') + token = re.findall('(.*?)