예제 #1
0
def main():
    colorama.init()

    config = load_config_file()
    args, wtf = create_args().parse_known_args()
    if (wtf):
        logger.error('Unknown argument %s', wtf[0])
        sys.exit(1)
    init_logging(args.verbose)

    # don't proceed if paths aren't right/programs missing
    pre_check(args, config)

    try:
        working_dir = config.get(APP_NAME, 'working_dir')
    except configparser.Error:
        working_dir = None

    if working_dir:
        if not os.path.isdir(working_dir):
            create_dir(working_dir)
        tempfile.tempdir = working_dir

    tmp_dir = tempfile.mkdtemp()
    logger.debug('Episode temp folder: %s', tmp_dir)
    atexit.register(delete_temp, tmp_dir)

    start, end, special = validate_args(args)
    print(WELCOME_MSG)

    for ep in range(start, end + 1):
        start_time = time.clock()
        episode = Episode(ep, config, args, tmp_dir, special)

        if not args.no_demux:
            episode.demux()
        else:
            if args.sub_only:
                detect_streams(os.path.join(config.get(APP_NAME, 'output_dir'),
                               args.series,
                               str(ep if not special else special).zfill(3),
                               'R1', 'Subtitle.idx'))
        if not args.no_retime:
            episode.retime_subs()
            episode.retime_audio()
        if not args.no_demux and args.no_mux:
            # move files to destination folder
            episode.move_demuxed_files()
        if not args.no_mux:
            episode.mux()

        if args.make_avs:
            # only works on files generated with --no-mux
            episode.make_avs()

        delete_temp(episode.temp_dir)
        elapsed = time.clock() - start_time
        logger.debug('Elapsed time: %s seconds', elapsed)
    logger.info('Finished!')