mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 11:01:17 +02:00
add html doujinshi viewer
This commit is contained in:
parent
42a09e2c1e
commit
d1ed9b6980
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python2.7
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
|
import os
|
||||||
import signal
|
import signal
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
@ -43,6 +44,30 @@ def main():
|
|||||||
doujinshi.downloader = downloader
|
doujinshi.downloader = downloader
|
||||||
doujinshi.download()
|
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 += '<img src="{0}" class="image-item {1}" attr-prev="{2}" attr-next="{3}">\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':
|
if not platform.system() == 'Windows':
|
||||||
logger.log(15, '🍺 All done.')
|
logger.log(15, '🍺 All done.')
|
||||||
else:
|
else:
|
||||||
|
126
nhentai/doujinshi.html
Normal file
126
nhentai/doujinshi.html
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{TITLE}</title>
|
||||||
|
<style>
|
||||||
|
html, body {{
|
||||||
|
background-color: #e8e6e6;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.container img {{
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
margin: 30px 0;
|
||||||
|
padding: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.container {{
|
||||||
|
height: 100%;
|
||||||
|
overflow: scroll;
|
||||||
|
background: #e8e6e6;
|
||||||
|
width: 200px;
|
||||||
|
padding: 30px;
|
||||||
|
float: left;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.image {{
|
||||||
|
margin-left: 260px;
|
||||||
|
height: 100%;
|
||||||
|
background: #222;
|
||||||
|
text-align: center;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.image img {{
|
||||||
|
height: 100%;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.i a {{
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
width: 50%;
|
||||||
|
height: 100%;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.i {{
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.current {{
|
||||||
|
background: #BBB;
|
||||||
|
border-radius: 10px;
|
||||||
|
}}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function cursorfocus(elem) {{
|
||||||
|
var container = document.getElementsByClassName('container')[0];
|
||||||
|
container.scrollTop = elem.offsetTop - 500;
|
||||||
|
}}
|
||||||
|
|
||||||
|
function getImage(type) {{
|
||||||
|
var current = document.getElementsByClassName("current")[0];
|
||||||
|
current.className = "image-item";
|
||||||
|
var img_src = type == 1 ? current.getAttribute('attr-next') : current.getAttribute('attr-prev');
|
||||||
|
if (img_src === "") {{
|
||||||
|
img_src = current.src;
|
||||||
|
}}
|
||||||
|
|
||||||
|
var img_list = document.getElementsByClassName("image-item");
|
||||||
|
for (i=0; i<img_list.length; i++) {{
|
||||||
|
if (img_list[i].src.endsWith(img_src)) {{
|
||||||
|
img_list[i].className = "image-item current";
|
||||||
|
cursorfocus(img_list[i]);
|
||||||
|
break;
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
var display = document.getElementById("dest");
|
||||||
|
display.src = img_src;
|
||||||
|
display.focus();
|
||||||
|
}}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
{IMAGES}</div>
|
||||||
|
<div class="image">
|
||||||
|
<div class="i">
|
||||||
|
<img src="" id="dest">
|
||||||
|
<a href="javascript:getImage(-1)" style="left: 0;"></a>
|
||||||
|
<a href="javascript:getImage(1)" style="left: 50%;"></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var img_list = document.getElementsByClassName("image-item");
|
||||||
|
|
||||||
|
var display = document.getElementById("dest");
|
||||||
|
display.src = img_list[0].src;
|
||||||
|
|
||||||
|
for (var i = 0; i < img_list.length; i++) {{
|
||||||
|
img_list[i].addEventListener('click', function() {{
|
||||||
|
var current = document.getElementsByClassName("current")[0];
|
||||||
|
current.className = "image-item";
|
||||||
|
this.className = "image-item current";
|
||||||
|
var display = document.getElementById("dest");
|
||||||
|
display.src = this.src;
|
||||||
|
display.focus();
|
||||||
|
}}, false);
|
||||||
|
}}
|
||||||
|
|
||||||
|
document.onkeypress = function(e) {{
|
||||||
|
if (e.keyCode == 32) {{
|
||||||
|
getImage(1);
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
</script>
|
||||||
|
</html>
|
@ -14,6 +14,9 @@ from nhentai.parser import request
|
|||||||
from nhentai.utils import Singleton
|
from nhentai.utils import Singleton
|
||||||
|
|
||||||
|
|
||||||
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class NhentaiImageNotExistException(Exception):
|
class NhentaiImageNotExistException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user