diff --git a/TorrentToMedia.py b/TorrentToMedia.py index a3095fb1..51ede50d 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -35,20 +35,29 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, inputCategory, root, nzbtomedia.CATEGORIES) # Confirm the category by parsing directory structure + if inputCategory == "": + inputCategory = "UNCAT" + + usercat = inputCategory + logger.debug("Determined Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) # auto-detect section section = nzbtomedia.CFG.findsection(inputCategory).isenabled() if section is None: - logger.error( - 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for teh appropriate section in your autoProcessMedia.cfg and try again.' % ( - inputCategory)) - return -1 + section = nzbtomedia.CFG.findsection("ALL").isenabled() + if section is None: + logger.error( + 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % ( + inputCategory)) + return -1 + else: + usercat = "ALL" 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.' % ( - inputCategory, section.keys())) + usercat, section.keys())) return -1 if section: @@ -60,50 +69,44 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, return -1 try: - Torrent_NoLink = int(section[inputCategory]["Torrent_NoLink"]) + Torrent_NoLink = int(section[usercat]["Torrent_NoLink"]) except: Torrent_NoLink = 0 try: - extract = int(section[inputCategory]['extract']) + extract = int(section[usercat]['extract']) except: extract = 0 - if not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES: + if sectionName == "UserScript": try: - nzbtomedia.USER_SCRIPT_MEDIAEXTENSIONS = (nzbtomedia.CFG[sectionName][inputCategory]["user_script_mediaExtensions"]) + nzbtomedia.USER_SCRIPT_MEDIAEXTENSIONS = section[usercat]["user_script_mediaExtensions"] except: nzbtomedia.USER_SCRIPT_MEDIAEXTENSIONS = None try: - nzbtomedia.USER_SCRIPT = nzbtomedia.CFG[sectionName][inputCategory]["user_script_path"] + nzbtomedia.USER_SCRIPT = section[usercat]["user_script_path"] except: nzbtomedia.USER_SCRIPT = None try: - nzbtomedia.USER_SCRIPT_PARAM = (nzbtomedia.CFG[sectionName][inputCategory]["user_script_param"]) + nzbtomedia.USER_SCRIPT_PARAM = section[usercat]["user_script_param"] except: nzbtomedia.USER_SCRIPT_PARAM = None try: - nzbtomedia.USER_SCRIPT_SUCCESSCODES = (nzbtomedia.CFG[sectionName][inputCategory]["user_script_successCodes"]) + nzbtomedia.USER_SCRIPT_SUCCESSCODES = section[usercat]["user_script_successCodes"] except: nzbtomedia.USER_SCRIPT_SUCCESSCODES = 0 try: - nzbtomedia.USER_SCRIPT_CLEAN = int(nzbtomedia.CFG[sectionName][inputCategory]["user_script_clean"]) + nzbtomedia.USER_SCRIPT_CLEAN = int(section[usercat]["user_script_clean"]) except: nzbtomedia.USER_SCRIPT_CLEAN = 1 try: - nzbtomedia.USER_SCRIPT_RUNONCE = int(nzbtomedia.CFG[sectionName][inputCategory]["user_script_runOnce"]) + nzbtomedia.USER_SCRIPT_RUNONCE = int(section[usercat]["user_script_runOnce"]) except: nzbtomedia.USER_SCRIPT_RUNONCE = 1 if clientAgent != 'manual': nzbtomedia.pause_torrent(clientAgent, inputHash, inputID, inputName) - processCategories = nzbtomedia.CATEGORIES - processOnly = processCategories - - if inputCategory == "": - inputCategory = "UNCAT" - outputDestination = os.path.normpath( nzbtomedia.os.path.join(nzbtomedia.OUTPUTDIRECTORY, inputCategory, nzbtomedia.sanitizeName(inputName))) @@ -115,15 +118,6 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, inputDirectory)) return -1 - if not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES: # if None, we only process the 5 listed. - if "ALL" in nzbtomedia.USER_SCRIPT_CATEGORIES: # All defined categories - processOnly = nzbtomedia.CATEGORIES - processOnly.extend(nzbtomedia.USER_SCRIPT_CATEGORIES) # Adds all categories to be processed by userscript. - - if not inputCategory in processOnly: - logger.info("No processing to be done for category: %s. Exiting" % (inputCategory)) - return - logger.debug("Scanning files in directory: %s" % (inputDirectory)) if sectionName == 'HeadPhones': @@ -200,16 +194,11 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, if not sectionName in ['CouchPotato', 'SickBeard', 'NzbDrone']: status = 0 - result = 0 - if (inputCategory in nzbtomedia.USER_SCRIPT_CATEGORIES and not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES) or ( - "ALL" in nzbtomedia.USER_SCRIPT_CATEGORIES and not inputCategory in processCategories): - logger.info("Processing user script %s." % (nzbtomedia.USER_SCRIPT)) - result = external_script(outputDestination, inputName, inputCategory) - elif status != 0: - logger.error("Something failed! Please check logs. Exiting") - return status + logger.info("Calling %s:%s to post-process:%s" % (sectionName, usercat, inputName)) - logger.info("Calling %s:%s to post-process:%s" % (sectionName, inputCategory, inputName)) + result = 0 + if sectionName in ["UserScript"]: + result = external_script(outputDestination, inputName, inputCategory) if sectionName == 'CouchPotato': result = nzbtomedia.autoProcessMovie().process(sectionName,outputDestination, inputName, status, clientAgent, inputHash, @@ -245,6 +234,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, def external_script(outputDestination, torrentName, torrentLabel): + if nzbtomedia.USER_SCRIPT is None: # do nothing and return success. + return 0 final_result = 0 # start at 0. num_files = 0 for dirpath, dirnames, filenames in os.walk(outputDestination): diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index fb92cb3b..14779973 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -260,10 +260,12 @@ [UserScript] #Use user_script for uncategorized downloads #Set the categories to use external script. - #Use "UNCAT" to process non-category downloads, and "ALL" for all. Set to "NONE" to disable external script. + #Use "UNCAT" to process non-category downloads, and "ALL" for all defined categories. [[UNCAT]] #Enable/Disable this subsection category enabled = 0 + Torrent_NoLink = 0 + extract = 1 #What extension do you want to process? Specify all the extension, or use "ALL" to process all files. user_script_mediaExtensions = .mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg #Specify the path to your custom script diff --git a/nzbtomedia/__init__.py b/nzbtomedia/__init__.py index b86df7e0..bafce00f 100644 --- a/nzbtomedia/__init__.py +++ b/nzbtomedia/__init__.py @@ -115,7 +115,6 @@ METACONTAINER = [] SECTIONS = [] CATEGORIES = [] -USER_SCRIPT_CATEGORIES = [] TRANSCODE = None FFMPEG_PATH = None @@ -155,7 +154,7 @@ def initialize(section=None): NZBTOMEDIA_BRANCH, NZBTOMEDIA_VERSION, NEWEST_VERSION, NEWEST_VERSION_STRING, VERSION_NOTIFY, SYS_ARGV, CFG, \ SABNZB_NO_OF_ARGUMENTS, SABNZB_0717_NO_OF_ARGUMENTS, CATEGORIES, TORRENT_CLIENTAGENT, USELINK, OUTPUTDIRECTORY, NOFLATTEN, \ UTORRENTPWD, UTORRENTUSR, UTORRENTWEBUI, DELUGEHOST, DELUGEPORT, DELUGEUSR, DELUGEPWD, TRANSMISSIONHOST, TRANSMISSIONPORT, \ - TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, METACONTAINER, SECTIONS, USER_SCRIPT_CATEGORIES, \ + TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, METACONTAINER, SECTIONS, \ __INITIALIZED__, AUTO_UPDATE, APP_FILENAME, USER_DELAY, APP_NAME, TRANSCODE, GIT_PATH, GIT_USER, \ GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \ DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, LOG_DB, \ @@ -352,9 +351,6 @@ def initialize(section=None): if not CHECK_MEDIA: # allow users to bypass this. FFPROBE = None - # userscript - map(USER_SCRIPT_CATEGORIES.append, ([subsections[0] for subsections in CFG['UserScript'].items()])) - # check for script-defied section and if None set to allow sections SECTIONS = CFG[tuple(x for x in CFG if CFG[x].sections and CFG[x].isenabled()) if not section else (section,)] map(CATEGORIES.extend,([subsection.sections for section,subsection in SECTIONS.items()]))