mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-30 08:10:46 +02:00
fix --gen-main bugs
This commit is contained in:
parent
440bb0dc38
commit
a909ad6d92
@ -81,10 +81,14 @@ def generate_html(output_dir='.', doujinshi_obj=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning('Writen HTML Viewer failed ({})'.format(str(e)))
|
logger.warning('Writen HTML Viewer failed ({})'.format(str(e)))
|
||||||
|
|
||||||
def generate_main_html(output_dir='.'):
|
|
||||||
"""Generete a main html to show all the contain doujinshi.
|
def generate_main_html(output_dir='./'):
|
||||||
With a link to thier `index.html`.
|
"""
|
||||||
Default output folder will be the CLI path."""
|
Generate a main html to show all the contain doujinshi.
|
||||||
|
With a link to their `index.html`.
|
||||||
|
Default output folder will be the CLI path.
|
||||||
|
"""
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
image_html = ''
|
image_html = ''
|
||||||
main = readfile('viewer/main.html')
|
main = readfile('viewer/main.html')
|
||||||
@ -99,31 +103,26 @@ def generate_main_html(output_dir='.'):
|
|||||||
</div>\n\
|
</div>\n\
|
||||||
</div>\n'
|
</div>\n'
|
||||||
|
|
||||||
if output_dir == '':
|
|
||||||
os.chdir('.')
|
|
||||||
else:
|
|
||||||
os.chdir(output_dir)
|
os.chdir(output_dir)
|
||||||
# switch to given dir
|
|
||||||
doujinshi_dirs = next(os.walk('.'))[1]
|
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:
|
for folder in doujinshi_dirs:
|
||||||
if folder[0] is not '[':
|
|
||||||
continue
|
|
||||||
files = os.listdir(folder)
|
files = os.listdir(folder)
|
||||||
|
files.sort()
|
||||||
|
|
||||||
if 'index.html' in files:
|
if 'index.html' in files:
|
||||||
count += 1
|
count += 1
|
||||||
|
logger.info('Add doujinshi \'{}\''.format(folder))
|
||||||
else:
|
else:
|
||||||
logger.warning('{} folder does not have index.html (try use --html arg first).'
|
|
||||||
.format(folder))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
image = files[0] # 001.jpg or 001.png
|
image = files[0] # 001.jpg or 001.png
|
||||||
if folder is not None:
|
if folder is not None:
|
||||||
title = folder.replace('_', ' ')
|
title = folder.replace('_', ' ')
|
||||||
# if sys.version_info > (3, 0):
|
|
||||||
# title = title.encode('utf-8')
|
|
||||||
else:
|
else:
|
||||||
title = 'nHentai HTML Viewer'
|
title = 'nHentai HTML Viewer'
|
||||||
|
|
||||||
image_html += element.format(FOLDER=folder, IMAGE=image, TITLE=title)
|
image_html += element.format(FOLDER=folder, IMAGE=image, TITLE=title)
|
||||||
|
|
||||||
if image_html == '':
|
if image_html == '':
|
||||||
@ -142,6 +141,7 @@ def generate_main_html(output_dir='.'):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning('Writen Main Viewer failed ({})'.format(str(e)))
|
logger.warning('Writen Main Viewer failed ({})'.format(str(e)))
|
||||||
|
|
||||||
|
|
||||||
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user