コード例 #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)
コード例 #2
0
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)
コード例 #3
0
            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:
                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."
                        )
コード例 #4
0
try:
    inputfile = os.environ.get('radarr_moviefile_path')
    original = os.environ.get('radarr_moviefile_scenename')
    imdbid = os.environ.get('radarr_movie_imdbid')
    tmdbid = os.environ.get('radarr_movie_tmdbid')
    movieid = int(os.environ.get('radarr_movie_id'))
    moviefileid = int(os.environ.get('radarr_moviefile_id'))
    scenename = os.environ.get('radarr_moviefile_scenename')
    releasegroup = os.environ.get('radarr_moviefile_releasegroup')
    moviefile_sourcefolder = os.environ.get('radarr_moviefile_sourcefolder')
except:
    log.exception("Error reading environment variables")
    sys.exit(1)

mp = MediaProcessor(settings)

if settings.Radarr.get('blockreprocess'):
    log.debug("Block reprocess enabled for Radarr")
    settings.process_same_extensions = False

log.debug("Input file: %s." % inputfile)
log.debug("Original name: %s." % original)
log.debug("IMDB ID: %s." % imdbid)
log.debug("TMDB ID: %s." % tmdbid)
log.debug("Radarr Movie ID: %d." % movieid)

try:
    if settings.Radarr.get('rename'):
        # Prevent asynchronous errors from file name changing
        mp.settings.waitpostprocess = True
コード例 #5
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))
コード例 #6
0
def displayOptions(path):
    mp = MediaProcessor(settings)
    log.info(mp.jsonDump(path))
コード例 #7
0
        status = 1
        sys.exit(POSTPROCESS_NONE)

    # Make sure there are no duplicate categories
    if len(categories) != len(set(categories)):
        log.error("Duplicate category detected. Category names must be unique.")
        status = 1
        sys.exit(POSTPROCESS_NONE)

    # All checks done, now launching the script.
    settings = ReadSettings(MP4folder)

    if shouldConvert:
        if output_dir:
            settings.output_dir = output_dir
        mp = MediaProcessor(settings, logger=log)
        ignore = []
        for r, d, f in os.walk(path):
            for files in f:
                inputfile = os.path.join(r, files)
                #DEBUG#print inputfile
                info = mp.isValidSource(inputfile)
                if info and inputfile not in ignore:
                    log.info("Processing file %s." % inputfile)
                    try:
                        output = mp.process(inputfile, info=info, reportProgress=True, progressOutput=progressOutput)
                        if output and output.get('output'):
                            log.info("Successfully processed %s." % inputfile)
                            ignore.append(output.get('output'))
                        else:
                            log.error("Converting file failed %s." % inputfile)
コード例 #8
0
        sys.exit(1)

    if len(categories) != len(set(categories)):
        log.error(
            "Duplicate category detected. Category names must be unique.")
        sys.exit(1)

    if settings.SAB['convert']:
        log.info("Performing conversion")
        # Check for custom uTorrent output_dir
        if settings.SAB['output_dir']:
            settings.output_dir = settings.SAB['output_dir']
            log.debug("Overriding output_dir to %s." %
                      settings.SAB['output_dir'])

        mp = MediaProcessor(settings)
        for r, d, f in os.walk(path):
            for files in f:
                inputfile = os.path.join(r, files)
                info = mp.isValidSource(inputfile)
                if info:
                    log.info("Processing file %s." % inputfile)
                    try:
                        output = mp.process(inputfile, info=info)
                    except:
                        log.exception("Error converting file %s." % inputfile)
                else:
                    log.debug("Ignoring file %s." % inputfile)
        if settings.output_dir:
            path = settings.output_dir
    else:
コード例 #9
0
try:
    settings = ReadSettings()

    if len(sys.argv) > 4:
        inputfile = sys.argv[1]
        original = sys.argv[2]
        tvdb_id = int(sys.argv[3])
        season = int(sys.argv[4])
        episode = int(sys.argv[5])

        log.debug("Input file: %s." % inputfile)
        log.debug("Original name: %s." % original)
        log.debug("TVDB ID: %s." % tvdb_id)
        log.debug("Season: %s episode: %s." % (season, episode))

        mp = MediaProcessor(settings)

        success = mp.fullprocess(inputfile,
                                 MediaType.TV,
                                 tvdbid=tvdb_id,
                                 season=season,
                                 episode=episode,
                                 original=original)
        if success:
            try:
                protocol = "https://" if settings.Sickbeard[
                    'ssl'] else "http://"
                host = settings.Sickbeard['host']  # Server Address
                port = settings.Sickbeard['port']  # Server Port
                apikey = settings.Sickbeard['apikey']  # Sickbeard API key
                webroot = settings.Sickbeard['webroot']  # Sickbeard webroot