Skip to content

Commit

Permalink
Added --group-nomatch-behaviour option
Browse files Browse the repository at this point in the history
If --group option is used and none of chapter group is matching with --group option, user now can use --group-nomatch-behaviour set to fallback, instead of ignoring unmatching chapters, the application will find another chapters
  • Loading branch information
mansuf committed Sep 9, 2024
1 parent 61ec2d7 commit bd25b3c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions mangadex_downloader/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,13 @@ def _check_chapter(self, chap):
if chap.user and group.id == chap.user.id:
group_check = True

if (
not group_check
and config.group_nomatch_behaviour == "fallback"
and self._check_duplicate(chap)
):
return False

if not group_check:
pbm.logger.debug(
f"Ignoring chapter {num_chap}, "
Expand Down
14 changes: 12 additions & 2 deletions mangadex_downloader/cli/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ def get_args(argv):
)

# Group related
group_group = parser.add_argument_group("Group") # wtf group_group
group_group.add_argument(
grp_group = parser.add_argument_group("Group")
grp_group.add_argument(
"--group",
"-g",
metavar="GROUP_ID",
Expand All @@ -227,6 +227,16 @@ def get_args(argv):
"Filter with user also supported.",
action="append",
)
grp_group.add_argument(
"--group-nomatch-behaviour",
"-gnb",
choices=("ignore", "fallback"),
default=config.group_nomatch_behaviour,
help="Change behaviour for group filtering if it doesn't match. "
"By default, it set to 'ignore'. Which mean it will ignore the chapter "
"if the chapter doesn't match with specified group. If you set it to 'fallback' "
"the app will find another chapter if the chapter doesn't match with specified group",
)

# Language related
lang_group = parser.add_argument_group("Language")
Expand Down
2 changes: 2 additions & 0 deletions mangadex_downloader/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
validate_http_retries,
validate_download_mode,
validate_stacked_progress_bar_order,
validate_group_nomatch_behaviour,
validate_log_level,
validate_progress_bar_layout,
validate_int,
Expand Down Expand Up @@ -116,6 +117,7 @@ class _Config:
"no_metadata": (False, validate_bool),
"page_size": (0, validate_int),
"order": ("newest", validate_order),
"group_nomatch_behaviour": ("ignore", validate_group_nomatch_behaviour),
}
default_conf = {x: y for x, (y, _) in confs.items()}

Expand Down
7 changes: 7 additions & 0 deletions mangadex_downloader/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"validate_log_level",
"validate_progress_bar_layout",
"validate_stacked_progress_bar_order",
"validate_group_nomatch_behaviour",
"load_env",
"LazyLoadEnv",
"ConfigTypeError",
Expand Down Expand Up @@ -329,3 +330,9 @@ def validate_order(val):
raise ConfigTypeError(f"'{val}' is not valid order")

return val


def validate_group_nomatch_behaviour(val):
val = val.strip().lower()
if val not in ["ignore", "fallback"]:
raise ConfigTypeError(f"'{val}' is not valid order")

0 comments on commit bd25b3c

Please sign in to comment.