change log color and update images

This commit is contained in:
Ricter Z 2023-02-05 23:44:15 +08:00
parent 8c900a833d
commit a8566482aa
8 changed files with 21 additions and 18 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 KiB

After

Width:  |  Height:  |  Size: 991 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 KiB

After

Width:  |  Height:  |  Size: 1.9 MiB

View File

@ -105,9 +105,9 @@ def main():
generate_main_html(options.output_dir) generate_main_html(options.output_dir)
if not platform.system() == 'Windows': if not platform.system() == 'Windows':
logger.log(15, '🍻 All done.') logger.log(16, '🍻 All done.')
else: else:
logger.log(15, 'All done.') logger.log(16, 'All done.')
else: else:
for doujinshi_id in doujinshi_ids: for doujinshi_id in doujinshi_ids:

View File

@ -7,6 +7,7 @@ import sys
import os import os
import requests import requests
import time import time
import urllib3.exceptions
from urllib.parse import urlparse from urllib.parse import urlparse
from nhentai import constant from nhentai import constant
@ -15,6 +16,7 @@ from nhentai.parser import request
from nhentai.utils import Singleton from nhentai.utils import Singleton
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
semaphore = multiprocessing.Semaphore(1) semaphore = multiprocessing.Semaphore(1)
@ -26,7 +28,6 @@ def download_callback(result):
result, data = result result, data = result
if result == 0: if result == 0:
logger.warning('fatal errors occurred, ignored') logger.warning('fatal errors occurred, ignored')
# exit(1)
elif result == -1: elif result == -1:
logger.warning(f'url {data} return status code 404') logger.warning(f'url {data} return status code 404')
elif result == -2: elif result == -2:
@ -35,7 +36,7 @@ def download_callback(result):
# workers won't be run, just pass # workers won't be run, just pass
pass pass
else: else:
logger.log(15, f'{data} downloaded successfully') logger.log(16, f'{data} downloaded successfully')
class Downloader(Singleton): class Downloader(Singleton):

View File

@ -34,7 +34,7 @@ class ColorizingStreamHandler(logging.StreamHandler):
# levels to (background, foreground, bold/intense) # levels to (background, foreground, bold/intense)
level_map = { level_map = {
logging.DEBUG: (None, 'blue', False), logging.DEBUG: (None, 'blue', False),
logging.INFO: (None, 'green', False), logging.INFO: (None, 'white', False),
logging.WARNING: (None, 'yellow', False), logging.WARNING: (None, 'yellow', False),
logging.ERROR: (None, 'red', False), logging.ERROR: (None, 'red', False),
logging.CRITICAL: ('red', 'white', False) logging.CRITICAL: ('red', 'white', False)
@ -146,10 +146,12 @@ class ColorizingStreamHandler(logging.StreamHandler):
if params and message: if params and message:
if message.lstrip() != message: if message.lstrip() != message:
prefix = re.search(r"\s+", message).group(0) prefix = re.search(r"\s+", message).group(0)
message = message[len(prefix):]
else: else:
prefix = "" 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 return message
@ -158,18 +160,18 @@ class ColorizingStreamHandler(logging.StreamHandler):
return self.colorize(message, record) return self.colorize(message, record)
logging.addLevelName(15, "INFO") logging.addLevelName(16, "SUCCESS")
logger = logging.getLogger('nhentai') logger = logging.getLogger('nhentai')
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout) LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
FORMATTER = logging.Formatter("\r[%(asctime)s] %(funcName)s: %(message)s", "%H:%M:%S") FORMATTER = logging.Formatter("\r[%(asctime)s] %(funcName)s: %(message)s", "%H:%M:%S")
LOGGER_HANDLER.setFormatter(FORMATTER) 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.addHandler(LOGGER_HANDLER)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
if __name__ == '__main__': if __name__ == '__main__':
logger.log(15, 'nhentai') logger.log(16, 'nhentai')
logger.info('info') logger.info('info')
logger.warning('warning') logger.warning('warning')
logger.debug('debug') logger.debug('debug')

View File

@ -108,7 +108,7 @@ def doujinshi_parser(id_):
raise Exception(f'Doujinshi id({id_}) is not valid') raise Exception(f'Doujinshi id({id_}) is not valid')
id_ = int(id_) 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 = dict()
doujinshi['id'] = id_ doujinshi['id'] = id_
url = f'{constant.DETAIL_URL}/{id_}/' url = f'{constant.DETAIL_URL}/{id_}/'
@ -219,8 +219,8 @@ def print_doujinshi(doujinshi_list):
return return
doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list] doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list]
headers = ['id', 'doujinshi'] headers = ['id', 'doujinshi']
logger.info(f'Search Result || Found {doujinshi_list.__len__()} doujinshis \n' + logger.info(f'Search Result || Found {doujinshi_list.__len__()} doujinshis')
tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst')) print(tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
def search_parser(keyword, sorting, page, is_page_all=False): 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') raise Exception(f'Doujinshi id({id_}) is not valid')
id_ = int(id_) 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 = dict()
doujinshi['id'] = id_ doujinshi['id'] = id_
url = f'{constant.DETAIL_URL}/{id_}' url = f'{constant.DETAIL_URL}/{id_}'

View File

@ -40,7 +40,7 @@ def check_cookie():
if not username: if not username:
logger.warning('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie') logger.warning('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie')
else: else:
logger.info(f'Login successfully! Your username: {username[0]}') logger.log(16, f'Login successfully! Your username: {username[0]}')
class _Singleton(type): 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: with open(os.path.join(doujinshi_dir, 'index.html'), 'wb') as f:
f.write(data.encode('utf-8')) 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: except Exception as e:
logger.warning(f'Writing HTML Viewer failed ({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')) f.write(data.encode('utf-8'))
shutil.copy(os.path.dirname(__file__) + '/viewer/logo.png', './') shutil.copy(os.path.dirname(__file__) + '/viewer/logo.png', './')
set_js_database() 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: except Exception as e:
logger.warning(f'Writing Main Viewer failed ({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: if rm_origin_dir:
shutil.rmtree(doujinshi_dir, ignore_errors=True) 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): 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: if rm_origin_dir:
shutil.rmtree(doujinshi_dir, ignore_errors=True) 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: except ImportError:
logger.error("Please install img2pdf package by using pip.") logger.error("Please install img2pdf package by using pip.")