mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-19 18:31:24 +02:00
Main viewer generator
This commit is contained in:
parent
18bdab1962
commit
0cda30385b
@ -86,7 +86,53 @@ def generate_main_html(output_dir='.'):
|
||||
With a link to thier `index.html`.
|
||||
Default output folder will be the CLI path.
|
||||
"""
|
||||
pass
|
||||
count = 0
|
||||
image_html = ''
|
||||
main = readfile('viewer/main.html')
|
||||
css = readfile('viewer/main.css')
|
||||
element = '\n\
|
||||
<div class="gallery-favorite">\n\
|
||||
<div class="gallery">\n\
|
||||
<a href="./{FOLDER}/index.html" class="cover" style="padding:0 0 141.6% 0"><img\n\
|
||||
src="./{FOLDER}/{IMAGE}" />\n\
|
||||
<div class="caption">{TITLE}</div>\n\
|
||||
</a>\n\
|
||||
</div>\n\
|
||||
</div>\n'
|
||||
|
||||
os.chdir(output_dir) # switch to given dir
|
||||
doujinshi_dirs = next(os.walk('.'))[1]
|
||||
# https://stackoverflow.com/questions/141291/how-to-list-only-top-level-directories-in-python
|
||||
|
||||
for folder in doujinshi_dirs:
|
||||
files = os.listdir(folder)
|
||||
if 'index.html' in files:
|
||||
count += 1
|
||||
else:
|
||||
logger.warning('{} folder does not have index.html, try use --html arg first.'\
|
||||
.format(folder))
|
||||
continue
|
||||
image = files[0] # 001.jpg or 001.png
|
||||
if folder is not None:
|
||||
title = folder.replace('_', ' ')
|
||||
if sys.version_info < (3, 0):
|
||||
title = title.encode('utf-8')
|
||||
else:
|
||||
title = 'nHentai HTML Viewer'
|
||||
image_html += element.format(FOLDER=folder, IMAGE=image, TITLE=title)
|
||||
|
||||
data = main.format(STYLES=css, COUNT=count, PICTURE=image_html)
|
||||
try:
|
||||
if sys.version_info < (3, 0):
|
||||
with open('./main.html', 'w') as f:
|
||||
f.write(data)
|
||||
else:
|
||||
with open('./main.html', 'wb') as f:
|
||||
f.write(data.encode('utf-8'))
|
||||
logger.log(15, 'Main Viewer has been write to \'{0}\''.format('./main.html'))
|
||||
except Exception as e:
|
||||
logger.warning('Writen Main Viewer failed ({})'.format(str(e)))
|
||||
logger.info('==>Process finished.')
|
||||
|
||||
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
||||
if doujinshi_obj is not None:
|
||||
|
@ -5,11 +5,9 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="theme-color" content="#1f1f1f" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||
<title>
|
||||
nHentai
|
||||
» Viewer</title>
|
||||
<link rel="stylesheet" href="https://static.nhentai.net/css/main_style.9bb9b703e601.css">
|
||||
{STYLE}
|
||||
<title>nHentai » Viewer</title>
|
||||
<!-- <link rel="stylesheet" href="./main.css"> -->
|
||||
<style>{STYLES}</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -20,13 +18,6 @@
|
||||
<div class="container" id="favcontainer">
|
||||
|
||||
{PICTURE}
|
||||
<div class="gallery-favorite">
|
||||
<div class="gallery">
|
||||
<a href="/folder/index.html" class="cover" style="padding:0 0 141.6% 0"><img
|
||||
src="/?.jpg" />
|
||||
<div class="caption">{TITLE}</div>
|
||||
</a></div>
|
||||
</div>
|
||||
|
||||
</div> <!-- container -->
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user