]> git.lizzy.rs Git - nhentai.git/commitdiff
support multi viewers
authorRicterZ <ricterzheng@gmail.com>
Thu, 26 Nov 2020 09:22:23 +0000 (17:22 +0800)
committerRicterZ <ricterzheng@gmail.com>
Thu, 26 Nov 2020 09:22:23 +0000 (17:22 +0800)
12 files changed:
MANIFEST.in
nhentai/__init__.py
nhentai/cmdline.py
nhentai/command.py
nhentai/constant.py
nhentai/utils.py
nhentai/viewer/default/index.html [new file with mode: 0644]
nhentai/viewer/default/scripts.js [new file with mode: 0644]
nhentai/viewer/default/styles.css [new file with mode: 0644]
nhentai/viewer/index.html [deleted file]
nhentai/viewer/scripts.js [deleted file]
nhentai/viewer/styles.css [deleted file]

index c68172b10e0a9e6439947983d7b6508d7363d157..9e4db9f6cab581a81fae4b4207a8b8fa77bc10aa 100644 (file)
@@ -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
index 475633d71944ecaef3f56dbb98e9f808002470a3..7efc3c4c893096a33381aea4823726e5a9ebad72 100644 (file)
@@ -1,3 +1,3 @@
-__version__ = '0.4.6'
+__version__ = '0.4.7'
 __author__ = 'RicterZ'
 __email__ = 'ricterzheng@gmail.com'
index 2d59309f50ffa7fefcc9e11c327a4429d1cca27e..59dadac91c1167dba4f12d4a34c04c123b329a7d 100644 (file)
@@ -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:
index 47fbc3c3fe9350e72169b057e75ddff048d77404..b44f9d20c64da13c5aa0ed7131a30500ada4c2a6 100644 (file)
@@ -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:
index 8ec89f7e87ade92e21b49ada38ddee205bb435e8..e27765e17918cd1e9e4779fe7a3829a7c3ed5fa3 100644 (file)
@@ -33,5 +33,6 @@ CONFIG = {
     'proxy': {},
     'cookie': '',
     'language': '',
+    'template': '',
 }
 
