def _compile_input(series_config, folders, series): full_arguments = "-f {input_chapter_folder}*[!waifud].* " \ "-od {compiled_chapter_folder} " \ "--clean".format(input_chapter_folder=folders.input_chapter, compiled_chapter_folder=folders.compiled_chapter, chapter_folder_name=folders.chapter_folder_name, series=series) if len(series_config.arguments) > 0: full_arguments += " " + series_config.arguments logger.info("Running comicom with final arguments: " + full_arguments) compiler.run(arguments.parse(full_arguments))
def _ensure_input_images(series_config, directories, chapter, skip_download): if len(glob.glob(directories.input_chapter + "*.*")) > 0: logger.info( "Found existing items in input folder, skipping download: " + str(glob.glob(directories.input_chapter))) return True elif skip_download or len(series_config.mangapy_source) > 0: logger.info("Using mangapy to download from: " + series_config.mangapy_source) return downloader.via_mangapy(series_config.mangapy_source, chapter, directories.input_chapter) else: logger.info("Sourcing input images from: " + series_config.local_input) local_files = glob.glob(series_config.local_input) if len(local_files) == 0: logger.info("No files found in local directory") return False else: if not os.path.exists(directories.input_chapter): os.mkdir(directories.input_chapter) for file in local_files: shutil.move(file, directories.input_chapter) return True
def main(): args = extract_args() logger.info("Processing series [{series}] chapter(s) {chapter}".format( series=args.series, chapter=args.chapters)) for chapter in args.chapters: series_config = load_config(args.series) folders = Directories(series_config.working_directory, series_config.folder_name) logger.info("") logger.info("Processing series [{series}] chapter {chapter}".format( series=args.series, chapter=chapter)) split_on_decimal = chapter.split(".") folders.chapter_folder_name = "ch" + str(split_on_decimal[0]).zfill(3) if len(split_on_decimal) > 1: folders.chapter_folder_name += "." + split_on_decimal[1] folders.input_chapter = folders.input + folders.chapter_folder_name + "/" folders.compiled_chapter = folders.compiled + folders.chapter_folder_name + "/" if not _ensure_input_images(series_config, folders, chapter, args.skip_download): continue _remove_ads(series_config, folders) _waifu_input(series_config, folders) _compile_input(series_config, folders, args.series)
def _waifu_input(series_config, folders): if len(series_config.waifu_key) > 0: logger.info("Detected waifu key") if len(glob.glob(folders.input_chapter + "*waifud.*")) == 0: input_files = glob.glob(folders.input_chapter + "*.*") temp_directory = tempfile.mkdtemp(prefix="prewaifu") + "/" logger.info("Processing with waifu using temp directory: " + temp_directory) for input_file in input_files: split_to_temp(input_file, temp_directory) starttime = default_timer() results = waifu.waifu(series_config.waifu_key, temp_directory + "*.*", folders.input_chapter) elapsed = default_timer() - starttime logger.info("Waifu'd " + str(len(results)) + " files in {:5.2f}s".format(elapsed)) shutil.rmtree(temp_directory, ignore_errors=True) if len(series_config.arguments) > 0: series_config.arguments += " " series_config.arguments += "-f " + folders.input_chapter + "*-waifud.jp*g"
def _remove_ads(series_config, folders): if len(series_config.ads_folder) > 0: logger.info("Checking folder for ads to remove: " + series_config.ads_folder) ads = glob.glob(series_config.ads_folder + "*.*") input_files = glob.glob(folders.input_chapter + "*.jp*g") if len(ads) == 0 or len(input_files) == 0: return logger.info( "Checking for any input images that roughly match these ad files: " + str(ads)) i = len(input_files) - 1 while any(imgmag.almost_matches(input_files[i], ad) for ad in ads): logger.info("Removing ad: " + input_files[i]) os.remove(input_files[i]) i -= 1 i = 0 while any(imgmag.almost_matches(input_files[i], ad) for ad in ads): logger.info("Removing ad: " + input_files[i]) os.remove(input_files[i]) i += 1
def load_config(series): config_file = localfiles.get_cc_suite_config_file() logger.info("Using configs: " + config_file) config = configparser.ConfigParser() config.read(config_file) if config["default"] is None: logger.info( "Unable to find required [default] section within the config file. \n" "It's recommended to delete your current config file and try again (a new one will be generated for you)" ) exit() blended_config = SeriesConfig(dict(config.items("default"))) if series not in config.sections(): logger.info( "Could not find configuration for series key, proceeding with default config: {series}\n" "Use 'cc-suite.py --config' to open the config file on your system and add a section for [{series}]" .format(series=series)) blended_config.folder_name = series return blended_config blended_config.load(dict(config.items(series))) if len(blended_config.folder_name) == 0: blended_config.folder_name = series if len(blended_config.working_directory) == 0: logger.info( "Could not find configuration for: {key}\n" "Use 'cc-suite.py --config' to open the config file on your system and add a section for [{key}]" .format(key="working_directory")) exit() return blended_config
def __call__(self, parser, namespace, values, option_string): config_file = localfiles.get_cc_suite_config_file() logger.info("Opening config file: " + config_file) open_file(config_file) parser.exit()