From bae0b8b44e6de7bbb541b77aed1776c4a96caebe Mon Sep 17 00:00:00 2001 From: shypike <> Date: Thu, 5 Jun 2008 20:01:17 +0000 Subject: [PATCH] Group can now be used as matching criterion for user-defined categories. The group is now sent as the 6th parameter to the user scripts. Note: only the first encountered group in an NZB file is used. --- main/Sample-PostProc.cmd | 1 + main/Sample-PostProc.sh | 1 + main/sabnzbd/interface.py | 22 ++++++++++++++++------ main/sabnzbd/newsunpack.py | 10 +++++----- main/sabnzbd/newzbin.py | 24 +----------------------- main/sabnzbd/nzbstuff.py | 42 ++++++++++++++++++++++++++++++++++++++---- main/sabnzbd/postproc.py | 3 ++- 7 files changed, 64 insertions(+), 39 deletions(-) diff --git a/main/Sample-PostProc.cmd b/main/Sample-PostProc.cmd index e06da29..b447c7b 100644 --- a/main/Sample-PostProc.cmd +++ b/main/Sample-PostProc.cmd @@ -9,6 +9,7 @@ echo The second parameter (nzb-name) = %2 echo The third parameter (nice name) = %3 echo The fourth parameter (newzbin #) = %4 echo The fifth parameter (category) = %5 +echo The sixth parameter (group) = %6 echo. diff --git a/main/Sample-PostProc.sh b/main/Sample-PostProc.sh index f7ff51b..66cc083 100755 --- a/main/Sample-PostProc.sh +++ b/main/Sample-PostProc.sh @@ -9,6 +9,7 @@ echo "The second parameter (nzb-name) =" $2 echo "The third parameter (nice name) =" $3 echo "The fourth parameter (newzbin-id) =" $4 echo "The fifth parameter (category) =" $5 +echo "The sixth parameter (group) =" $6 echo diff --git a/main/sabnzbd/interface.py b/main/sabnzbd/interface.py index 79601fe..c84a43b 100644 --- a/main/sabnzbd/interface.py +++ b/main/sabnzbd/interface.py @@ -146,14 +146,21 @@ def ListScripts(): return lst -def ListCats(): +def ListCats(default=False): """ Return list of categories """ - lst = ['None'] + content = False + if default: + lst = ['Default', 'None'] + else: + lst = ['None'] + for cat in sabnzbd.CFG['categories']: + content = True lst.append(cat) - if len(lst) < 2: + if content: + return lst + else: return [] - return lst def Raiser(root, dummy): @@ -263,8 +270,8 @@ class MainPage(ProtectedClass): info['script_list'].insert(0, 'Default') info['script'] = sabnzbd.DIRSCAN_SCRIPT - info['cat'] = 'None' - info['cat_list'] = ListCats() + info['cat'] = 'Default' + info['cat_list'] = ListCats(True) info['warning'] = "" if not sabnzbd.CFG['servers']: @@ -283,6 +290,8 @@ class MainPage(ProtectedClass): def addID(self, id = None, pp=None, script=None, cat=None, redirect = None): if pp and pp=="-1": pp = None if script and script.lower()=='default': script = None + if cat and cat.lower()=='default': cat = None + RE_NEWZBIN_URL = re.compile(r'/browse/post/(\d+)') newzbin_url = RE_NEWZBIN_URL.search(id.lower()) @@ -302,6 +311,7 @@ class MainPage(ProtectedClass): def addURL(self, url = None, pp=None, script=None, cat=None, redirect = None): if pp and pp=="-1": pp = None if script and script.lower()=='default': script = None + if cat and cat.lower()=='default': cat = None if url: url = url.strip() if url and (url.isdigit() or len(url)==5): diff --git a/main/sabnzbd/newsunpack.py b/main/sabnzbd/newsunpack.py index 06a40d6..6ae883d 100644 --- a/main/sabnzbd/newsunpack.py +++ b/main/sabnzbd/newsunpack.py @@ -105,16 +105,16 @@ def find_programs(curdir): #------------------------------------------------------------------------------ -def external_processing(extern_proc, complete_dir, filename, nicename, cat): +def external_processing(extern_proc, complete_dir, filename, nicename, cat, group): name, msgid = SplitFileName(filename) - command = ['%s' % extern_proc, '%s' % complete_dir, '%s' % filename, \ - '%s' % nicename, '%s' % msgid, '%s' % cat] + command = [str(extern_proc), str(complete_dir), str(filename), \ + str(nicename), str(msgid), str(cat), str(group)] stup, need_shell, command, creationflags = build_command(command) - logging.info('[%s] Running external script %s(%s, %s, %s, %s, %s)', __NAME__, \ - extern_proc, complete_dir, filename, nicename, msgid, cat) + logging.info('[%s] Running external script %s(%s, %s, %s, %s, %s, %s)', __NAME__, \ + extern_proc, complete_dir, filename, nicename, msgid, cat, group) p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, diff --git a/main/sabnzbd/newzbin.py b/main/sabnzbd/newzbin.py index b5c9b47..4a9e471 100644 --- a/main/sabnzbd/newzbin.py +++ b/main/sabnzbd/newzbin.py @@ -34,6 +34,7 @@ import sabnzbd from sabnzbd.constants import * from sabnzbd.decorators import * from sabnzbd.misc import Cat2OptsDef, sanitize_filename +from sabnzbd.nzbstuff import CatConvert import sabnzbd.newswrapper # Regex to find msgid in the Bookmarks page @@ -57,29 +58,6 @@ def IsNewzbin(uri): return uri.find('newzbin') > 0 or uri.find('newzxxx') > 0 -def CatConvert(cat): - """ Convert newzbin category to user categories - Return unchanged if not found - """ - newcat = cat - if cat: - found = False - for ucat in sabnzbd.CFG['categories']: - try: - newzbin = sabnzbd.CFG['categories'][ucat]['newzbin'] - if type(newzbin) != type([]): - newzbin = [newzbin] - except: - newzbin = [] - for name in newzbin: - if name.lower() == cat.lower(): - logging.debug('[%s] Convert newzbin-cat "%s" to user-cat "%s"', __NAME__, cat, ucat) - newcat = ucat - found = True - break - if found: break - return newcat - ################################################################################ # DirectNZB support diff --git a/main/sabnzbd/nzbstuff.py b/main/sabnzbd/nzbstuff.py index b4674d7..57c9e6f 100644 --- a/main/sabnzbd/nzbstuff.py +++ b/main/sabnzbd/nzbstuff.py @@ -443,11 +443,14 @@ class NzbObject(TryList): if nzf.nzf_id: sabnzbd.remove_data(nzf.nzf_id) - if sabnzbd.CREATE_GROUP_FOLDERS: - self.__dirprefix.append(self.__group) + if self.__cat == None: + self.__cat = CatConvert(self.__group) - if sabnzbd.CREATE_CAT_FOLDERS and cat: - self.__dirprefix.append(cat) + #if sabnzbd.CREATE_GROUP_FOLDERS: + self.__dirprefix.append(self.__group) + + #if sabnzbd.CREATE_CAT_FOLDERS and cat: + # self.__dirprefix.append(cat) self.__avg_date = datetime.datetime.fromtimestamp(avg_age / valids) @@ -726,6 +729,12 @@ class NzbObject(TryList): def get_dirprefix(self): return self.__dirprefix[:] + def get_group(self): + if self.__dirprefix: + return self.__dirprefix[0] + else: + return '' + def get_bytes_downloaded(self): return self.__bytes_downloaded @@ -945,3 +954,28 @@ def SplitFileName(name): return "", "" +def CatConvert(cat): + """ Convert newzbin-category/group-name to user categories + Return unchanged if not found + """ + newcat = cat + if cat: + found = False + for ucat in sabnzbd.CFG['categories']: + try: + newzbin = sabnzbd.CFG['categories'][ucat]['newzbin'] + if type(newzbin) != type([]): + newzbin = [newzbin] + except: + newzbin = [] + for name in newzbin: + if name.lower() == cat.lower(): + if name.find('.') < 0: + logging.debug('[%s] Convert newzbin-cat "%s" to user-cat "%s"', __NAME__, cat, ucat) + else: + logging.debug('[%s] Convert group "%s" to user-cat "%s"', __NAME__, cat, ucat) + newcat = ucat + found = True + break + if found: break + return newcat diff --git a/main/sabnzbd/postproc.py b/main/sabnzbd/postproc.py index 3488617..bc41c54 100644 --- a/main/sabnzbd/postproc.py +++ b/main/sabnzbd/postproc.py @@ -79,6 +79,7 @@ class PostProcessor(Thread): ## Get the job flags flagRepair, flagUnpack, flagDelete = nzo.get_repair_opts() script = nzo.get_script() + group = nzo.get_group() cat = nzo.get_cat() ## Collect the par files @@ -230,7 +231,7 @@ class PostProcessor(Thread): if os.path.exists(script): nzo.set_status("Running Script...") nzo.set_unpackstr('=> Running user script %s' % script, '[USER-SCRIPT]', 5) - ext_out = external_processing(script, workdir_complete, filename, dirname, cat) + ext_out = external_processing(script, workdir_complete, filename, dirname, cat, group) fname = MakeLogFile(filename, ext_out) ## Email the results