mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
new feature #396
This commit is contained in:
parent
2e895d8d0f
commit
34c1ea8952
@ -9,7 +9,7 @@ from urllib.parse import urlparse
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from nhentai import __version__
|
from nhentai import __version__
|
||||||
from nhentai.utils import generate_html, generate_main_html, DB
|
from nhentai.utils import generate_html, generate_main_html, DB, EXTENSIONS
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
from nhentai.constant import PATH_SEPARATOR
|
from nhentai.constant import PATH_SEPARATOR
|
||||||
|
|
||||||
@ -114,8 +114,9 @@ def cmd_parser():
|
|||||||
default=False, help='no padding in the images filename, such as \'001.jpg\'')
|
default=False, help='no padding in the images filename, such as \'001.jpg\'')
|
||||||
|
|
||||||
# generate options
|
# generate options
|
||||||
parser.add_option('--html', dest='html_viewer', action='store_true',
|
parser.add_option('--html', dest='html_viewer', action='store', default=None,
|
||||||
help='generate a html viewer at current directory')
|
help='generate an HTML viewer in the specified directory, or scan all subfolders'
|
||||||
|
' within the entire directory to generate the HTML viewer.')
|
||||||
parser.add_option('--no-html', dest='is_nohtml', action='store_true',
|
parser.add_option('--no-html', dest='is_nohtml', action='store_true',
|
||||||
help='don\'t generate HTML after downloading')
|
help='don\'t generate HTML after downloading')
|
||||||
parser.add_option('--gen-main', dest='main_viewer', action='store_true',
|
parser.add_option('--gen-main', dest='main_viewer', action='store_true',
|
||||||
@ -159,7 +160,26 @@ def cmd_parser():
|
|||||||
args, _ = parser.parse_args(sys.argv[1:])
|
args, _ = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
if args.html_viewer:
|
if args.html_viewer:
|
||||||
generate_html(template=constant.CONFIG['template'])
|
if not os.path.exists(args.html_viewer):
|
||||||
|
logger.error(f'Path \'{args.html_viewer}\' not exists')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(args.html_viewer):
|
||||||
|
if not dirs:
|
||||||
|
generate_html(output_dir=args.html_viewer, template=constant.CONFIG['template'])
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
for dir_name in dirs:
|
||||||
|
# it will scan the entire subdirectories
|
||||||
|
doujinshi_dir = os.path.join(root, dir_name)
|
||||||
|
items = set(map(lambda s: os.path.splitext(s)[1], os.listdir(doujinshi_dir)))
|
||||||
|
|
||||||
|
# skip directory without any images
|
||||||
|
if items & set(EXTENSIONS):
|
||||||
|
generate_html(output_dir=doujinshi_dir, template=constant.CONFIG['template'])
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if args.main_viewer and not args.id and not args.keyword and not args.favorites:
|
if args.main_viewer and not args.id and not args.keyword and not args.favorites:
|
||||||
|
@ -109,6 +109,9 @@ def parse_doujinshi_obj(
|
|||||||
|
|
||||||
filename = os.path.join(output_dir, _filename)
|
filename = os.path.join(output_dir, _filename)
|
||||||
else:
|
else:
|
||||||
|
if file_type == 'html':
|
||||||
|
return output_dir, 'index.html'
|
||||||
|
|
||||||
doujinshi_dir = f'.{PATH_SEPARATOR}'
|
doujinshi_dir = f'.{PATH_SEPARATOR}'
|
||||||
|
|
||||||
if not os.path.exists(doujinshi_dir):
|
if not os.path.exists(doujinshi_dir):
|
||||||
@ -118,7 +121,7 @@ def parse_doujinshi_obj(
|
|||||||
|
|
||||||
|
|
||||||
def generate_html(output_dir='.', doujinshi_obj=None, template='default'):
|
def generate_html(output_dir='.', doujinshi_obj=None, template='default'):
|
||||||
doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, '.html')
|
doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, 'html')
|
||||||
image_html = ''
|
image_html = ''
|
||||||
|
|
||||||
if not os.path.exists(doujinshi_dir):
|
if not os.path.exists(doujinshi_dir):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user