from src.tagger import Tagger import argparse tagger = Tagger() def tag_all(args): # type:ignore if args.mode == "overwrite": tagger.overwrite elif args.mode == "merge": tagger.merge if args.verbose: tagger.verbose = True tagger.tag() with open("failed.txt", "r") as f: items = f.readlines() unique_items = set(item.strip() for item in items if item.strip()) print(f"Failed to tag {len(unique_items)} items.") print("Failed items:") for item in unique_items: print(item.strip()) def tag_series(args): # type:ignore if args.id: tagger.tag_series(series_ids=args.id) elif args.name: names = [] name = " ".join(args.name) if ":" in name: names = name.split(":") else: names.append(name) tagger.tag_series(series_names=names) def manual_parse(args): # type:ignore name = args.name if args.name else None series_id = int(args.id) if args.id else None print(f"Using name: {name} and id: {series_id}") tagger.tag_manual(series_name=name, anilist_id=series_id) def main(): parser = argparse.ArgumentParser(description="KomTagger CLI") subparsers = parser.add_subparsers(dest="command", required=True) # tag subcommand tag_parser = subparsers.add_parser("tag", help="Run tag operation") tag_parser.add_argument( "mode", choices=["overwrite", "merge"], help="Set mode for tagging, merge will add the tags to the current tags, overwrite will replace the current tags", ) tag_parser.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output" ) tag_parser.set_defaults(func=tag_all) # tag-series subcommand series_parser = subparsers.add_parser("tag-series", help="Run tag-series operation") group = series_parser.add_mutually_exclusive_group(required=True) group.add_argument("--id", nargs="+", help="ID for tag series") group.add_argument( "--name", nargs="+", help="Name(s) for tag series (use ':' to separate multiple names)", ) series_parser.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output" ) series_parser.set_defaults(func=tag_series) manual_parsing = subparsers.add_parser("match", help="Run manual parsing operation") manual_parsing.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output" ) manual_parsing.add_argument( "--name", type=str, help="Series name to use", ) manual_parsing.add_argument( "--id", type=str, help="Series ID to use", ) manual_parsing.set_defaults(func=manual_parse) failed_parser = subparsers.add_parser( "failed", help="Show failed items from the last tag operation and manually tag them", ) failed_parser.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output" ) failed_parser.set_defaults(func=tagger.show_failed) args = parser.parse_args() args.func(args) # Call the function associated with the command if __name__ == "__main__": main()