Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--start-volume & --end-volume functionality addition #113

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion mangadex_downloader/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ def __init__(
no_oneshot=None,
groups=None,
_range=None,
start_volume=None,
end_volume=None,
**kwargs
):

Expand All @@ -380,7 +382,9 @@ def __init__(
end_chapter or
start_page or
end_page or
no_oneshot
no_oneshot or
start_volume or
end_volume
)

if _range and legacy_range:
Expand All @@ -395,6 +399,8 @@ def __init__(
self.start_page = start_page
self.end_page = end_page
self.no_oneshot = no_oneshot
self.start_volume = start_volume
self.end_volume = end_volume
self.groups = None
self.all_group = False
self.legacy_range = legacy_range
Expand Down Expand Up @@ -456,6 +462,7 @@ def _parse_groups(self, ids):

def _check_range_chapter_legacy(self, chap):
num_chap = chap.chapter
num_vol = chap.volume
if num_chap != 'none':
try:
num_chap = float(num_chap)
Expand All @@ -464,8 +471,17 @@ def _check_range_chapter_legacy(self, chap):
except TypeError:
# null value
pass
if num_vol != 'none':
try:
num_vol = float(num_vol)
except ValueError:
pass
except TypeError:
# null value
pass

is_number = isinstance(num_chap, float)
is_vol_number = isinstance(num_vol, float)

# There is a chance that "Chapter 0" is Oneshot or prologue
# We need to verify that is valid oneshot chapter
Expand All @@ -480,6 +496,14 @@ def _check_range_chapter_legacy(self, chap):
log.debug(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
return False

if is_vol_number and num_vol > 0.0:
if self.start_volume is not None and not (num_vol >= self.start_volume):
log.debug(f"Ignoring chapter in volume {num_vol}, because volume {num_vol} is in ignored list")
return False
if self.end_volume is not None and not (num_vol <= self.end_volume):
log.debug(f"Ignoring chapter in volume {num_vol}, because volume {num_vol} is in ignored list")
return False

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This volume checking must be placed before chapter checking, if both start/end chapter and volume is used then --start-volume and --end-volume won't be useful enough.

For example:

mangadex-dl "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" --start-chapter 1 --end-chapter 43 --start-volume 1 --end-volume 2

The user wants to stop download at volume number 2 but because of --end-chapter is set to 43, then it will continue to download until chapter 43, not until volume 2. Which you can see in provided MangaDex link above, volume 2 stopped at chapter 34

Overall, this PR looks good, i will try test and merge it once the fix is resolved 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are confused, it should be like this !

image

I'm sorry i cannot use git diff in Github 🗿, so i use text comparer in devtoys

if chap.oneshot and self.no_oneshot and not self.all_group:
log.debug("Ignoring oneshot chapter since it's in ignored list")
return False
Expand All @@ -491,8 +515,11 @@ def _check_range_chapter_legacy(self, chap):
log.debug(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
return False



return True


def _check_range_chapter(self, chap):
if self.legacy_range:
return self._check_range_chapter_legacy(chap)
Expand Down
17 changes: 17 additions & 0 deletions mangadex_downloader/cli/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ def get_args(argv):
default=config.volume_cover_language,
)

# Volume related
vol_group = parser.add_argument_group('Volume')
vol_group.add_argument(
'--start-volume',
'-sv',
type=float,
help='Start download chapter from given volume number',
metavar='VOLUME'
)
vol_group.add_argument(
'--end-volume',
'-ev',
type=float,
help='Stop download chapter from given volume number',
metavar='VOLUME'
)

# Chapter related
chap_group = parser.add_argument_group('Chapter')
chap_group.add_argument(
Expand Down
14 changes: 13 additions & 1 deletion mangadex_downloader/cli/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def download_manga(url, args, legacy=False):
if args.start_chapter > args.end_chapter:
raise MangaDexException("--start-chapter cannot be more than --end-chapter")

if args.start_volume is not None and args.end_volume is not None:
if args.start_volume > args.end_volume:
raise MangaDexException("--start-volume cannot be more than --end-volume")

if args.start_page is not None and args.end_page is not None:
if args.start_page > args.end_page:
raise MangaDexException("--start-page cannot be more than --end-page")
Expand All @@ -68,7 +72,9 @@ def download_manga(url, args, legacy=False):
'end_chapter': '--end-chapter',
'start_page': '--start-page',
'end_page': '--end-page',
'no_oneshot_chapter': '--no-oneshot-chapter'
'no_oneshot_chapter': '--no-oneshot-chapter',
'start_volume': '--start-volume',
'end_volume': '--end-volume'
}
for name, arg in range_forbidden_args.items():
value = getattr(args, name)
Expand All @@ -86,6 +92,8 @@ def download_manga(url, args, legacy=False):
args.start_page,
args.end_page,
args.no_oneshot_chapter,
args.start_volume,
args.end_volume,
args.use_alt_details,
args.group,
args.range,
Expand Down Expand Up @@ -129,6 +137,10 @@ def download_list(url, args):
_error_list('--start-page')
elif args.end_page:
_error_list('--end-page')
elif args.start_volume:
_error_list('--start-volume')
elif args.end_volume:
_error_list('--end-volume')
elif args.range:
_error_list('--range')

Expand Down
4 changes: 4 additions & 0 deletions mangadex_downloader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def download(
start_page=None,
end_page=None,
no_oneshot_chapter=False,
start_volume=False,
end_volume=False,
use_alt_details=False,
groups=None,
_range=None,
Expand Down Expand Up @@ -118,6 +120,8 @@ def download_manga(m, path):
"start_page": start_page,
"end_page": end_page,
"no_oneshot": no_oneshot_chapter,
"start_volume": start_volume,
"end_volume": end_volume,
"groups": groups,
"_range": _range,
}
Expand Down