Skip to content

Commit

Permalink
[skip ci] [On progress] Add stacked progress bars pt. 1
Browse files Browse the repository at this point in the history
Completed formats:
- Any chapters format (cbz, raw, epub, etc)
- Any volumes format (cbz-volume, raw-volume, etc)
  • Loading branch information
mansuf committed Jun 7, 2023
1 parent c1a3f2d commit 5b878bd
Show file tree
Hide file tree
Showing 20 changed files with 839 additions and 513 deletions.
29 changes: 15 additions & 14 deletions mangadex_downloader/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .group import Group
from .config import config, env
from .utils import convert_int_or_float, get_local_attr
from .progress_bar import progress_bar_manager as pbm
# from . import range as range_mod # range_mod stands for "range module"

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -80,7 +81,7 @@ def _check_range_page_legacy(self, page, log_info):
if not (page >= self.start_page):

if log_info:
log.info("Ignoring page %s as \"start_page\" is %s" % (
pbm.logger.info("Ignoring page %s as \"start_page\" is %s" % (
page,
self.start_page
))
Expand All @@ -91,7 +92,7 @@ def _check_range_page_legacy(self, page, log_info):
if not (page <= self.end_page):

if log_info:
log.info("Ignoring page %s as \"end_page\" is %s" % (
pbm.logger.info("Ignoring page %s as \"end_page\" is %s" % (
page,
self.end_page
))
Expand All @@ -107,7 +108,7 @@ def _check_range_page(self, page, log_info):
if self.range is not None and not self.range.check_page(self.chap, page):

if log_info:
log.info(f"Ignoring page {page}, because page {page} is in ignored list")
log.debug(f"Ignoring page {page}, because page {page} is in ignored list")

return False

Expand Down Expand Up @@ -472,22 +473,22 @@ def _check_range_chapter_legacy(self, chap):
# then we need to skip start_chapter and end_chapter checking
if is_number and num_chap > 0.0:
if self.start_chapter is not None and not (num_chap >= self.start_chapter):
log.info(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
log.debug(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
return False

if self.end_chapter is not None and not (num_chap <= self.end_chapter):
log.info(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
log.debug(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
return False

if chap.oneshot and self.no_oneshot and not self.all_group:
log.info("Ignoring oneshot chapter since it's in ignored list")
log.debug("Ignoring oneshot chapter since it's in ignored list")
return False

# If chapter 0 is prologue or whatever and not oneshot
# Re-check start_chapter
elif not chap.oneshot and is_number:
if self.start_chapter is not None and not (num_chap >= self.start_chapter):
log.info(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
log.debug(f"Ignoring chapter {num_chap}, because chapter {num_chap} is in ignored list")
return False

return True
Expand All @@ -497,7 +498,7 @@ def _check_range_chapter(self, chap):
return self._check_range_chapter_legacy(chap)

if self.range is not None and not self.range.check_chapter(chap):
log.info(f"Ignoring chapter {chap.chapter}, because chapter {chap.chapter} is in ignored list")
log.debug(f"Ignoring chapter {chap.chapter}, because chapter {chap.chapter} is in ignored list")
return False

return True
Expand All @@ -522,21 +523,21 @@ def _check_chapter(self, chap):
config.download_mode == "unread" and
chap.id in self._unread_chapters
):
log.warning(
log.debug(
f"Ignoring chapter {chap.get_simplified_name()} because it's marked as read"
)
return False

if not self.all_group and not self.groups and self._check_duplicate(chap):
log.warning(
log.debug(
f"Found duplicate {chap.simple_name} from [{chap.groups_name}], ignoring... "
)
return False

# Some manga has chapters where it has no pages / images inside of it.
# We need to verify it, to prevent error when downloading the manga.
if chap.pages == 0:
log.warning("Chapter {0} from group {1} has no images, ignoring...".format(
log.debug("Chapter {0} from group {1} has no images, ignoring...".format(
chap.chapter,
chap.groups_name
))
Expand All @@ -552,14 +553,14 @@ def _check_chapter(self, chap):
if chap.groups:
blacklisted_groups = filter(lambda x: x.id in env.group_blacklist, chap.groups)
for group in blacklisted_groups:
log.info(
log.debug(
f"Ignoring chapter {chap.chapter}, " \
f"because group '{group.name}' is blacklisted"
)
return False

if chap.user and chap.user.id in env.user_blacklist:
log.info(
log.debug(
f"Ignoring chapter {chap.chapter}, " \
f"because user '{chap.user.name}' is blacklisted"
)
Expand All @@ -586,7 +587,7 @@ def _check_chapter(self, chap):
group_check = True

if not group_check:
log.info(
log.debug(
f"Ignoring chapter {num_chap}, " \
f"{group_type} \"{group_names}\" is not match with \"{group.name}\""
)
Expand Down
39 changes: 32 additions & 7 deletions mangadex_downloader/cli/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,7 @@ def get_args(argv):
nargs=0,
help='Print mangadex-downloader version'
)
misc_group.add_argument(
'--no-progress-bar',
'-npb',
action='store_true',
default=config.no_progress_bar,
help='Disable progress bar when downloading or converting'
)

misc_group.add_argument(
'--write-tachiyomi-info',
'-wti',
Expand All @@ -414,6 +408,37 @@ def get_args(argv):
'NOTE: If you enable this, the application will not verify images and chapters. '
)

console_group = parser.add_argument_group("Console output")
console_group.add_argument(
'--log-level',
default=config.log_level,
help="Set logger level, available options: " \
"CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET"
)
console_group.add_argument(
'--progress-bar-layout',
'-pbl',
default=config.progress_bar_layout,
help="Set progress bar layout, available options: " \
"default, stacked, none"
)
console_group.add_argument(
'--stacked-progress-bar-order',
'-spb-order',
default=config.stacked_progress_bar_order,
help="Set stacked progress bar order, available options: " \
"volumes, chapters, pages, file sizes, convert. " \
"Multiple values is supported, separated by comma"
)
console_group.add_argument(
'--no-progress-bar',
'-npb',
action='store_true',
default=config.no_progress_bar,
help="[DEPRECATED] Use '--progress-bar-layout=none' instead. " \
"Disable progress bar when downloading or converting"
)

# Update application
update_group = parser.add_argument_group('Update application')
update_group.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions mangadex_downloader/cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import re
import sys

from .utils import dynamic_bars, get_key_value
from .utils import dynamic_bars
from ..config import config, login_cache
from ..utils import getpass_handle, input_handle
from ..utils import getpass_handle, input_handle, get_key_value
from ..errors import HTTPException, LoginFailed
from ..network import Net

Expand Down
3 changes: 1 addition & 2 deletions mangadex_downloader/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
Paginator,
dynamic_bars,
IteratorEmpty,
get_key_value,
split_comma_separated
)
from ..iterator import (
Expand All @@ -48,7 +47,7 @@
validate_forum_thread_url
)
from .. import __repository__
from ..utils import input_handle, validate_url, get_cover_art_url
from ..utils import input_handle, validate_url, get_cover_art_url, get_key_value
from ..errors import InvalidURL, MangaDexException, PillowNotInstalled, UnhandledException
from ..network import Net
from ..manga import Manga
Expand Down
2 changes: 1 addition & 1 deletion mangadex_downloader/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import logging
import sys

from .utils import get_key_value
from ..utils import get_key_value
from ..config import (
config,
_conf,
Expand Down
5 changes: 3 additions & 2 deletions mangadex_downloader/cli/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import re
import requests

from .utils import get_key_value, check_group_all
from .utils import check_group_all
from .command import registered_commands
from ..config import config
from ..network import Net
Expand All @@ -34,7 +34,8 @@
from ..utils import (
validate_url as get_uuid,
find_md_urls,
valid_url_types
valid_url_types,
get_key_value
)
from ..main import (
download as dl_manga,
Expand Down
6 changes: 0 additions & 6 deletions mangadex_downloader/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ def dynamic_bars(length):

return bar

def get_key_value(text, sep='='):
splitted = text.split(sep, maxsplit=1)
key = splitted[0]
value = "".join(splitted[1:])
return key, value

def split_comma_separated(text, single_value_to_list=False):
if ',' not in text:
return [text] if single_value_to_list else text
Expand Down
15 changes: 14 additions & 1 deletion mangadex_downloader/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ..cover import default_cover_type, valid_cover_types
from ..language import Language
from ..errors import MangaDexException
from ..progress_bar import ProgressBarManager

# Fix #28
_doh_providers = [None]
Expand Down Expand Up @@ -117,7 +118,19 @@ class _Config:
"no_track": [
False,
validate_bool
]
],
"stacked_progress_bar_order": [
"volumes, chapters, pages, file sizes, convert",
validate_stacked_progress_bar_order
],
"log_level": [
logging.INFO,
validate_log_level
],
"progress_bar_layout": [
"default",
validate_progress_bar_layout
],
}
default_conf = {
x: y for x, (y, _) in confs.items()
Expand Down
45 changes: 43 additions & 2 deletions mangadex_downloader/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
from .. import format as fmt
from ..errors import MangaDexException, InvalidURL
from ..language import get_language
from ..utils import validate_url
from ..utils import validate_url, get_key_value
from ..progress_bar import progress_bar_manager

__all__ = (
"validate_bool", "validate_language", "validate_value_from_iterator",
"validate_format", "dummy_validator", "validate_zip_compression_type",
"validate_int", "validate_tag", "validate_blacklist",
"validate_sort_by", "validate_http_retries", "validate_download_mode",
"validate_doh_provider",
"validate_doh_provider", "validate_log_level", "validate_progress_bar_layout",
"validate_stacked_progress_bar_order",
"load_env", "LazyLoadEnv", "ConfigTypeError"
)

Expand Down Expand Up @@ -233,5 +235,44 @@ def load(self):
self.validator
)

valid_output_modes = [
"logger",
"stacked-progress-bar",
"progress-bar"
]

valid_stacked_progress_bar_types = [
"volumes",
"chapters",
"pages",
"file sizes",
"converted files"
]

def validate_log_level(val):
val = val if isinstance(val, int) else val.upper()
log_level = logging.getLevelName(val)
if log_level == f"Level {val}":
# Instead of raising exception,
# logging.getLevelName will return string "Level {level}"
raise ConfigTypeError(f"'{val}' is not valid logger level")

log = logging.getLogger("mangadex_downloader")
log.setLevel(log_level)
return val

def validate_progress_bar_layout(val):
valid_progress_bar_layouts = ["default", "stacked", "none"]
if val not in valid_progress_bar_layouts:
raise ConfigTypeError(f"'{val}' is not valid progress bar layout")

return val

def validate_stacked_progress_bar_order(val):
values = [i.strip() for i in val.split(",")]
for value in values:
if value not in progress_bar_manager.valid_types_order:
raise ConfigTypeError(f"'{val}' is not valid stacked progress bar order")

progress_bar_manager.set_types_order(*values)
return values
Loading

0 comments on commit 5b878bd

Please sign in to comment.