diff --git a/TorrentToMedia.py b/TorrentToMedia.py index ea1eba67..eaeb69f6 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -39,7 +39,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, logger.debug("Determined Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) # auto-detect section - section = nzbtomedia.CFG.findsection(inputCategory) + section = nzbtomedia.CFG.findsection(inputCategory).isenabled() if len(section) > 1: logger.error( 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % ( diff --git a/nzbToMedia.py b/nzbToMedia.py index 3cc46876..663e73fe 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -303,7 +303,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down myDB.upsert("downloads", newValueDict, controlValueDict) # auto-detect section - section = nzbtomedia.CFG.findsection(inputCategory) + section = nzbtomedia.CFG.findsection(inputCategory).isenabled() if len(section) > 1: logger.error( 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % ( @@ -485,7 +485,7 @@ def main(args, section=None): except: download_id = None - if not clientAgent.lower() in (nzbtomedia.NZB_CLIENTS or 'manual'): + if not clientAgent.lower() in (nzbtomedia.NZB_CLIENTS, 'manual'): continue results = process(dirName, os.path.basename(dirName), 0, clientAgent=clientAgent, diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index 4bd65b37..c973171d 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -12,7 +12,7 @@ from nzbtomedia.transcoder import transcoder class autoProcessTV: def processEpisode(self, section, dirName, inputName=None, failed=False, clientAgent = "manual", inputCategory=None): # auto-detect correct fork - fork, fork_params = autoFork(inputCategory) + fork, fork_params = autoFork(section, inputCategory) # Check video files for corruption status = int(failed) diff --git a/nzbtomedia/nzbToMediaAutoFork.py b/nzbtomedia/nzbToMediaAutoFork.py index 07f738f6..9b9fea94 100644 --- a/nzbtomedia/nzbToMediaAutoFork.py +++ b/nzbtomedia/nzbToMediaAutoFork.py @@ -3,14 +3,8 @@ import nzbtomedia import requests from nzbtomedia import logger -def autoFork(inputCategory): +def autoFork(section, inputCategory): # auto-detect correct section - section = nzbtomedia.CFG.findsection(inputCategory) - if not section: - logger.error( - "We were unable to find a section for category %s, please check your autoProcessMedia.cfg file." % inputCategory) - return 1 - # config settings try: host = nzbtomedia.CFG[section][inputCategory]["host"] diff --git a/nzbtomedia/nzbToMediaConfig.py b/nzbtomedia/nzbToMediaConfig.py index 070f49a2..9cff604d 100644 --- a/nzbtomedia/nzbToMediaConfig.py +++ b/nzbtomedia/nzbToMediaConfig.py @@ -1,5 +1,6 @@ import os import shutil +import copy import nzbtomedia from configobj import * @@ -9,33 +10,36 @@ class Section(configobj.Section): def isenabled(section): # checks if subsection enabled, returns true/false if subsection specified otherwise returns true/false in {} if not section.sections: - if not int(section['enabled']) == 1: - return + if int(section['enabled']) == 1: + return section else: - for section_name, subsections in section.items(): + to_return = copy.deepcopy(section) + for section_name, subsections in to_return.items(): if subsections.sections: for subsection in subsections: if not int(subsections[subsection]['enabled']) == 1: - subsections.pop(subsection) + del subsections[subsection] else: if not int(subsections['enabled']) == 1: - section.pop(section_name) + del to_return[section_name] - if len(section[section_name]) == 0: - section.pop(section_name) - return section + if len(to_return[section_name]) == 0: + del to_return[section_name] + return to_return def findsection(section, key): - for subsection in section: - if key not in section[subsection]: - section.pop(subsection) - return section + to_return = copy.deepcopy(section) + for subsection in to_return: + if key not in to_return[subsection]: + del to_return[subsection] + return to_return def __getitem__(self, key): if key in self.keys(): return dict.__getitem__(self, key) - for section, subsections in self.items(): + to_return = copy.deepcopy(self) + for section, subsections in to_return.items(): if section in key: continue if isinstance(subsections, Section) and subsections.sections: @@ -45,15 +49,15 @@ class Section(configobj.Section): if key in options: return options[key] - subsections.pop(subsection) + del subsections[subsection] else: if section not in key: - self.pop(section) + del to_return[section] if len(subsections) == 0: - self.pop(section) + del to_return[section] - return self + return to_return class ConfigObj(configobj.ConfigObj, Section): def __init__(self, *args, **kw): diff --git a/tests/general.py b/tests/general.py index 424d0a56..580e2190 100644 --- a/tests/general.py +++ b/tests/general.py @@ -8,11 +8,6 @@ from nzbtomedia.nzbToMediaUtil import get_downloadInfo # Initialize the config nzbtomedia.initialize() -EXTENSIONS = [re.compile('.r\d{2}$', re.I), - re.compile('.part\d+.rar$', re.I), - re.compile('.rar$', re.I)] -EXTENSIONS += [re.compile('%s$' % ext, re.I) for ext in nzbtomedia.COMPRESSEDCONTAINER] - test = nzbtomedia.CFG['HeadPhones']['music'] section = nzbtomedia.CFG.findsection('tv').isenabled() print section \ No newline at end of file