diff --git a/images/download.png b/images/download.png index 6c3767c..ec9c23e 100644 Binary files a/images/download.png and b/images/download.png differ diff --git a/images/search.png b/images/search.png index 70bfeaf..fdb8a19 100644 Binary files a/images/search.png and b/images/search.png differ diff --git a/images/viewer.png b/images/viewer.png index a16e6ce..199244b 100644 Binary files a/images/viewer.png and b/images/viewer.png differ diff --git a/nhentai/command.py b/nhentai/command.py index e82c43e..a6fd1ce 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -105,9 +105,9 @@ def main(): generate_main_html(options.output_dir) if not platform.system() == 'Windows': - logger.log(15, '🍻 All done.') + logger.log(16, '🍻 All done.') else: - logger.log(15, 'All done.') + logger.log(16, 'All done.') else: for doujinshi_id in doujinshi_ids: diff --git a/nhentai/downloader.py b/nhentai/downloader.py index db144b5..5afdf64 100644 --- a/nhentai/downloader.py +++ b/nhentai/downloader.py @@ -7,6 +7,7 @@ import sys import os import requests import time +import urllib3.exceptions from urllib.parse import urlparse from nhentai import constant @@ -15,6 +16,7 @@ from nhentai.parser import request from nhentai.utils import Singleton +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) semaphore = multiprocessing.Semaphore(1) @@ -26,7 +28,6 @@ def download_callback(result): result, data = result if result == 0: logger.warning('fatal errors occurred, ignored') - # exit(1) elif result == -1: logger.warning(f'url {data} return status code 404') elif result == -2: @@ -35,7 +36,7 @@ def download_callback(result): # workers won't be run, just pass pass else: - logger.log(15, f'{data} downloaded successfully') + logger.log(16, f'{data} downloaded successfully') class Downloader(Singleton): diff --git a/nhentai/logger.py b/nhentai/logger.py index f0a53ca..aacca79 100644 --- a/nhentai/logger.py +++ b/nhentai/logger.py @@ -34,7 +34,7 @@ class ColorizingStreamHandler(logging.StreamHandler): # levels to (background, foreground, bold/intense) level_map = { logging.DEBUG: (None, 'blue', False), - logging.INFO: (None, 'green', False), + logging.INFO: (None, 'white', False), logging.WARNING: (None, 'yellow', False), logging.ERROR: (None, 'red', False), logging.CRITICAL: ('red', 'white', False) @@ -146,10 +146,12 @@ class ColorizingStreamHandler(logging.StreamHandler): if params and message: if message.lstrip() != message: prefix = re.search(r"\s+", message).group(0) + message = message[len(prefix):] else: prefix = "" - message += prefix + ''.join((self.csi, ';'.join(params), 'm', message, self.reset)) + message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params), + 'm', message, self.reset))) return message @@ -158,18 +160,18 @@ class ColorizingStreamHandler(logging.StreamHandler): return self.colorize(message, record) -logging.addLevelName(15, "INFO") +logging.addLevelName(16, "SUCCESS") logger = logging.getLogger('nhentai') LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout) FORMATTER = logging.Formatter("\r[%(asctime)s] %(funcName)s: %(message)s", "%H:%M:%S") LOGGER_HANDLER.setFormatter(FORMATTER) -LOGGER_HANDLER.level_map[logging.getLevelName("INFO")] = (None, "cyan", False) +LOGGER_HANDLER.level_map[logging.getLevelName("SUCCESS")] = (None, "green", False) logger.addHandler(LOGGER_HANDLER) logger.setLevel(logging.DEBUG) if __name__ == '__main__': - logger.log(15, 'nhentai') + logger.log(16, 'nhentai') logger.info('info') logger.warning('warning') logger.debug('debug') diff --git a/nhentai/parser.py b/nhentai/parser.py index 6c1ab53..201cf82 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -108,7 +108,7 @@ def doujinshi_parser(id_): raise Exception(f'Doujinshi id({id_}) is not valid') id_ = int(id_) - logger.log(15, f'Fetching doujinshi information of id {id_}') + logger.info(f'Fetching doujinshi information of id {id_}') doujinshi = dict() doujinshi['id'] = id_ url = f'{constant.DETAIL_URL}/{id_}/' @@ -219,8 +219,8 @@ def print_doujinshi(doujinshi_list): return doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list] headers = ['id', 'doujinshi'] - logger.info(f'Search Result || Found {doujinshi_list.__len__()} doujinshis \n' + - tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst')) + logger.info(f'Search Result || Found {doujinshi_list.__len__()} doujinshis') + print(tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst')) def search_parser(keyword, sorting, page, is_page_all=False): @@ -273,7 +273,7 @@ def __api_suspended_doujinshi_parser(id_): raise Exception(f'Doujinshi id({id_}) is not valid') id_ = int(id_) - logger.log(15, f'Fetching information of doujinshi id {id_}') + logger.info(f'Fetching information of doujinshi id {id_}') doujinshi = dict() doujinshi['id'] = id_ url = f'{constant.DETAIL_URL}/{id_}' diff --git a/nhentai/utils.py b/nhentai/utils.py index b3d405e..5716327 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -40,7 +40,7 @@ def check_cookie(): if not username: logger.warning('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie') else: - logger.info(f'Login successfully! Your username: {username[0]}') + logger.log(16, f'Login successfully! Your username: {username[0]}') class _Singleton(type): @@ -115,7 +115,7 @@ def generate_html(output_dir='.', doujinshi_obj=None, template='default'): with open(os.path.join(doujinshi_dir, 'index.html'), 'wb') as f: f.write(data.encode('utf-8')) - logger.log(15, f'HTML Viewer has been written to "{os.path.join(doujinshi_dir, "index.html")}"') + logger.log(16, f'HTML Viewer has been written to "{os.path.join(doujinshi_dir, "index.html")}"') except Exception as e: logger.warning(f'Writing HTML Viewer failed ({e})') @@ -175,7 +175,7 @@ def generate_main_html(output_dir='./'): f.write(data.encode('utf-8')) shutil.copy(os.path.dirname(__file__) + '/viewer/logo.png', './') set_js_database() - logger.log(15, f'Main Viewer has been written to "{output_dir}main.html"') + logger.log(16, f'Main Viewer has been written to "{output_dir}main.html"') except Exception as e: logger.warning(f'Writing Main Viewer failed ({e})') @@ -202,7 +202,7 @@ def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_ if rm_origin_dir: shutil.rmtree(doujinshi_dir, ignore_errors=True) - logger.log(15, f'Comic Book CBZ file has been written to "{doujinshi_dir}"') + logger.log(16, f'Comic Book CBZ file has been written to "{doujinshi_dir}"') def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False): @@ -233,7 +233,7 @@ def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False): if rm_origin_dir: shutil.rmtree(doujinshi_dir, ignore_errors=True) - logger.log(15, f'PDF file has been written to "{doujinshi_dir}"') + logger.log(16, f'PDF file has been written to "{doujinshi_dir}"') except ImportError: logger.error("Please install img2pdf package by using pip.")