diff --git a/headphones/__init__.py b/headphones/__init__.py index 75c65bb5..882fed07 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -43,6 +43,7 @@ HTTP_ROOT = None LAUNCH_BROWSER = False GIT_PATH = None +INSTALL_TYPE = None CURRENT_VERSION = None LATEST_VERSION = None COMMITS_BEHIND = None @@ -58,6 +59,8 @@ RENAME_FILES = False CLEANUP_FILES = False ADD_ALBUM_ART = False DOWNLOAD_DIR = None +BLACKHOLE = None +BLACKHOLE_DIR = None USENET_RETENTION = None NZB_SEARCH_INTERVAL = 360 @@ -135,7 +138,7 @@ def initialize(): HTTP_PORT, HTTP_HOST, HTTP_USERNAME, HTTP_PASSWORD, HTTP_ROOT, LAUNCH_BROWSER, GIT_PATH, \ CURRENT_VERSION, \ MUSIC_DIR, PREFER_LOSSLESS, FLAC_TO_MP3, MOVE_FILES, RENAME_FILES, FOLDER_FORMAT, \ - FILE_FORMAT, CLEANUP_FILES, ADD_ALBUM_ART, DOWNLOAD_DIR, USENET_RETENTION, \ + FILE_FORMAT, CLEANUP_FILES, ADD_ALBUM_ART, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, \ NZB_SEARCH_INTERVAL, LIBRARYSCAN_INTERVAL, \ SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, \ @@ -178,6 +181,8 @@ def initialize(): CLEANUP_FILES = bool(check_setting_int(CFG, 'General', 'cleanup_files', 0)) ADD_ALBUM_ART = bool(check_setting_int(CFG, 'General', 'add_album_art', 0)) DOWNLOAD_DIR = check_setting_str(CFG, 'General', 'download_dir', '') + BLACKHOLE = bool(check_setting_int(CFG, 'General', 'blackhole', 0)) + BLACKHOLE_DIR = check_setting_str(CFG, 'General', 'blackhole_dir', '') USENET_RETENTION = check_setting_int(CFG, 'General', 'usenet_retention', '') NZB_SEARCH_INTERVAL = check_setting_int(CFG, 'General', 'nzb_search_interval', 360) @@ -305,6 +310,8 @@ def config_write(): new_config['General']['cleanup_files'] = int(CLEANUP_FILES) new_config['General']['add_album_art'] = int(ADD_ALBUM_ART) new_config['General']['download_dir'] = DOWNLOAD_DIR + new_config['General']['blackhole'] = int(BLACKHOLE) + new_config['General']['blackhole_dir'] = BLACKHOLE_DIR new_config['General']['usenet_retention'] = USENET_RETENTION new_config['General']['nzb_search_interval'] = NZB_SEARCH_INTERVAL diff --git a/headphones/searcher.py b/headphones/searcher.py index a8b653d1..78543132 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -2,7 +2,7 @@ import urllib import string import lib.feedparser as feedparser import sqlite3 -import re +import os, re import headphones from headphones import logger @@ -64,13 +64,12 @@ def searchNZB(albumid=None): size = int(item.links[1]['length']) if size < maxsize: resultlist.append((title, size, url)) - logger.info(u"Found " + title +" : " + url + " (Size: " + size + ")") + logger.info('Found %s. Size: %i' % (title, size)) else: - logger.info(title + u" is larger than the maxsize for this category, skipping. (Size: " + size+")") - + logger.info('%s is larger than the maxsize for this category, skipping. (Size: %i bytes)' % (title, size)) - except: - logger.info(u"No results found") + except Exception, e: + logger.info(u"No results found. %s" % e) if headphones.NEWZNAB: @@ -100,12 +99,12 @@ def searchNZB(albumid=None): size = int(item.links[1]['length']) if size < maxsize: resultlist.append((title, size, url)) - logger.info(u"Found " + title +" : " + url + " (Size: " + size + ")") + logger.info('Found %s. Size: %i' % (title, size)) else: - logger.info(title + u" is larger than the maxsize for this category, skipping. (Size: " + size+")") + logger.info('%s is larger than the maxsize for this category, skipping. (Size: %i bytes)' % (title, size)) - except: - logger.info(u"No results found") + except Exception, e: + logger.info(u"No results found. %s" % e) if headphones.NZBSORG: @@ -137,50 +136,68 @@ def searchNZB(albumid=None): size = int(item.links[1]['length']) if size < maxsize: resultlist.append((title, size, url)) - logger.info(u"Found " + title +" : " + url + " (Size: " + size + ")") + logger.info('Found %s. Size: %i' % (title, size)) else: - logger.info(title + u" is larger than the maxsize for this category, skipping. (Size: " + size +")") - + logger.info('%s is larger than the maxsize for this category, skipping. (Size: %i bytes)' % (title, size)) - except: - logger.info(u"No results found") + except Exception, e: + logger.info(u"No results found. %s" % e) if len(resultlist): bestqual = sorted(resultlist, key=lambda title: title[1], reverse=True)[0] - logger.info(u"Downloading: " + bestqual[0]) + logger.info(u"Found best result: %s (%s) - %s bytes" % (bestqual[0], bestqual[2], bestqual[1])) downloadurl = bestqual[2] - linkparams = {} - - linkparams["mode"] = "addurl" - - if headphones.SAB_APIKEY: - linkparams["apikey"] = headphones.SAB_APIKEY - if headphones.SAB_USERNAME: - linkparams["ma_username"] = headphones.SAB_USERNAME - if headphones.SAB_PASSWORD: - linkparams["ma_password"] = headphones.SAB_PASSWORD - if headphones.SAB_CATEGORY: - linkparams["cat"] = headphones.SAB_CATEGORY - - linkparams["name"] = downloadurl + if headphones.SAB_HOST and not headphones.BLACKHOLE: + linkparams = {} - saburl = 'http://' + headphones.SAB_HOST + '/sabnzbd/api?' + urllib.urlencode(linkparams) - logger.info(u"Sending link to SABNZBD: " + saburl) - - try: - urllib.urlopen(saburl) + linkparams["mode"] = "addurl" - except: - logger.error(u"Unable to send link. Are you sure the host address is correct?") + if headphones.SAB_APIKEY: + linkparams["apikey"] = headphones.SAB_APIKEY + if headphones.SAB_USERNAME: + linkparams["ma_username"] = headphones.SAB_USERNAME + if headphones.SAB_PASSWORD: + linkparams["ma_password"] = headphones.SAB_PASSWORD + if headphones.SAB_CATEGORY: + linkparams["cat"] = headphones.SAB_CATEGORY + + linkparams["name"] = downloadurl + linkparams["nzbname"] = ('%s - %s [%s]' % (albums[0], albums[1], year)) + + saburl = 'http://' + headphones.SAB_HOST + '/sabnzbd/api?' + urllib.urlencode(linkparams) + logger.info(u"Sending link to SABNZBD: " + saburl) - c.execute('UPDATE albums SET status = "Snatched" WHERE AlbumID="%s"' % albums[2]) - c.execute('INSERT INTO snatched VALUES( ?, ?, ?, ?, CURRENT_DATE, ?)', (albums[2], bestqual[0], bestqual[1], bestqual[2], "Snatched")) - conn.commit() - - else: - pass + try: + urllib.urlopen(saburl) + + except: + logger.error(u"Unable to send link. Are you sure the host address is correct?") + break + + c.execute('UPDATE albums SET status = "Snatched" WHERE AlbumID="%s"' % albums[2]) + c.execute('INSERT INTO snatched VALUES( ?, ?, ?, ?, CURRENT_DATE, ?)', (albums[2], bestqual[0], bestqual[1], bestqual[2], "Snatched")) + conn.commit() + c.close() + + elif headphones.BLACKHOLE: + + nzb_name = ('%s - %s [%s].nzb' % (albums[0], albums[1], year)) + download_path = os.path.join(headphones.BLACKHOLE_DIR, nzb_name) + + try: + urllib.urlretrieve(downloadurl, download_path) + except Exception, e: + logger.error('Couldn\'t retrieve NZB: %s' % e) + break + + c.execute('UPDATE albums SET status = "Snatched" WHERE AlbumID="%s"' % albums[2]) + c.execute('INSERT INTO snatched VALUES( ?, ?, ?, ?, CURRENT_DATE, ?)', (albums[2], bestqual[0], bestqual[1], bestqual[2], "Snatched")) + conn.commit() + c.close() + + + - c.close() \ No newline at end of file diff --git a/headphones/templates.py b/headphones/templates.py index ecc49446..fd8409d2 100644 --- a/headphones/templates.py +++ b/headphones/templates.py @@ -140,6 +140,23 @@ configform = form = ''' i.e. Downloads/music or /Users/name/Downloads/music + +
Use Black Hole:
+Black Hole Directory:
Path to Music folder:
+
Path to Music folder:
i.e. /Users/name/Music/iTunes or /Volumes/share/music