Browse Source

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.
tags/0.6.0
shypike 17 years ago
parent
commit
bae0b8b44e
  1. 1
      main/Sample-PostProc.cmd
  2. 1
      main/Sample-PostProc.sh
  3. 22
      main/sabnzbd/interface.py
  4. 10
      main/sabnzbd/newsunpack.py
  5. 24
      main/sabnzbd/newzbin.py
  6. 42
      main/sabnzbd/nzbstuff.py
  7. 3
      main/sabnzbd/postproc.py

1
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.

1
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

22
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):

10
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,

24
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

42
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

3
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

Loading…
Cancel
Save