Beispiel #1
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('-tv',
                        '--tvdbid',
                        help="Set the TVDB ID for a tv show")
    parser.add_argument('-s', '--season', help="Specifiy the season number")
    parser.add_argument('-e', '--episode', help="Specify the episode number")
    parser.add_argument('-imdb',
                        '--imdbid',
                        help="Specify the IMDB ID for a movie")
    parser.add_argument('-tmdb',
                        '--tmdbid',
                        help="Specify theMovieDB ID for a movie")
    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(
        '-cmp4',
        '--convertmp4',
        action='store_true',
        help=
        "Overrides convert-mp4 setting in autoProcess.ini enabling the reprocessing of mp4 files"
    )
    parser.add_argument(
        '-m',
        '--moveto',
        help=
        "Override move-to value setting in autoProcess.ini changing the final destination of the file"
    )

    args = vars(parser.parse_args())

    # Setup the silent mode
    silent = args['auto']
    tag = True

    print("%sbit Python." % (struct.calcsize("P") * 8))

    # Settings overrides
    if (args['config']):
        if os.path.exists(args['config']):
            print('Using configuration file "%s"' % (args['config']))
            settings = ReadSettings(os.path.split(args['config'])[0],
                                    os.path.split(args['config'])[1],
                                    logger=log)
        elif os.path.exists(
                os.path.join(os.path.dirname(sys.argv[0]), args['config'])):
            print('Using configuration file "%s"' % (args['config']))
            settings = ReadSettings(os.path.dirname(sys.argv[0]),
                                    args['config'],
                                    logger=log)
        else:
            print(
                'Configuration file "%s" not present, using default autoProcess.ini'
                % (args['config']))
    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['convertmp4']):
        settings.processMP4 = True
        print("Reprocessing of MP4 files enabled")
    if (args['notag']):
        settings.tagfile = False
        print("No-tagging enabled")
    if (args['nopost']):
        settings.postprocess = False
        print("No post processing 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")

    tvdbid = int(args['tvdbid']) if args['tvdbid'] else None
    if os.path.isdir(path):
        walkDir(path,
                silent,
                tvdbid=tvdbid,
                preserveRelative=args['preserveRelative'],
                tag=settings.tagfile)
    elif (os.path.isfile(path)
          and MkvtoMp4(settings, logger=log).validSource(path)):
        if (not settings.tagfile):
            tagdata = None
        elif (args['tvdbid'] and not (args['imdbid'] or args['tmdbid'])):
            season = int(args['season']) if args['season'] else None
            episode = int(args['episode']) if args['episode'] else None
            if (tvdbid and season and episode):
                tagdata = [3, tvdbid, season, episode]
            else:
                tagdata = getinfo(path, silent=silent, tvdbid=tvdbid)
        elif ((args['imdbid'] or args['tmdbid']) and not args['tvdbid']):
            if (args['imdbid']):
                imdbid = args['imdbid']
                tagdata = [1, imdbid]
            elif (args['tmdbid']):
                tmdbid = int(args['tmdbid'])
                tagdata = [2, tmdbid]
        else:
            tagdata = getinfo(path, silent=silent, tvdbid=tvdbid)
        processFile(path, tagdata)
    else:
        try:
            print("File %s is not in the correct format" % (path))
        except:
            print("File is not in the correct format")
