from src.logic.cli import avail_check, search_all import os import argparse from src.logic.utils import move, tag_folder, rename, detect_chapters from komconfig import KomConfig from src.aria import launch_aria2c, kill_aria2c from src.data.komga import scan_komga from pathlib import Path cfg: KomConfig = KomConfig() def grabber(args): nyaa, komga = avail_check() os.system(f"rm -rf {cfg.komgrabber.download_location}") os.mkdir(cfg.komgrabber.download_location) if nyaa is True and komga is True: search_all() if args.scan: scan_komga() if cfg.komgrabber.aria2.kill_after_completion: # kill aria2c os.system("killall aria2c") else: print("No connection established, quitting") def grab_series(series: list[str]): # nyaa, komga = avail_check() os.system(f"rm -rf {cfg.komgrabber.download_location}") os.mkdir(cfg.komgrabber.download_location) def file_operations(args): path = cfg.komgrabber.download_location if args.path: # type: ignore path = Path(args.path) # type: ignore if args.rename: rename(path) if args.detect_chapters: detect_chapters(path) if args.tag: tag_folder(path) if args.move: move(path) if args.scan: scan_komga() def main(): parser = argparse.ArgumentParser(description="KomGrabber CLI") subparsers = parser.add_subparsers(dest="command", required=True) # tag subcommand tag_parser = subparsers.add_parser("search", help="Run search operation") tag_parser.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output" ) tag_parser.add_argument( "--scan", action="store_true", help="Scan the library after downloading", ) tag_parser.set_defaults(func=grabber) # tag-series subcommand file_ops = subparsers.add_parser("file", help="Run file related operations") file_ops.add_argument( "-p", "--path", type=str, default=cfg.komgrabber.download_location, help="Path to use for actions (overwrites default path).", ) file_ops.add_argument( "-t", "--tag", default=True, action="store_true", help="Tag the downloaded files with the series name.", ) file_ops.add_argument( "-r", "--rename", default=True, action="store_true", help="Rename the downloaded files to match the series name.", ) file_ops.add_argument( "-d", "--detect-chapters", action="store_true", default=True, help="Detect chapters in the downloaded files.", ) file_ops.add_argument( "-m", "--move", action="store_true", default=True, help="Move the downloaded files to the specified path.", ) file_ops.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose output" ) file_ops.add_argument( "--scan", action="store_true", help="Scan the library after downloading", ) file_ops.set_defaults(func=file_operations) args = parser.parse_args() args.func(args) if __name__ == "__main__": main()