From 24fb3192c70ce09fabd7b9fa164ba6c5ddadfaf7 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 20 Jul 2013 16:46:49 +0530 Subject: [PATCH] Added Headphones Indexer --- data/interfaces/default/config.html | 32 +++++++++++++- headphones/__init__.py | 16 ++++++- headphones/searcher.py | 66 +++++++++++++++++++++++++++-- headphones/webserve.py | 5 ++- 4 files changed, 112 insertions(+), 7 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 34e35d17..07cdae9c 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -208,6 +208,26 @@ NZBs +
+ Headphones Indexer +
+ +
+
+
+ + + Headphones VIP Server username & password +
+
+ + +
+ +
+
Newznab
@@ -801,10 +821,10 @@
- +
-
+
Get an Account!
@@ -1125,6 +1145,14 @@ formfields.append("
"); $("#add_newznab").before(formfields); }); + + $(".hpuser").keyup(function() { + $(".hpuser").val($(this).val()); + }); + + $(".hppass").keyup(function() { + $(".hppass").val($(this).val()); + }); $(function() { $( "#tabs" ).tabs(); diff --git a/headphones/__init__.py b/headphones/__init__.py index 4e863b54..4df3318d 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -136,6 +136,8 @@ NZBGET_PASSWORD = None NZBGET_CATEGORY = None NZBGET_HOST = None +HEADPHONES_INDEXER = False + NZBMATRIX = False NZBMATRIX_USERNAME = None NZBMATRIX_APIKEY = None @@ -291,7 +293,7 @@ def initialize(): TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, ISOHUNT, KAT, MININOVA, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, \ RUTRACKER, RUTRACKER_USER, RUTRACKER_PASSWORD, WHATCD, WHATCD_USERNAME, WHATCD_PASSWORD, DOWNLOAD_TORRENT_DIR, \ LIBRARYSCAN, LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ - NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ + NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, HEADPHONES_INDEXER, NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS, \ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, NZBSRUS, NZBSRUS_UID, NZBSRUS_APIKEY, \ NZB_DOWNLOADER, PREFERRED_WORDS, REQUIRED_WORDS, IGNORED_WORDS, \ LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, ENCODERFOLDER, ENCODER_PATH, ENCODER, XLDPROFILE, BITRATE, SAMPLINGFREQUENCY, \ @@ -309,6 +311,7 @@ def initialize(): CheckSection('General') CheckSection('SABnzbd') CheckSection('NZBget') + CheckSection('Headphones') CheckSection('NZBMatrix') CheckSection('Newznab') CheckSection('NZBsorg') @@ -419,6 +422,8 @@ def initialize(): NZBGET_CATEGORY = check_setting_str(CFG, 'NZBget', 'nzbget_category', '') NZBGET_HOST = check_setting_str(CFG, 'NZBget', 'nzbget_host', '') + HEADPHONES_INDEXER = bool(check_setting_int(CFG, 'Headphones', 'headphones_indexer', 0)) + NZBMATRIX = bool(check_setting_int(CFG, 'NZBMatrix', 'nzbmatrix', 0)) NZBMATRIX_USERNAME = check_setting_str(CFG, 'NZBMatrix', 'nzbmatrix_username', '') NZBMATRIX_APIKEY = check_setting_str(CFG, 'NZBMatrix', 'nzbmatrix_apikey', '') @@ -555,6 +560,12 @@ def initialize(): if BLACKHOLE: NZB_DOWNLOADER = 2 CONFIG_VERSION = '4' + + # Enable Headphones Indexer if they have a VIP account + if CONFIG_VERSION == '4': + if HPUSER and HPPASS: + HEADPHONES_INDEXER = True + CONFIG_VERSION = '5' if not LOG_DIR: LOG_DIR = os.path.join(DATA_DIR, 'logs') @@ -764,6 +775,9 @@ def config_write(): new_config['NZBget']['nzbget_password'] = NZBGET_PASSWORD new_config['NZBget']['nzbget_category'] = NZBGET_CATEGORY new_config['NZBget']['nzbget_host'] = NZBGET_HOST + + new_config['Headphones'] = {} + new_config['Headphones']['headphones_indexer'] = int(HEADPHONES_INDEXER) new_config['NZBMatrix'] = {} new_config['NZBMatrix']['nzbmatrix'] = int(NZBMATRIX) diff --git a/headphones/searcher.py b/headphones/searcher.py index 9ee0ac30..a7c51a9b 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -25,7 +25,7 @@ from xml.dom import minidom from xml.parsers.expat import ExpatError import lib.simplejson as json from StringIO import StringIO -import gzip +import gzip, base64 import os, re, time import string @@ -111,7 +111,7 @@ def searchforalbum(albumid=None, new=False, lossless=False): for result in results: foundNZB = "none" - if (headphones.NEWZNAB or headphones.NZBSORG or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE_DIR or headphones.NZBGET_HOST): + if (headphones.HEADPHONES_INDEXER or headphones.NEWZNAB or headphones.NZBSORG or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE_DIR or headphones.NZBGET_HOST): if result['Status'] == "Wanted Lossless": foundNZB = searchNZB(result['AlbumID'], new, losslessOnly=True) else: @@ -127,7 +127,7 @@ def searchforalbum(albumid=None, new=False, lossless=False): else: foundNZB = "none" - if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE_DIR or headphones.NZBGET_HOST): + if (headphones.HEADPHONES_INDEXER or headphones.NEWZNAB or headphones.NZBSORG or headphones.NZBSRUS) and (headphones.SAB_HOST or headphones.BLACKHOLE_DIR or headphones.NZBGET_HOST): foundNZB = searchNZB(albumid, new, lossless) if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES or headphones.RUTRACKER or headphones.WHATCD) and foundNZB == "none": @@ -182,6 +182,66 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): resultlist = [] + if headphones.HEADPHONES_INDEXER: + + provider = "headphones" + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: + categories = "3040" + elif headphones.PREFERRED_QUALITY: + categories = "3040,3010" + else: + categories = "3010" + + if albums['Type'] == 'Other': + categories = "3030" + logger.info("Album type is audiobook/spokenword. Using audiobook category") + + params = { "t": "search", + "cat": categories, + "apikey": '89edf227c1de9b3de50383fff11466c6', + "maxage": headphones.USENET_RETENTION, + "q": term + } + + searchURL = 'http://headphones.codeshy.com/newznab/api?' + urllib.urlencode(params) + + # Add a user-agent + request = urllib2.Request(searchURL) + request.add_header('User-Agent', 'headphones/0.0 +https://github.com/rembo10/headphones') + base64string = base64.encodestring('%s:%s' % (headphones.HPUSER, headphones.HPPASS)).replace('\n', '') + request.add_header("Authorization", "Basic %s" % base64string) + + opener = urllib2.build_opener() + + logger.info(u'Parsing results from %s' % (searchURL, 'Headphones Index')) + + try: + data = opener.open(request).read() + except Exception, e: + logger.warn('Error fetching data from %s: %s' % ('Headphones Index', e)) + data = False + + if data: + + d = feedparser.parse(data) + + if not len(d.entries): + logger.info(u"No results found from %s for %s" % ('Headphones Index', term)) + pass + + else: + for item in d.entries: + try: + url = item.link + title = item.title + size = int(item.links[1]['length']) + + resultlist.append((title, size, url, provider)) + logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) + + except Exception, e: + logger.error(u"An unknown error occurred trying to parse the feed: %s" % e) + if headphones.NEWZNAB: newznab_hosts = [(headphones.NEWZNAB_HOST, headphones.NEWZNAB_APIKEY, headphones.NEWZNAB_ENABLED)] diff --git a/headphones/webserve.py b/headphones/webserve.py index fac897f9..31d3f26d 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -586,6 +586,7 @@ class WebInterface(object): "use_blackhole" : checked(headphones.BLACKHOLE), "blackhole_dir" : headphones.BLACKHOLE_DIR, "usenet_retention" : headphones.USENET_RETENTION, + "use_headphones_indexer" : checked(headphones.HEADPHONES_INDEXER), "use_newznab" : checked(headphones.NEWZNAB), "newznab_host" : headphones.NEWZNAB_HOST, "newznab_api" : headphones.NEWZNAB_APIKEY, @@ -704,7 +705,8 @@ 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, 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='nzbget', nzbget_password=None, nzbget_category=None, nzb_downloader=0, download_dir=None, blackhole=0, blackhole_dir=None, usenet_retention=None, newznab=0, newznab_host=None, newznab_apikey=None, + sab_category=None, nzbget_host=None, nzbget_username='nzbget', nzbget_password=None, nzbget_category=None, nzb_downloader=0, download_dir=None, blackhole=0, 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, 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=10, 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, @@ -741,6 +743,7 @@ class WebInterface(object): headphones.BLACKHOLE = blackhole headphones.BLACKHOLE_DIR = blackhole_dir headphones.USENET_RETENTION = usenet_retention + headphones.HEADPHONES_INDEXER = use_headphones_indexer headphones.NEWZNAB = newznab headphones.NEWZNAB_HOST = newznab_host headphones.NEWZNAB_APIKEY = newznab_apikey