diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 3a7b4204..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 + Black Hole Transmission uTorrent (Beta)
@@ -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/searcher.py b/headphones/searcher.py index f4b8ada7..42e124d8 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -31,7 +31,7 @@ import subprocess import headphones from headphones.common import USER_AGENT from headphones import logger, db, helpers, classes, sab, nzbget, request -from headphones import transmission, notifiers +from headphones import utorrent, transmission, notifiers import lib.bencode as bencode @@ -696,6 +696,30 @@ def send_to_downloader(data, bestqual, album): except Exception, e: logger.exception("Unhandled exception") + else: + logger.info("Sending torrent to uTorrent") + + # rutracker needs cookies to be set, pass the .torrent file instead of url + if bestqual[3] == 'rutracker.org': + file_or_url = rutracker.get_torrent(bestqual[2]) + else: + file_or_url = bestqual[2] + + folder_name = utorrent.addTorrent(file_or_url) + + if folder_name: + logger.info('Torrent folder name: %s' % folder_name) + else: + logger.error('Torrent folder name could not be determined') + return + + # remove temp .torrent file created above + if bestqual[3] == 'rutracker.org': + try: + shutil.rmtree(os.path.split(file_or_url)[0]) + except Exception, e: + logger.exception("Unhandled exception") + myDB = db.DBConnection() myDB.action('UPDATE albums SET status = "Snatched" WHERE AlbumID=?', [album['AlbumID']]) myDB.action('INSERT INTO snatched VALUES( ?, ?, ?, ?, DATETIME("NOW", "localtime"), ?, ?, ?)', [album['AlbumID'], bestqual[0], bestqual[1], bestqual[2], "Snatched", folder_name, kind]) @@ -1426,4 +1450,4 @@ def preprocess(resultlist): logger.error("Couldn't retrieve the best nzb. Skipping.") continue - return (None, None) \ No newline at end of file + return (None, None) diff --git a/headphones/utorrent.py b/headphones/utorrent.py index fca5f5e3..7be48355 100644 --- a/headphones/utorrent.py +++ b/headphones/utorrent.py @@ -12,3 +12,93 @@ # # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . + +import re +import os +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): + + host = headphones.UTORRENT_HOST + username = headphones.UTORRENT_USERNAME + password = headphones.UTORRENT_PASSWORD + label = headphones.UTORRENT_LABEL + 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', 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, 'token':token} + response = request.request_json(host, params=params, auth=auth, cookies=cookies) + break + + if folder: + break + else: + time.sleep(5) + tries += 1 + + return folder + + diff --git a/headphones/webserve.py b/headphones/webserve.py index 7ec08e76..9a9af5f8 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -935,6 +935,7 @@ class WebInterface(object): "utorrent_host" : headphones.UTORRENT_HOST, "utorrent_user" : headphones.UTORRENT_USERNAME, "utorrent_pass" : headphones.UTORRENT_PASSWORD, + "utorrent_label" : headphones.UTORRENT_LABEL, "nzb_downloader_sabnzbd" : radio(headphones.NZB_DOWNLOADER, 0), "nzb_downloader_nzbget" : radio(headphones.NZB_DOWNLOADER, 1), "nzb_downloader_blackhole" : radio(headphones.NZB_DOWNLOADER, 2), @@ -1112,7 +1113,7 @@ class WebInterface(object): def configUpdate(self, http_host='0.0.0.0', http_username=None, http_port=8181, http_password=None, launch_browser=0, api_enabled=0, api_key=None, download_scan_interval=None, update_db_interval=None, mb_ignore_age=None, nzb_search_interval=None, libraryscan_interval=None, sab_host=None, sab_username=None, sab_apikey=None, sab_password=None, sab_category=None, nzbget_host=None, nzbget_username=None, nzbget_password=None, nzbget_category=None, transmission_host=None, transmission_username=None, transmission_password=None, - utorrent_host=None, utorrent_username=None, utorrent_password=None, nzb_downloader=0, torrent_downloader=0, download_dir=None, blackhole_dir=None, usenet_retention=None, + utorrent_host=None, utorrent_username=None, utorrent_password=None, utorrent_label=None,nzb_downloader=0, torrent_downloader=0, download_dir=None, blackhole_dir=None, usenet_retention=None, use_headphones_indexer=0, newznab=0, newznab_host=None, newznab_apikey=None, newznab_enabled=0, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, nzbsrus=0, nzbsrus_uid=None, nzbsrus_apikey=None, omgwtfnzbs=0, omgwtfnzbs_uid=None, omgwtfnzbs_apikey=None, preferred_words=None, required_words=None, ignored_words=None, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=None, use_piratebay=0, piratebay_proxy_url=None, use_isohunt=0, use_kat=0, use_mininova=0, waffles=0, waffles_uid=None, waffles_passkey=None, whatcd=0, whatcd_username=None, whatcd_password=None, @@ -1158,6 +1159,7 @@ class WebInterface(object): headphones.UTORRENT_HOST = utorrent_host headphones.UTORRENT_USERNAME = utorrent_username headphones.UTORRENT_PASSWORD = utorrent_password + headphones.UTORRENT_LABEL = utorrent_label headphones.NZB_DOWNLOADER = int(nzb_downloader) headphones.TORRENT_DOWNLOADER = int(torrent_downloader) headphones.DOWNLOAD_DIR = download_dir