Exemple #1
0
def main():
    # Ensure a valid config file
    ReadSettings()

    if not os.path.isfile(autoProcess):
        logging.error("autoProcess.ini does not exist")
        sys.exit(1)

    safeConfigParser = configparser.ConfigParser()
    safeConfigParser.read(autoProcess)

    # Set FFMPEG/FFProbe Paths
    safeConfigParser.set("Converter", "ffmpeg", "/usr/local/bin/ffmpeg")
    safeConfigParser.set("Converter", "ffprobe", "/usr/local/bin/ffprobe")

    section = os.environ.get("SMA_RS")
    if section and os.path.isfile(xml):
        tree = ET.parse(xml)
        root = tree.getroot()
        port = root.find("Port").text
        try:
            sslport = root.find("SslPort").text
        except:
            sslport = port
        webroot = root.find("UrlBase").text
        webroot = webroot if webroot else ""
        ssl = root.find("EnableSsl").text
        ssl = ssl.lower() in ["true", "yes", "t", "1", "y"] if ssl else False
        apikey = root.find("ApiKey").text

        # Set values from config.xml
        safeConfigParser.set(section, "apikey", apikey)
        safeConfigParser.set(section, "ssl", str(ssl))
        safeConfigParser.set(section, "port", sslport if ssl else port)
        safeConfigParser.set(section, "webroot", webroot)

        # Set IP from environment variable
        ip = os.environ.get("HOST")
        if ip:
            safeConfigParser.set(section, "host", ip)
        else:
            safeConfigParser.set(section, "host", "127.0.0.1")

    fp = open(autoProcess, "w")
    safeConfigParser.write(fp)
    fp.close()
log.info("qBittorrent post processing started.")

if len(sys.argv) != 7:
    log.error(
        "Not enough command line parameters present, are you launching this from qBittorrent?"
    )
    log.error(
        "#Args: %L %T %R %F %N %I Category, Tracker, RootPath, ContentPath , TorrentName, InfoHash"
    )
    log.error("Length was %s" % str(len(sys.argv)))
    log.error(str(sys.argv[1:]))
    sys.exit(1)

try:
    settings = ReadSettings()
    label = sys.argv[1].lower().strip()
    root_path = str(sys.argv[3])
    content_path = str(sys.argv[4])
    name = sys.argv[5]
    torrent_hash = sys.argv[6]
    categories = [
        settings.qBittorrent['sb'], settings.qBittorrent['sonarr'],
        settings.qBittorrent['radarr'], settings.qBittorrent['sr'],
        settings.qBittorrent['bypass']
    ]
    path_mapping = settings.qBittorrent['path-mapping']

    log.debug("Root Path: %s." % root_path)
    log.debug("Content Path: %s." % content_path)
    log.debug("Label: %s." % label)
Exemple #3
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))
Exemple #4
0
        sys.exit(POSTPROCESS_NONE)

    # Make sure one of the appropriate categories is set
    if len([x for x in categories if x.startswith(category)]) < 1:
        log.error("Post-Process: No valid category detected. Category was %s." % (category))
        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)