+def generate_main_html(output_dir='./'):
+ """
+ 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.
+ """
+
+ image_html = ''
+
+ main = readfile('viewer/main.html')
+ css = readfile('viewer/main.css')
+ js = readfile('viewer/main.js')
+
+ 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)
+ doujinshi_dirs = next(os.walk('.'))[1]
+
+ for folder in doujinshi_dirs:
+ files = os.listdir(folder)
+ files.sort()
+
+ if 'index.html' in files:
+ logger.info('Add doujinshi \'{}\''.format(folder))
+ else:
+ continue
+
+ image = files[0] # 001.jpg or 001.png
+ if folder is not None:
+ title = folder.replace('_', ' ')
+ else:
+ title = 'nHentai HTML Viewer'
+
+ image_html += element.format(FOLDER=folder, IMAGE=image, TITLE=title)
+ if image_html == '':
+ logger.warning('No index.html found, --gen-main paused.')
+ return
+ try:
+ data = main.format(STYLES=css, SCRIPTS=js, PICTURE=image_html)
+ 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'))
+ shutil.copy(os.path.dirname(__file__)+'/viewer/logo.png', './')
+ set_js_database()
+ logger.log(
+ 15, 'Main Viewer has been written to \'{0}main.html\''.format(output_dir))
+ except Exception as e:
+ logger.warning('Writing Main Viewer failed ({})'.format(str(e)))
+
+
+def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=False):