if settings.qBittorrent[ 'actionbefore'] == 'pause': # currently only support pausing log.debug("Sending action %s to qBittorrent" % settings.qBittorrent['actionbefore']) qb.pause(torrent_hash) if settings.qBittorrent['convert']: # Check for custom qBittorrent output_dir if settings.qBittorrent['output_dir']: settings.output_dir = settings.qBittorrent['output_dir'] log.debug("Overriding output_dir to %s." % settings.qBittorrent['output_dir']) # Perform conversion. log.info("Performing conversion") settings.delete = False if not settings.output_dir: # If the user hasn't set an output directory, go up one from the root path and create a directory there as [name]-convert suffix = "convert" settings.output_dir = os.path.abspath( os.path.join(root_path, '..', ("%s-%s" % (re.sub(settings.regex, '_', name), suffix)))) else: settings.output_dir = os.path.join( settings.output_dir, re.sub(settings.regex, '_', name)) if not os.path.exists(settings.output_dir): try: os.makedirs(settings.output_dir) delete_dir = settings.output_dir except:
def main(): global settings parser = argparse.ArgumentParser( description= "Manual conversion and tagging script for sickbeard_mp4_automator") parser.add_argument( '-i', '--input', help='The source that will be converted. May be a file or a directory') parser.add_argument( '-c', '--config', help='Specify an alternate configuration file location') parser.add_argument( '-a', '--auto', action="store_true", help= "Enable auto mode, the script will not prompt you for any further input, good for batch files. It will guess the metadata using guessit" ) parser.add_argument('-s', '--season', help="Specifiy the season number") parser.add_argument('-e', '--episode', help="Specify the episode number") parser.add_argument('-tvdb', '--tvdbid', help="Specify the TVDB ID for media") parser.add_argument('-imdb', '--imdbid', help="Specify the IMDB ID for media") parser.add_argument('-tmdb', '--tmdbid', help="Specify the TMDB ID for media") parser.add_argument( '-nm', '--nomove', action='store_true', help= "Overrides and disables the custom moving of file options that come from output_dir and move-to" ) parser.add_argument( '-nc', '--nocopy', action='store_true', help= "Overrides and disables the custom copying of file options that come from output_dir and move-to" ) parser.add_argument( '-nd', '--nodelete', action='store_true', help="Overrides and disables deleting of original files") parser.add_argument( '-nt', '--notag', action="store_true", help="Overrides and disables tagging when using the automated option") parser.add_argument( '-np', '--nopost', action="store_true", help= "Overrides and disables the execution of additional post processing scripts" ) parser.add_argument( '-pr', '--preserverelative', action='store_true', help= "Preserves relative directories when processing multiple files using the copy-to or move-to functionality" ) parser.add_argument( '-pse', '--processsameextensions', action='store_true', help= "Overrides process-same-extensions setting in autoProcess.ini enabling the reprocessing of files" ) parser.add_argument( '-fc', '--forceconvert', action='store_true', help= "Overrides force-convert setting in autoProcess.ini and also enables process-same-extenions if true forcing the conversion of files" ) parser.add_argument( '-m', '--moveto', help= "Override move-to value setting in autoProcess.ini changing the final destination of the file" ) parser.add_argument( '-oo', '--optionsonly', action="store_true", help= "Display generated conversion options only, do not perform conversion") parser.add_argument( '-cl', '--codeclist', action="store_true", help="Print a list of supported codecs and their paired FFMPEG encoders" ) parser.add_argument('-o', '--original', help="Specify the original source/release filename") args = vars(parser.parse_args()) # Setup the silent mode silent = args['auto'] print("Python %s-bit %s." % (struct.calcsize("P") * 8, sys.version)) print("Guessit version: %s." % guessit.__version__) if args['codeclist']: showCodecs() return # Settings overrides if args['config'] and os.path.exists(args['config']): settings = ReadSettings(args['config'], logger=log) elif args['config'] and os.path.exists( os.path.join(os.path.dirname(sys.argv[0]), args['config'])): settings = ReadSettings(os.path.join(os.path.dirname(sys.argv[0]), args['config']), logger=log) else: settings = ReadSettings(logger=log) if (args['nomove']): settings.output_dir = None settings.moveto = None print("No-move enabled") elif (args['moveto']): settings.moveto = args['moveto'] print("Overriden move-to to " + args['moveto']) if (args['nocopy']): settings.copyto = None print("No-copy enabled") if (args['nodelete']): settings.delete = False print("No-delete enabled") if (args['processsameextensions']): settings.process_same_extensions = True print("Reprocessing of same extensions enabled") if (args['forceconvert']): settings.process_same_extensions = True settings.force_convert = True print( "Force conversion of files enabled. As a result conversion of mp4 files is also enabled" ) if (args['notag']): settings.tagfile = False print("No-tagging enabled") if (args['nopost']): settings.postprocess = False print("No post processing enabled") if (args['optionsonly']): logging.getLogger("resources.mediaprocessor").setLevel( logging.CRITICAL) print("Options only mode enabled") # Establish the path we will be working with if (args['input']): path = (str(args['input'])) try: path = glob.glob(path)[0] except: pass else: path = getValue("Enter path to file") if os.path.isdir(path): walkDir(path, silent=silent, tmdbid=args.get('tmdbid'), tvdbid=args.get('tvdbid'), imdbid=args.get('imdbid'), preserveRelative=args['preserverelative'], tag=settings.tagfile, optionsOnly=args['optionsonly']) elif (os.path.isfile(path)): mp = MediaProcessor(settings, logger=log) info = mp.isValidSource(path) if info: if (args['optionsonly']): displayOptions(path) return try: processFile(path, mp, info=info, silent=silent, tag=settings.tagfile, tmdbid=args.get('tmdbid'), tvdbid=args.get('tvdbid'), imdbid=args.get('imdbid'), season=args.get('season'), episode=args.get('episode'), original=args.get('original')) except SkipFileException: log.debug("Skipping file %s" % path) else: print("File %s is not in a valid format" % (path)) else: print("File %s does not exist" % (path))