From 51074ee948701b58ba17b259181560adfa5ea5eb Mon Sep 17 00:00:00 2001 From: RicterZ Date: Thu, 26 Nov 2020 17:22:23 +0800 Subject: [PATCH] support multi viewers --- MANIFEST.in | 9 ++------- nhentai/__init__.py | 2 +- nhentai/cmdline.py | 15 +++++++++++++++ nhentai/command.py | 11 +++++++---- nhentai/constant.py | 1 + nhentai/utils.py | 8 ++++---- nhentai/viewer/{ => default}/index.html | 0 nhentai/viewer/{ => default}/scripts.js | 0 nhentai/viewer/{ => default}/styles.css | 0 9 files changed, 30 insertions(+), 16 deletions(-) rename nhentai/viewer/{ => default}/index.html (100%) rename nhentai/viewer/{ => default}/scripts.js (100%) rename nhentai/viewer/{ => default}/styles.css (100%) diff --git a/MANIFEST.in b/MANIFEST.in index c68172b..9e4db9f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,4 @@ include README.md include requirements.txt -include nhentai/viewer/index.html -include nhentai/viewer/styles.css -include nhentai/viewer/scripts.js -include nhentai/viewer/main.html -include nhentai/viewer/main.css -include nhentai/viewer/main.js -include nhentai/viewer/logo.png +include nhentai/viewer/* +include nhentai/viewer/default/* \ No newline at end of file diff --git a/nhentai/__init__.py b/nhentai/__init__.py index 475633d..7efc3c4 100644 --- a/nhentai/__init__.py +++ b/nhentai/__init__.py @@ -1,3 +1,3 @@ -__version__ = '0.4.6' +__version__ = '0.4.7' __author__ = 'RicterZ' __email__ = 'ricterzheng@gmail.com' diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 2d59309..59dadac 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -126,6 +126,8 @@ def cmd_parser(): default=False, help='save downloaded doujinshis, whose will be skipped if you re-download them') parser.add_option('--clean-download-history', action='store_true', default=False, dest='clean_download_history', help='clean download history') + parser.add_option('--template', dest='viewer_template', action='store', + help='set viewer template', default='') try: sys.argv = [unicode(i.decode(sys.stdin.encoding)) for i in sys.argv] @@ -179,6 +181,19 @@ def cmd_parser(): logger.info('Proxy now set to \'{0}\'.'.format(args.proxy)) write_config() exit(0) + + if args.viewer_template: + if not args.viewer_template: + args.viewer_template = 'default' + + if not os.path.exists(os.path.join(os.path.dirname(__file__), + 'viewer/{}/index.html'.format(args.viewer_template))): + logger.error('Template \'{}\' does not exists'.format(args.viewer_template)) + exit(1) + else: + constant.CONFIG['template'] = args.viewer_template + write_config() + # --- end set config --- if args.favorites: diff --git a/nhentai/command.py b/nhentai/command.py index 47fbc3c..b44f9d2 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -13,7 +13,7 @@ from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, fav from nhentai.doujinshi import Doujinshi from nhentai.downloader import Downloader from nhentai.logger import logger -from nhentai.constant import NHENTAI_CONFIG_FILE, BASE_URL +from nhentai.constant import BASE_URL from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, \ paging, check_cookie, signal_handler, DB @@ -24,8 +24,11 @@ def main(): logger.info('Using mirror: {0}'.format(BASE_URL)) # CONFIG['proxy'] will be changed after cmd_parser() - if constant.CONFIG['proxy']: - logger.info('Using proxy: {0}'.format(constant.CONFIG['proxy'])) + if constant.CONFIG['proxy']['http']: + logger.info('Using proxy: {0}'.format(constant.CONFIG['proxy']['http'])) + + if constant.CONFIG['template']: + logger.info('Using viewer template "{}"'.format(constant.CONFIG['template'])) # check your cookie check_cookie() @@ -88,7 +91,7 @@ def main(): db.add_one(doujinshi.id) if not options.is_nohtml and not options.is_cbz and not options.is_pdf: - generate_html(options.output_dir, doujinshi) + generate_html(options.output_dir, doujinshi, template=constant.CONFIG['template']) elif options.is_cbz: generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir) elif options.is_pdf: diff --git a/nhentai/constant.py b/nhentai/constant.py index 8ec89f7..e27765e 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -33,5 +33,6 @@ CONFIG = { 'proxy': {}, 'cookie': '', 'language': '', + 'template': '', } diff --git a/nhentai/utils.py b/nhentai/utils.py index fb73559..b3358e4 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -64,7 +64,7 @@ def readfile(path): return file.read() -def generate_html(output_dir='.', doujinshi_obj=None): +def generate_html(output_dir='.', doujinshi_obj=None, template='default'): image_html = '' if doujinshi_obj is not None: @@ -81,9 +81,9 @@ def generate_html(output_dir='.', doujinshi_obj=None): image_html += '\n'\ .format(image) - html = readfile('viewer/index.html') - css = readfile('viewer/styles.css') - js = readfile('viewer/scripts.js') + html = readfile('viewer/{}/index.html'.format(template)) + css = readfile('viewer/{}/styles.css'.format(template)) + js = readfile('viewer/{}/scripts.js'.format(template)) if doujinshi_obj is not None: serialize_json(doujinshi_obj, doujinshi_dir) diff --git a/nhentai/viewer/index.html b/nhentai/viewer/default/index.html similarity index 100% rename from nhentai/viewer/index.html rename to nhentai/viewer/default/index.html diff --git a/nhentai/viewer/scripts.js b/nhentai/viewer/default/scripts.js similarity index 100% rename from nhentai/viewer/scripts.js rename to nhentai/viewer/default/scripts.js diff --git a/nhentai/viewer/styles.css b/nhentai/viewer/default/styles.css similarity index 100% rename from nhentai/viewer/styles.css rename to nhentai/viewer/default/styles.css -- 2.44.0