Beispiel #2
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(
        '-cmp4',
        '--convertmp4',
        action='store_true',
        help=
        "Overrides convert-mp4 setting in autoProcess.ini enabling the reprocessing of mp4 files"
    )
    parser.add_argument(
        '-fc',
        '--forceconvert',
        action='store_true',
        help=
        "Overrides force-convert setting in autoProcess.ini and also enables convert-mp4 if true forcing the conversion of mp4 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")

    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__)

    # Settings overrides
    if (args['config']):
        if os.path.exists(args['config']):
            settings = ReadSettings(args['config'], logger=log)
        elif 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['convertmp4']):
        settings.processMP4 = True
        print("Reprocessing of MP4 files enabled")
    if (args['forceconvert']):
        settings.forceConvert = True
        settings.processMP4 = True
        print(
            "Force conversion of mp4 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("mkvtomp4").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)):
        converter = MkvtoMp4(settings, logger=log)
        info = converter.isValidSource(path)
        if info:
            if (args['optionsonly']):
                displayOptions(path)
                return
            if not settings.tagfile:
                processFile(path, None, converter, info=info)
            else:
                try:
                    tagdata = getInfo(path,
                                      silent=silent,
                                      tmdbid=args.get('tmdbid'),
                                      tvdbid=args.get('tvdbid'),
                                      imdbid=args.get('imdbid'),
                                      season=args.get('season'),
                                      episode=args.get('episode'))
                    processFile(path, tagdata, converter, info=info)
                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))
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('-tv', '--tvdbid', help="Set the TVDB ID for a tv show")
    parser.add_argument('-s', '--season', help="Specifiy the season number")
    parser.add_argument('-e', '--episode', help="Specify the episode number")
    parser.add_argument('-imdb', '--imdbid', help="Specify the IMDB ID for a movie")
    parser.add_argument('-tmdb', '--tmdbid', help="Specify theMovieDB ID for a movie")
    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('-cmp4', '--convertmp4', action='store_true', help="Overrides convert-mp4 setting in autoProcess.ini enabling the reprocessing of mp4 files")

    args = vars(parser.parse_args())

    #Setup the silent mode
    silent = args['auto']
    tag = True

    print("%sbit Python." % (struct.calcsize("P") * 8))

    #Settings overrides
    if(args['config']):
        if os.path.exists(args['config']):
            print('Using configuration file "%s"' % (args['config']))
            settings = ReadSettings(os.path.split(args['config'])[0], os.path.split(args['config'])[1], logger=log)
        elif os.path.exists(os.path.join(os.path.dirname(sys.argv[0]),args['config'])):
            print('Using configuration file "%s"' % (args['config']))
            settings = ReadSettings(os.path.dirname(sys.argv[0]), args['config'], logger=log)
        else:
            print('Configuration file "%s" not present, using default autoProcess.ini' % (args['config']))
    if (args['nomove']):
        settings.output_dir = None
        settings.moveto = None
        print("No-move enabled")
    if (args['nocopy']):
        settings.copyto = None
        print("No-copy enabled")
    if (args['nodelete']):
        settings.delete = False
        print("No-delete enabled")
    if (args['convertmp4']):
        settings.processMP4 = True
        print("Reprocessing of MP4 files enabled")
    if (args['notag']):
        settings.tagfile = False
        print("No-tagging enabled")
    if (args['nopost']):
        settings.postprocess = False
        print("No post processing enabled")

    #Establish the path we will be working with
    if (args['input']):
        path = str(args['input']).decode(locale.getpreferredencoding())
        try:
            path = glob.glob(path)[0]
        except:
            pass
    else:
        path = getValue("Enter path to file")

    if os.path.isdir(path):
        tvdbid = int(args['tvdbid']) if args['tvdbid'] else None
        walkDir(path, silent, tvdbid=tvdbid, preserveRelative=args['preserveRelative'], tag=settings.tagfile)
    elif (os.path.isfile(path) and MkvtoMp4(settings, logger=log).validSource(path)):
        if (not settings.tagfile):
            tagdata = None
        elif (args['tvdbid'] and not (args['imdbid'] or args['tmdbid'])):
            tvdbid = int(args['tvdbid']) if args['tvdbid'] else None
            season = int(args['season']) if args['season'] else None
            episode = int(args['episode']) if args['episode'] else None
            if (tvdbid and season and episode):
                tagdata = [3, tvdbid, season, episode]
            else:
                tagdata = getinfo(path, silent=silent, tvdbid=tvdbid)
        elif ((args['imdbid'] or args['tmdbid']) and not args['tvdbid']):
            if (args['imdbid']):
                imdbid = args['imdbid']
                tagdata = [1, imdbid]
            elif (args['tmdbid']):
                tmdbid = int(args['tmdbid'])
                tagdata = [2, tmdbid]
        else:
            tagdata = getinfo(path, silent=silent)
        processFile(path, tagdata)
    else:
        try:
            print("File %s is not in the correct format" % (path))
        except:
            print("File is not in the correct format")
