feat: enhance search functionality and add series tagging support
This commit is contained in:
105
cli.py
105
cli.py
@@ -1,41 +1,71 @@
|
||||
from src.logic.search import avail_check, search_all, search_requested
|
||||
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
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from komconfig import KomConfig
|
||||
|
||||
from src.data.komga import scan_komga
|
||||
from src.logic.search import avail_check, search_all, search_requested, search_series
|
||||
from src.logic.utils import detect_chapters, move, rename, tag_folder
|
||||
|
||||
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)
|
||||
# os.system(f"rm -rf {cfg.komgrabber.download_location}")
|
||||
# os.mkdir(cfg.komgrabber.download_location)
|
||||
if not os.path.exists(cfg.komgrabber.tag_location):
|
||||
os.mkdir(cfg.komgrabber.tag_location)
|
||||
if not os.path.exists(cfg.komgrabber.tag_location):
|
||||
os.mkdir(cfg.komgrabber.tag_location)
|
||||
|
||||
if nyaa is True and komga is True:
|
||||
if args.request:
|
||||
search_requested()
|
||||
search_all(args.library, args.all)
|
||||
if args.library is None:
|
||||
libraries = cfg.komga.libraries
|
||||
if not libraries:
|
||||
print("No libraries found in Komga, please check your configuration")
|
||||
return
|
||||
for library in libraries:
|
||||
if not library.id:
|
||||
print(
|
||||
f"Library {library} has no id, please check your configuration"
|
||||
)
|
||||
continue
|
||||
search_all(library, args.all)
|
||||
else:
|
||||
library = cfg.komga.getLibraryByName(args.library)
|
||||
search_all(library, args.all)
|
||||
|
||||
if cfg.komgrabber.aria2.kill_after_completion:
|
||||
if (
|
||||
cfg.komgrabber.downloader == "aria2"
|
||||
and cfg.komgrabber.downloader_settings.kill_after_completion
|
||||
):
|
||||
# kill aria2c
|
||||
os.system("killall aria2c")
|
||||
else:
|
||||
print("No connection established, quitting")
|
||||
|
||||
|
||||
def grab_series(series: list[str]):
|
||||
def grab_series(args):
|
||||
# nyaa, komga = avail_check()
|
||||
os.system(f"rm -rf {cfg.komgrabber.download_location}")
|
||||
os.mkdir(cfg.komgrabber.download_location)
|
||||
#
|
||||
if not args.series:
|
||||
print("No series provided to tag")
|
||||
return
|
||||
series = [series.strip() for series in args.series]
|
||||
library = cfg.komga.getLibraryByName(args.library)
|
||||
if not library:
|
||||
print(f"Library {args.library} not found, please check your configuration")
|
||||
return
|
||||
search_series(library, series)
|
||||
|
||||
|
||||
def file_operations(args):
|
||||
path = cfg.komgrabber.download_location
|
||||
if args.path: # type: ignore
|
||||
path = Path(args.path) # type: ignore
|
||||
path = Path(args.path) # type: ignore
|
||||
if args.rename:
|
||||
rename(path)
|
||||
if args.detect_chapters:
|
||||
@@ -43,20 +73,35 @@ def file_operations(args):
|
||||
if args.tag:
|
||||
tag_folder(path)
|
||||
if args.move:
|
||||
move(path)
|
||||
move(path, args.library)
|
||||
if args.scan:
|
||||
scan_komga()
|
||||
|
||||
# remove all folders and files in path
|
||||
for folder in os.listdir(path):
|
||||
folder_path = os.path.join(path, folder)
|
||||
if os.path.isfile(folder_path):
|
||||
os.remove(folder_path)
|
||||
elif os.path.isdir(folder_path):
|
||||
shutil.rmtree(folder_path)
|
||||
|
||||
# os.rmdir(path)
|
||||
|
||||
|
||||
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. After the search is completed, the library will be scanned to detect new or updated series.")
|
||||
tag_parser = subparsers.add_parser(
|
||||
"search",
|
||||
help="Run search operation. After the search is completed, the library will be scanned to detect new or updated series.",
|
||||
)
|
||||
tag_parser.add_argument(
|
||||
"library",
|
||||
type=str,
|
||||
nargs="?", # makes it optional
|
||||
default=None, # or "" if you prefer an empty string
|
||||
metavar="[library]", # nicer usage display
|
||||
help="Library to search in (e.g. 'manga', 'anime', leave empty for all)",
|
||||
)
|
||||
|
||||
@@ -87,7 +132,7 @@ def main():
|
||||
"-p",
|
||||
"--path",
|
||||
type=str,
|
||||
default=cfg.komgrabber.download_location,
|
||||
default=cfg.komgrabber.tag_location,
|
||||
help="Path to use for actions (overwrites default path).",
|
||||
)
|
||||
file_ops.add_argument(
|
||||
@@ -127,8 +172,28 @@ def main():
|
||||
action="store_true",
|
||||
help="Scan the library after downloading",
|
||||
)
|
||||
file_ops.add_argument(
|
||||
"--library",
|
||||
type=str,
|
||||
help="Specify the library to use for operations",
|
||||
default="Manga",
|
||||
)
|
||||
file_ops.set_defaults(func=file_operations)
|
||||
|
||||
series_tagger = subparsers.add_parser(
|
||||
"search-series", help="Search series in the library"
|
||||
)
|
||||
series_tagger.add_argument(
|
||||
"series",
|
||||
type=str,
|
||||
nargs="+",
|
||||
help="Series to search (e.g. 'One Piece', 'Naruto')",
|
||||
)
|
||||
series_tagger.add_argument(
|
||||
"--library", type=str, help="Library to use for tagging", default="Manga"
|
||||
)
|
||||
series_tagger.set_defaults(func=grab_series)
|
||||
|
||||
args = parser.parse_args()
|
||||
args.func(args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user