initial commit
This commit is contained in:
110
cli.py
Normal file
110
cli.py
Normal file
@@ -0,0 +1,110 @@
|
||||
from src.logic.cli import avail_check, main as cli_main
|
||||
import os
|
||||
import argparse
|
||||
from src.logic.rename import rename
|
||||
from src.logic.tag import tag_folder
|
||||
from src.logic.move import move
|
||||
from src.logic.detect_chapters import detect_chapters
|
||||
from komconfig import KomConfig
|
||||
|
||||
cfg = KomConfig()
|
||||
|
||||
|
||||
def grabber():
|
||||
nyaa, komga = avail_check()
|
||||
print(nyaa, komga)
|
||||
if nyaa is True and komga is True:
|
||||
cli_main()
|
||||
# kill aria2c
|
||||
os.system("killall aria2c")
|
||||
else:
|
||||
print("No connection established, quitting")
|
||||
|
||||
|
||||
def main(run_args=None):
|
||||
parser = argparse.ArgumentParser(
|
||||
description="A script to call various functions related to Komga File Management."
|
||||
)
|
||||
|
||||
help_texts = {
|
||||
"search": "Starts a search for all ongoing series in Komga.",
|
||||
"move": "Moves the downloaded files from the download path to the Komga library.",
|
||||
"tag": "Tries to tag all files in the download dir using comictagger.",
|
||||
"rename": "Renames the files based on the naming scheme [Title] v[number] #[number] to get best results with comictagger.",
|
||||
"detect_chapters": "Detects the chapters in the downloaded folders and removes them.",
|
||||
}
|
||||
|
||||
search_parser = parser.add_argument_group("Search")
|
||||
search_parser.add_argument(
|
||||
"-s",
|
||||
"--search",
|
||||
dest="actions",
|
||||
action="append_const",
|
||||
const="search",
|
||||
help=help_texts["search"],
|
||||
)
|
||||
move_parser = parser.add_argument_group("Move")
|
||||
move_parser.add_argument(
|
||||
"-m",
|
||||
"--move",
|
||||
dest="actions",
|
||||
action="append_const",
|
||||
const="move",
|
||||
help=help_texts["move"],
|
||||
)
|
||||
tag_parser = parser.add_argument_group("Tag")
|
||||
tag_parser.add_argument(
|
||||
"-t",
|
||||
"--tag",
|
||||
dest="actions",
|
||||
action="append_const",
|
||||
const="tag",
|
||||
help=help_texts["tag"],
|
||||
)
|
||||
rename_parser = parser.add_argument_group("Rename")
|
||||
rename_parser.add_argument(
|
||||
"-r",
|
||||
"--rename",
|
||||
dest="actions",
|
||||
action="append_const",
|
||||
const="rename",
|
||||
help=help_texts["rename"],
|
||||
)
|
||||
detect_chapters_parser = parser.add_argument_group("Detect Chapters")
|
||||
detect_chapters_parser.add_argument(
|
||||
"-d",
|
||||
"--detect_chapters",
|
||||
dest="actions",
|
||||
action="append_const",
|
||||
const="detect_chapters",
|
||||
help=help_texts["detect_chapters"],
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--path",
|
||||
type=str,
|
||||
default=cfg.komgrabber.download_location,
|
||||
help="Path to use for actions (overwrites default path).",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# based on provided arguments, call the corresponding function
|
||||
if args.actions is None:
|
||||
parser.print_help()
|
||||
return
|
||||
for action in args.actions:
|
||||
if action == "search":
|
||||
grabber()
|
||||
elif action == "move":
|
||||
move(src=args.path, dest=cfg.komga.media_path)
|
||||
elif action == "tag":
|
||||
tag_folder(args.path)
|
||||
elif action == "rename":
|
||||
rename(args.path)
|
||||
elif action == "detect_chapters":
|
||||
detect_chapters(args.path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user