index fb7355909fa07d32e750074c2aa34b2d05fd1c7b..b3358e461fcc774224f0fa1844448204999cef1b 100644 (file)
@@ -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 += '<img src="{0}" class="image-item"/>\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/default/index.html b/nhentai/viewer/default/index.html
new file mode 100644 (file)
index 0000000..33ea2af
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>\r
+<html>\r
+<head>\r
+    <meta charset="UTF-8">\r
+    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />\r
+    <title>{TITLE}</title>\r
+    <style>\r
+{STYLES}\r
+    </style>\r
+</head>\r
+<body>\r
+\r
+<nav id="list">\r
+{IMAGES}</nav>\r
+\r
+<div id="image-container">\r
+    <span id="page-num"></span>\r
+    <div id="dest"></div>\r
+</div>\r
+\r
+<script>\r
+{SCRIPTS}\r
+</script>\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/nhentai/viewer/default/scripts.js b/nhentai/viewer/default/scripts.js
new file mode 100644 (file)
index 0000000..e1301b0
--- /dev/null
@@ -0,0 +1,85 @@
+const pages = Array.from(document.querySelectorAll('img.image-item'));
+let currentPage = 0;
+
+function changePage(pageNum) {
+    const previous = pages[currentPage];
+    const current = pages[pageNum];
+
+    if (current == null) {
+        return;
+    }
+    
+    previous.classList.remove('current');
+    current.classList.add('current');
+
+    currentPage = pageNum;
+
+    const display = document.getElementById('dest');
+    display.style.backgroundImage = `url("${current.src}")`;
+
+    scroll(0,0)
+
+    document.getElementById('page-num')
+        .innerText = [
+                (pageNum + 1).toLocaleString(),
+                pages.length.toLocaleString()
+            ].join('\u200a/\u200a');
+}
+
+changePage(0);
+
+document.getElementById('list').onclick = event => {
+    if (pages.includes(event.target)) {
+        changePage(pages.indexOf(event.target));
+    }
+};
+
+document.getElementById('image-container').onclick = event => {
+    const width = document.getElementById('image-container').clientWidth;
+    const clickPos = event.clientX / width;
+
+    if (clickPos < 0.5) {
+        changePage(currentPage - 1);
+    } else {
+        changePage(currentPage + 1);
+    }
+};
+
+document.onkeypress = event => {
+    switch (event.key.toLowerCase()) {
+        // Previous Image
+        case 'w':
+          scrollBy(0, -40);
+          break;
+        case 'a':
+            changePage(currentPage - 1);
+            break;
+        // Return to previous page
+        case 'q':
+            window.history.go(-1);
+            break;
+        // Next Image
+        case ' ':
+        case 's':
+           scrollBy(0, 40);
+            break;
+        case 'd':
+            changePage(currentPage + 1);
+            break;
+    }// remove arrow cause it won't work
+};
+
+document.onkeydown = event =>{
+    switch (event.keyCode) {
+        case 37: //left
+            changePage(currentPage - 1);
+            break;
+        case 38: //up
+            break;
+        case 39: //right
+            changePage(currentPage + 1);
+            break;
+        case 40: //down
+            break;
+    }
+};
\ No newline at end of file
diff --git a/nhentai/viewer/default/styles.css b/nhentai/viewer/default/styles.css
new file mode 100644 (file)
index 0000000..62dfbe4
--- /dev/null
@@ -0,0 +1,70 @@
+  
+*, *::after, *::before {
+    box-sizing: border-box;
+}
+
+img {
+    vertical-align: middle;
+}
+
+html, body {
+    display: flex;
+    background-color: #e8e6e6;
+    height: 100%;
+    width: 100%;
+    padding: 0;
+    margin: 0;
+    font-family: sans-serif;
+}
+
+#list {
+    height: 2000px;
+    overflow: scroll;
+    width: 260px;
+    text-align: center;
+}
+
+#list img {
+    width: 200px;
+    padding: 10px;
+    border-radius: 10px;
+    margin: 15px 0;
+    cursor: pointer;
+}
+
+#list img.current {
+    background: #0003;
+}
+
+#image-container {
+    flex: auto;
+    height: 2000px;
+    background: #222;
+    color: #fff;
+    text-align: center;
+    cursor: pointer;
+    -webkit-user-select: none;
+    user-select: none;
+    position: relative;
+}
+
+#image-container #dest {
+    height: 2000px;
+    width: 100%;
+    background-size: contain;
+    background-repeat: no-repeat;
+    background-position: top;
+}
+
+#image-container #page-num {
+    position: static;
+    font-size: 14pt;
+    left: 10px;
+    bottom: 5px;
+    font-weight: bold;
+    opacity: 0.75;
+    text-shadow: /* Duplicate the same shadow to make it very strong */
+        0 0 2px #222,
+        0 0 2px #222,
+        0 0 2px #222;
+}
\ No newline at end of file
diff --git a/nhentai/viewer/index.html b/nhentai/viewer/index.html
deleted file mode 100644 (file)
index 33ea2af..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<!DOCTYPE html>\r
-<html>\r
-<head>\r
-    <meta charset="UTF-8">\r
-    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />\r
-    <title>{TITLE}</title>\r
-    <style>\r
-{STYLES}\r
-    </style>\r
-</head>\r
-<body>\r
-\r
-<nav id="list">\r
-{IMAGES}</nav>\r
-\r
-<div id="image-container">\r
-    <span id="page-num"></span>\r
-    <div id="dest"></div>\r
-</div>\r
-\r
-<script>\r
-{SCRIPTS}\r
-</script>\r
-</body>\r
-</html>
\ No newline at end of file
diff --git a/nhentai/viewer/scripts.js b/nhentai/viewer/scripts.js
deleted file mode 100644 (file)
index e1301b0..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-const pages = Array.from(document.querySelectorAll('img.image-item'));
-let currentPage = 0;
-
-function changePage(pageNum) {
-    const previous = pages[currentPage];
-    const current = pages[pageNum];
-
-    if (current == null) {
-        return;
-    }
-    
-    previous.classList.remove('current');
-    current.classList.add('current');
-
-    currentPage = pageNum;
-
-    const display = document.getElementById('dest');
-    display.style.backgroundImage = `url("${current.src}")`;
-
-    scroll(0,0)
-
-    document.getElementById('page-num')
-        .innerText = [
-                (pageNum + 1).toLocaleString(),
-                pages.length.toLocaleString()
-            ].join('\u200a/\u200a');
-}
-
-changePage(0);
-
-document.getElementById('list').onclick = event => {
-    if (pages.includes(event.target)) {
-        changePage(pages.indexOf(event.target));
-    }
-};
-
-document.getElementById('image-container').onclick = event => {
-    const width = document.getElementById('image-container').clientWidth;
-    const clickPos = event.clientX / width;
-
-    if (clickPos < 0.5) {
-        changePage(currentPage - 1);
-    } else {
-        changePage(currentPage + 1);
-    }
-};
-
-document.onkeypress = event => {
-    switch (event.key.toLowerCase()) {
-        // Previous Image
-        case 'w':
-          scrollBy(0, -40);
-          break;
-        case 'a':
-            changePage(currentPage - 1);
-            break;
-        // Return to previous page
-        case 'q':
-            window.history.go(-1);
-            break;
-        // Next Image
-        case ' ':
-        case 's':
-           scrollBy(0, 40);
-            break;
-        case 'd':
-            changePage(currentPage + 1);
-            break;
-    }// remove arrow cause it won't work
-};
-
-document.onkeydown = event =>{
-    switch (event.keyCode) {
-        case 37: //left
-            changePage(currentPage - 1);
-            break;
-        case 38: //up
-            break;
-        case 39: //right
-            changePage(currentPage + 1);
-            break;
-        case 40: //down
-            break;
-    }
-};
\ No newline at end of file
diff --git a/nhentai/viewer/styles.css b/nhentai/viewer/styles.css
deleted file mode 100644 (file)
index 62dfbe4..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-  
-*, *::after, *::before {
-    box-sizing: border-box;
-}
-
-img {
-    vertical-align: middle;
-}
-
-html, body {
-    display: flex;
-    background-color: #e8e6e6;
-    height: 100%;
-    width: 100%;
-    padding: 0;
-    margin: 0;
-    font-family: sans-serif;
-}
-
-#list {
-    height: 2000px;
-    overflow: scroll;
-    width: 260px;
-    text-align: center;
-}
-
-#list img {
-    width: 200px;
-    padding: 10px;
-    border-radius: 10px;
-    margin: 15px 0;
-    cursor: pointer;
-}
-
-#list img.current {
-    background: #0003;
-}
-
-#image-container {
-    flex: auto;
-    height: 2000px;
-    background: #222;
-    color: #fff;
-    text-align: center;
-    cursor: pointer;
-    -webkit-user-select: none;
-    user-select: none;
-    position: relative;
-}
-
-#image-container #dest {
-    height: 2000px;
-    width: 100%;
-    background-size: contain;
-    background-repeat: no-repeat;
-    background-position: top;
-}
-
-#image-container #page-num {
-    position: static;
-    font-size: 14pt;
-    left: 10px;
-    bottom: 5px;
-    font-weight: bold;
-    opacity: 0.75;
-    text-shadow: /* Duplicate the same shadow to make it very strong */
-        0 0 2px #222,
-        0 0 2px #222,
-        0 0 2px #222;
-}
\ No newline at end of file