def process(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None, failureLink=None): if core.SAFE_MODE and inputDirectory == core.NZB_DEFAULTDIR: logger.error( 'The input directory:[%s] is the Default Download Directory. Please configure category directories to prevent processing of other media.' % ( inputDirectory)) return [-1, ""] if not download_id and clientAgent == 'sabnzbd': download_id = get_nzoid(inputName) if clientAgent != 'manual' and not core.DOWNLOADINFO: logger.debug('Adding NZB download info for directory %s to database' % (inputDirectory)) myDB = nzbToMediaDB.DBConnection() encoded, inputDirectory1 = CharReplace(inputDirectory) encoded, inputName1 = CharReplace(inputName) controlValueDict = {"input_directory": unicode(inputDirectory1)} newValueDict = {"input_name": unicode(inputName1), "input_hash": unicode(download_id), "input_id": unicode(download_id), "client_agent": unicode(clientAgent), "status": 0, "last_update": datetime.date.today().toordinal() } myDB.upsert("downloads", newValueDict, controlValueDict) # auto-detect section if inputCategory is None: inputCategory = 'UNCAT' usercat = inputCategory section = core.CFG.findsection(inputCategory).isenabled() if section is None: section = core.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())) return [-1, ""] if section: sectionName = section.keys()[0] logger.info('Auto-detected SECTION:%s' % (sectionName)) else: logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % ( inputCategory)) return [-1, ""] try: extract = int(section[usercat]['extract']) except: extract = 0 try: if int(section[usercat]['remote_path']) and not core.REMOTEPATHS: logger.error('Remote Path is enabled for %s:%s but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!' % ( sectionName, inputCategory)) return [-1, ""] except: logger.error('Remote Path %s is not valid for %s:%s Please set this to either 0 to disable or 1 to enable!' % ( section[usercat]['remote_path'], sectionName, inputCategory)) inputName, inputDirectory = convert_to_ascii(inputName, inputDirectory) if extract == 1: logger.debug('Checking for archives to extract in directory: %s' % (inputDirectory)) extractFiles(inputDirectory) logger.info("Calling %s:%s to post-process:%s" % (sectionName, inputCategory, inputName)) if sectionName == "CouchPotato": result = autoProcessMovie().process(sectionName, inputDirectory, inputName, status, clientAgent, download_id, inputCategory, failureLink) elif sectionName in ["SickBeard", "NzbDrone"]: result = autoProcessTV().processEpisode(sectionName, inputDirectory, inputName, status, clientAgent, download_id, inputCategory, failureLink) elif sectionName == "HeadPhones": result = autoProcessMusic().process(sectionName, inputDirectory, inputName, status, clientAgent, inputCategory) elif sectionName == "Mylar": result = autoProcessComics().processEpisode(sectionName, inputDirectory, inputName, status, clientAgent, inputCategory) elif sectionName == "Gamez": result = autoProcessGames().process(sectionName, inputDirectory, inputName, status, clientAgent, inputCategory) elif sectionName == 'UserScript': result = external_script(inputDirectory, inputName, inputCategory, section[usercat]) else: result = [-1, ""] plex_update(inputCategory) if result[0] == 0: if clientAgent != 'manual': # update download status in our DB update_downloadInfoStatus(inputName, 1) if not sectionName in ['UserScript', 'NzbDrone']: # cleanup our processing folders of any misc unwanted files and empty directories cleanDir(inputDirectory, sectionName, inputCategory) return result
def startproc(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None, failureLink=None): if core.SAFE_MODE and inputDirectory == core.NZB_DEFAULTDIR: logger.error( 'The input directory:[{0}] is the Default Download Directory. Please configure category directories to prevent processing of other media.' .format(inputDirectory)) return [-1, ""] if not download_id and clientAgent == 'sabnzbd': download_id = get_nzoid(inputName) if clientAgent != 'manual' and not core.DOWNLOADINFO: logger.debug( 'Adding NZB download info for directory {0} to database'.format( inputDirectory)) myDB = nzbToMediaDB.DBConnection() inputDirectory1 = inputDirectory inputName1 = inputName try: encoded, inputDirectory1 = CharReplace(inputDirectory) encoded, inputName1 = CharReplace(inputName) except: pass controlValueDict = {"input_directory": text_type(inputDirectory1)} newValueDict = { "input_name": text_type(inputName1), "input_hash": text_type(download_id), "input_id": text_type(download_id), "client_agent": text_type(clientAgent), "status": 0, "last_update": datetime.date.today().toordinal() } myDB.upsert("downloads", newValueDict, controlValueDict) # auto-detect section if inputCategory is None: inputCategory = 'UNCAT' usercat = inputCategory section = core.CFG.findsection(inputCategory).isenabled() if section is None: section = core.CFG.findsection("ALL").isenabled() if section is None: logger.error( 'Category:[{0}] 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.' .format(inputCategory)) return [-1, ""] else: usercat = "ALL" if len(section) > 1: logger.error( 'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' .format(inputCategory, section.keys())) return [-1, ""] if section: sectionName = section.keys()[0] logger.info('Auto-detected SECTION:{0}'.format(sectionName)) else: logger.error( "Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!" .format(inputCategory)) return [-1, ""] cfg = dict(core.CFG[sectionName][usercat]) extract = int(cfg.get("extract", 0)) try: if int(cfg.get("remote_path")) and not core.REMOTEPATHS: logger.error( 'Remote Path is enabled for {0}:{1} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!' .format(sectionName, inputCategory)) return [-1, ""] except: logger.error( 'Remote Path {0} is not valid for {1}:{2} Please set this to either 0 to disable or 1 to enable!' .format(core.get("remote_path"), sectionName, inputCategory)) inputName, inputDirectory = convert_to_ascii(inputName, inputDirectory) if extract == 1: logger.debug( 'Checking for archives to extract in directory: {0}'.format( inputDirectory)) extractFiles(inputDirectory) logger.info("Calling Checker to check the Files and Convert them to mp4") result = Filechecker().checkfiles(sectionName, inputDirectory, inputName, status, clientAgent, download_id, inputCategory, failureLink) return result