Skip to content

Commit

Permalink
Added option to change order chapter (newest or oldest)
Browse files Browse the repository at this point in the history
Ref: #106
  • Loading branch information
mansuf committed Aug 24, 2024
1 parent 725dd7f commit 32203fa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
13 changes: 7 additions & 6 deletions mangadex_downloader/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def __init__(
data = get_chapter(_id)["data"]

self.id = data["id"]
self._attr = data["attributes"]
self.attr = data["attributes"]

# Get scanlation groups and manga
rels = data["relationships"]
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(
self.use_group_name = not config.no_group_name
self.use_chapter_title = config.use_chapter_title

self._lang = Language(self._attr["translatedLanguage"])
self._lang = Language(self.attr["translatedLanguage"])

self._parse_name()

Expand All @@ -203,7 +203,7 @@ def from_data(cls, data):

@property
def volume(self):
vol = self._attr["volume"]
vol = self.attr["volume"]
if vol is not None:
# As far as i know
# Volume manga are integer numbers, not float
Expand All @@ -226,18 +226,18 @@ def __str__(self) -> str:
@property
def chapter(self):
try:
return self._attr["chapter"].strip()
return self.attr["chapter"].strip()
except AttributeError:
# null value
return None

@property
def title(self):
return self._attr["title"]
return self.attr["title"]

@property
def pages(self):
return self._attr["pages"]
return self.attr["pages"]

@property
def language(self):
Expand Down Expand Up @@ -336,6 +336,7 @@ def iter_chapters_feed(manga_id, lang=None):
"offset": offset,
"order[volume]": "asc",
"order[chapter]": "asc",
"order[readableAt]": "desc" if config.order == "newest" else "asc",
"includeEmptyPages": 0,
}

Expand Down
8 changes: 8 additions & 0 deletions mangadex_downloader/cli/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ def get_args(argv):
help="Merge all chapters that has no volume into 1 file for 'volume' format. ",
default=config.create_no_volume,
)
chap_group.add_argument(
"--order",
default=config.order,
choices=("newest", "oldest"),
help="Change chapter order, by default it set to 'newest'. "
"Which mean it always try to download the newest chapter. "
"Available options: newest, oldest",
)

# Chapter page related
chap_page_group = parser.add_argument_group("Chapter Page")
Expand Down
4 changes: 3 additions & 1 deletion mangadex_downloader/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
validate_stacked_progress_bar_order,
validate_log_level,
validate_progress_bar_layout,
convert_string_lowercase,
validate_int,
validate_order,
convert_string_lowercase,
ConfigTypeError,
)
from .. import format as fmt, json_op
Expand Down Expand Up @@ -114,6 +115,7 @@ class _Config:
),
"no_metadata": (False, validate_bool),
"page_size": (0, validate_int),
"order": ("newest", validate_order),
}
default_conf = {x: y for x, (y, _) in confs.items()}

Expand Down
9 changes: 9 additions & 0 deletions mangadex_downloader/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

__all__ = (
"validate_bool",
"validate_order",
"validate_language",
"validate_value_from_iterator",
"validate_format",
Expand Down Expand Up @@ -320,3 +321,11 @@ def validate_stacked_progress_bar_order(val):

progress_bar_manager.set_types_order(*values)
return values


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

return val

0 comments on commit 32203fa

Please sign in to comment.