From d1ed9b6980f1ff72ce53d3f1e4438a48d985e23a Mon Sep 17 00:00:00 2001 From: Ricter Z Date: Sun, 18 Jun 2017 14:19:07 +0800 Subject: [PATCH] add html doujinshi viewer --- nhentai/command.py | 25 ++++++++ nhentai/doujinshi.html | 126 +++++++++++++++++++++++++++++++++++++++++ nhentai/downloader.py | 3 + 3 files changed, 154 insertions(+) create mode 100644 nhentai/doujinshi.html diff --git a/nhentai/command.py b/nhentai/command.py index bbab984..b86ba9c 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -1,6 +1,7 @@ #!/usr/bin/env python2.7 # coding: utf-8 from __future__ import unicode_literals, print_function +import os import signal import platform @@ -43,6 +44,30 @@ def main(): doujinshi.downloader = downloader doujinshi.download() + image_html = '' + previous = '' + + doujinshi_dir = os.path.join(options.output_dir, str(doujinshi.id)) + file_list = os.listdir(doujinshi_dir) + for index, image in enumerate(file_list): + try: + next_ = file_list[file_list.index(image) + 1] + except IndexError: + next_ = '' + + image_html += '\n'\ + .format(image, 'current' if index == 0 else '', previous, next_) + previous = image + + with open(os.path.join(os.path.dirname(__file__), 'doujinshi.html'), 'r') as template: + html = template.read() + + data = html.format(TITLE=doujinshi.name, IMAGES=image_html) + with open(os.path.join(doujinshi_dir, 'index.html'), 'w') as f: + f.write(data) + + logger.log(15, 'HTML Viewer has been write to \'{0}\''.format(os.path.join(doujinshi_dir, 'index.html'))) + if not platform.system() == 'Windows': logger.log(15, '🍺 All done.') else: diff --git a/nhentai/doujinshi.html b/nhentai/doujinshi.html new file mode 100644 index 0000000..eae0e25 --- /dev/null +++ b/nhentai/doujinshi.html @@ -0,0 +1,126 @@ + + + + + {TITLE} + + + + + + +
+{IMAGES}
+
+
+ + + +
+
+ + + + \ No newline at end of file diff --git a/nhentai/downloader.py b/nhentai/downloader.py index bd82f0d..b954e27 100644 --- a/nhentai/downloader.py +++ b/nhentai/downloader.py @@ -14,6 +14,9 @@ from nhentai.parser import request from nhentai.utils import Singleton +requests.packages.urllib3.disable_warnings() + + class NhentaiImageNotExistException(Exception): pass