def main_functions(stop_event):
    try:
        global settings
        settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini", logger=log)
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        
        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('-r', '--readonly', action="store_true", help='Read all data from files in the directory provided, and list them in a file')
        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('-tv', '--tvdbid', help="Set the TVDB ID for a tv show")
        parser.add_argument('-s', '--season', help="Specifiy the season number")
        parser.add_argument('-o', '--outdir', help="Specifiy the output directory")
        parser.add_argument('-e', '--episode', help="Specify the episode number")
        parser.add_argument('-imdb', '--imdbid', help="Specify the IMDB ID for a movie")
        parser.add_argument('-tmdb', '--tmdbid', help="Specify theMovieDB ID for a movie")
        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('-cmp4', '--convertmp4', action='store_true', help="Overrides convert-mp4 setting in autoProcess.ini enabling the reprocessing of mp4 files")
        parser.add_argument('-mp', '--maxproc', help="Specify the max amount of concurrent scripts can happen. Passmark score of your CPU / 2000 is a good baseline.")
        parser.add_argument('-m', '--moveto', help="Override move-to value setting in autoProcess.ini changing the final destination of the file")
        parser.add_argument('-fc', '--forceConvert', action='store_true', help="Override video copying and force encoding, useful for files that have timescale issues.") 

        args = vars(parser.parse_args())

        # Setup the silent mode
        silent = args['auto']
        tag = True

        #Concurrent
        if not args['maxproc'] == None:
            checkForSpot(args['maxproc'])


        # Settings overrides
        if(args['config']):
            if os.path.exists(args['config']):
                print('Using configuration file "%s"' % (args['config']))
                settings = ReadSettings(os.path.split(args['config'])[0], os.path.split(args['config'])[1], logger=log)
            elif os.path.exists(os.path.join(os.path.dirname(sys.argv[0]), args['config'])):
                print('Using configuration file "%s"' % (args['config']))
                settings = ReadSettings(os.path.dirname(sys.argv[0]), args['config'], logger=log)
            else:
                print('Configuration file "%s" not present, using default autoProcess.ini' % (args['config']))

        # IF READONLY IS SET, WE WILL ONLY DO THAT. WE WILL NOT USE ANY OTHER CMD ARGUMENT GIVEN (EXCEPT CONFIG)
        if (args['readonly']):
            log.debug("Reading info about files only..Ignoring all other command arguments..")
            readonly = True
        else:
            readonly = False
            if (args['outdir']):
                settings.output_dir = os.path.normpath(args['outdir'])
                settings.create_subdirectories = False
                print("new output directory: %s. Setting create_subdirectories False" % (settings.output_dir))
            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['convertmp4']):
                settings.processMP4 = True
                print("Reprocessing of MP4 files enabled")
            if (args['notag']):
                settings.tagfile = False
                print("No-tagging enabled")
            if (args['nopost']):
                settings.postprocess = False
                print("No post processing enabled")
            if (args['forceConvert']):
                settings.forceConvert = True

        # 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 readonly:
            getFileInfo(path, stop_event)
        else:
            tvdbid = int(args['tvdbid']) if args['tvdbid'] else None
            if os.path.isdir(path):
                walkDir(path, stop_event, silent, tvdbid=tvdbid, preserveRelative=args['preserveRelative'], tag=settings.tagfile)
            elif (os.path.isfile(path) and MkvtoMp4(settings, logger=log).validSource(path)):
                if (not settings.tagfile):
                    tagdata = None
                elif (args['tvdbid'] and not (args['imdbid'] or args['tmdbid'])):
                    season = int(args['season']) if args['season'] else None
                    episode = int(args['episode']) if args['episode'] else None
                    if (tvdbid and season and episode):
                        tagdata = [3, tvdbid, season, episode]
                    else:
                        tagdata = getinfo(path, silent=silent, tvdbid=tvdbid)
                elif ((args['imdbid'] or args['tmdbid']) and not args['tvdbid']):
                    if (args['imdbid']):
                        imdbid = args['imdbid']
                        tagdata = [1, imdbid]
                    elif (args['tmdbid']):
                        tmdbid = int(args['tmdbid'])
                        tagdata = [2, tmdbid]
                else:
                    tagdata = getinfo(path, silent=silent, tvdbid=tvdbid)
                
                processFile(path, tagdata, stop_event, None)
            elif (os.path.isfile(path)):
                try:
                    with open(path) as f:
                        content = f.readlines()
                        content = [x.strip() for x in content]
                        contentCopy = list(content)
                        contentLen = len(content)
                        print("TOTAL FILES TO CONVERT: %s" % contentLen)
                        count = 0
                    
                    try:            
                        for x in content:
                            currFile = x;
                            updatedCount = percentage(count, contentLen)
                            print("Completion: %%%s" % round(updatedCount, 2), end='\r')    
                            
                            if MkvtoMp4(settings, logger=log).validSource(currFile):
                                if (not settings.tagfile):
                                    tagdata = None
                                elif (args['tvdbid'] and not (args['imdbid'] or args['tmdbid'])):
                                    tvdbid = int(args['tvdbid']) if args['tvdbid'] else None
                                    season = int(args['season']) if args['season'] else None
                                    episode = int(args['episode']) if args['episode'] else None
                                    if (tvdbid and season and episode):
                                        tagdata = [3, tvdbid, season, episode]
                                    else:
                                        tagdata = getinfo(currFile, silent=silent, tvdbid=tvdbid)
                                elif ((args['imdbid'] or args['tmdbid']) and not args['tvdbid']):
                                    if (args['imdbid']):
                                        imdbid = args['imdbid']
                                        tagdata = [1, imdbid]
                                    elif (args['tmdbid']):
                                        tmdbid = int(args['tmdbid'])
                                        tagdata = [2, tmdbid]
                                else:
                                    tagdata = getinfo(currFile, silent=silent)
                                
                                print("PROCCESSING: %s" % (currFile))
                                processFile(currFile, tagdata, stop_event)
                                
                                count += 1
                                print("removing %s from file..list length before: %s" % (currFile, len(contentCopy)))
                                contentCopy.remove(currFile)
                                print("list length after: %s" % (len(contentCopy)))
                                
                                data = open(path, "w")
                                for c in contentCopy:
                                       data.write("%s\n" % (c))
                                data.close()
                    except Exception as e:
                        print(e)
      
                except:
                    print("File %s is not in the correct format" % (path))
            else:
                try:
                    print("File %s is not in the correct format" % (path))
                except:
                    print("File is not in the correct format")
    except:
        if stop_event.is_set():
            print("Manually stopping conversion...")
        else:
            raise Exception("".join(traceback.format_exception(*sys.exc_info())))
    
    #print("done with conversions.")
    stop_event.set()