diff --git a/headphones/__init__.py b/headphones/__init__.py index 2d99b679..9286835f 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -500,12 +500,7 @@ def initialize(): # Update the config to use direct path to the encoder rather than the encoder folder if ENCODERFOLDER: - if ENCODER == "xld": - ENCODER_PATH = os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING), 'xld') - elif ENCODER == "ffmpeg": - ENCODER_PATH = os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING), 'ffmpeg') - elif ENCODER == "lame": - ENCODER_PATH = os.path.join(headphones.ENCODERFOLDER.encode(headphones.SYS_ENCODING), 'lame') + ENCODER_PATH = os.path.join(ENCODERFOLDER, ENCODER) CONFIG_VERSION = '3' if not LOG_DIR: diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 716b2ace..cb37c5c9 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -43,13 +43,13 @@ def checkFolder(): if album['FolderName']: - # Need to check for variations due to sab renaming. Ideally we'd check the sab config via api to - # figure out which options are checked, but oh well + # We're now checking sab config options after sending to determine renaming - but we'll keep the + # iterations in just in case we can't read the config for some reason nzb_album_possibilities = [ album['FolderName'], sab_replace_dots(album['FolderName']), sab_replace_spaces(album['FolderName']), - sab_replace_dots(sab_replace_spaces(album['FolderName'])) + sab_replace_spaces(sab_replace_dots(album['FolderName'])) ] torrent_album_path = os.path.join(headphones.DOWNLOAD_TORRENT_DIR, album['FolderName']).encode(headphones.SYS_ENCODING) @@ -828,6 +828,8 @@ def forcePostProcess(): logger.info('Processing: %s' % folder_basename) # First try to see if there's a match in the snatched table, then we'll try to parse the foldername + # TODO: Iterate through underscores -> spaces, spaces -> dots, underscores -> dots (this might be hit or miss since it assumes + # all spaces/underscores came from sab replacing values snatched = myDB.action('SELECT AlbumID, Title from snatched WHERE FolderName LIKE ?', [folder_basename]).fetchone() if snatched: logger.info('Found a match in the database: %s. Verifying to make sure it is the correct album' % snatched['Title']) diff --git a/headphones/sab.py b/headphones/sab.py index f3c7fcd3..b337199b 100644 --- a/headphones/sab.py +++ b/headphones/sab.py @@ -24,6 +24,7 @@ import headphones from lib import MultipartPostHandler import urllib2, cookielib +import ast from headphones.common import USER_AGENT from headphones import logger @@ -42,12 +43,6 @@ def sendNZB(nzb): if headphones.SAB_CATEGORY: params['cat'] = headphones.SAB_CATEGORY - -# # if released recently make it high priority -# for curEp in nzb.episodes: -# if datetime.date.today() - curEp.airdate <= datetime.timedelta(days=7): -# params['priority'] = 1 - # if it's a normal result we just pass SAB the URL if nzb.resultType == "nzb": # for newzbin results send the ID to sab specifically @@ -144,3 +139,37 @@ def sendNZB(nzb): else: logger.info(u"Unknown failure sending NZB to sab. Return text is: " + sabText) return False + +def checkConfig(): + + params = { 'mode' : 'get_config', + 'section' : 'misc' + } + + if headphones.SAB_USERNAME: + params['ma_username'] = headphones.SAB_USERNAME + if headphones.SAB_PASSWORD: + params['ma_password'] = headphones.SAB_PASSWORD + if headphones.SAB_APIKEY: + params['apikey'] = headphones.SAB_APIKEY + + if not headphones.SAB_HOST.startswith('http'): + headphones.SAB_HOST = 'http://' + headphones.SAB_HOST + + if headphones.SAB_HOST.endswith('/'): + headphones.SAB_HOST = headphones.SAB_HOST[0:len(headphones.SAB_HOST)-1] + + url = headphones.SAB_HOST + "/" + "api?" + urllib.urlencode(params) + + try: + f = urllib.urlopen(url).read() + except Exception, e: + logger.warn("Unable to read SABnzbd config file - cannot determine renaming options (might affect auto & forced post processing)") + return (0, 0) + + config_options = ast.literal_eval(f) + + replace_spaces = config_options['misc']['replace_spaces'] + replace_dots = config_options['misc']['replace_dots'] + + return (replace_spaces, replace_dots) diff --git a/headphones/searcher.py b/headphones/searcher.py index bbe14128..b3a796ce 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -537,6 +537,15 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): nzb.extraInfo.append(data) nzb.name = nzb_folder_name sab.sendNZB(nzb) + + # If we sent the file to sab, we can check how it was renamed and insert that into the snatched table + (replace_spaces, replace_dots) = sab.checkConfig() + print replace_spaces + print replace_dots + if replace_dots: + nzb_folder_name = helpers.sab_replace_dots(nzb_folder_name) + if replace_spaces: + nzb_folder_name = helpers.sab_replace_spaces(nzb_folder_name) elif headphones.BLACKHOLE: