Exemple #1
0
def walkDir(dir,
            silent=False,
            preserveRelative=False,
            tmdbid=None,
            imdbid=None,
            tvdbid=None,
            tag=True,
            optionsOnly=False):
    files = []
    mp = MediaProcessor(settings, logger=log)
    for r, d, f in os.walk(dir):
        for file in f:
            files.append(os.path.join(r, file))
    for filepath in files:
        info = mp.isValidSource(filepath)
        if info:
            log.info("Processing file %s" % (filepath))
            relative = os.path.split(os.path.relpath(
                filepath, dir))[0] if preserveRelative else None
            if optionsOnly:
                displayOptions(filepath)
                continue
            try:
                processFile(filepath,
                            mp,
                            info=info,
                            relativePath=relative,
                            silent=silent,
                            tag=tag,
                            tmdbid=tmdbid,
                            tvdbid=tvdbid,
                            imdbid=imdbid)
            except SkipFileException:
                log.debug("Skipping file %s." % filepath)
def walkDir(dir, settings, silent=False, preserveRelative=False, tmdbid=None, imdbid=None, tvdbid=None, tag=True, optionsOnly=False, processedList=None, processedArchive=None):
    files = []
    error = []
    mp = MediaProcessor(settings, logger=log)
    for r, d, f in os.walk(dir):
        for file in f:
            files.append(os.path.join(r, file))
    for filepath in files:
        info = mp.isValidSource(filepath)
        if info:
            log.info("Processing file %s" % (filepath))
            relative = os.path.split(os.path.relpath(filepath, dir))[0] if preserveRelative else None
            if optionsOnly:
                displayOptions(filepath, settings)
                continue
            try:
                processFile(filepath, mp, info=info, relativePath=relative, silent=silent, tag=tag, tmdbid=tmdbid, tvdbid=tvdbid, imdbid=imdbid, processedList=processedList, processedArchive=processedArchive)
            except SkipFileException:
                log.debug("Skipping file %s." % filepath)
            except KeyboardInterrupt:
                break
            except:
                log.exception("Error processing file %s." % filepath)
                error.append(filepath)
    if error:
        log.error("Script failed to process the following files:")
        for e in error:
            log.error(e)
            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:
                log.exception("Unable to make output directory %s." %
                              settings.output_dir)

        mp = MediaProcessor(settings)

        if single_file:
            # single file
            inputfile = content_path
            info = mp.isValidSource(inputfile)
            if info:
                log.info("Processing file %s." % inputfile)
                try:
                    output = mp.process(inputfile,
                                        reportProgress=True,
                                        info=info)
                    if not output:
                        log.error(
                            "No output file generated for single torrent download."
                        )
                        sys.exit(1)
                except:
                    log.exception("Error converting file %s." % inputfile)
        else:
            log.debug("Processing multiple files.")
Exemple #4
0
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))