Check sab config for renaming options so we can insert the correct folder name into the snatched table

This commit is contained in:
rembo10
2012-12-09 00:09:33 -05:00
parent 5a766e126c
commit 2ed6652d7a
3 changed files with 48 additions and 8 deletions

View File

@@ -43,8 +43,8 @@ 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']),
@@ -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'])

View File

@@ -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)

View File

@@ -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: