mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
store proxy config
This commit is contained in:
parent
86b3a092c7
commit
f10ae3cf58
@ -69,7 +69,7 @@ def cmd_parser():
|
||||
parser.add_option('--delay', '-d', type='int', dest='delay', action='store', default=0,
|
||||
help='slow down between downloading every doujinshi')
|
||||
parser.add_option('--proxy', '-p', type='string', dest='proxy', action='store', default='',
|
||||
help='uses a proxy, for example: http://127.0.0.1:1080')
|
||||
help='store a proxy, for example: -p \'http://127.0.0.1:1080\'')
|
||||
parser.add_option('--file', '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
|
||||
parser.add_option('--format', type='string', dest='name_format', action='store',
|
||||
help='format the saved folder name', default='[%i][%a][%t]')
|
||||
@ -125,6 +125,29 @@ def cmd_parser():
|
||||
logger.info('Cookie saved.')
|
||||
exit(0)
|
||||
|
||||
if os.path.exists(os.path.join(constant.NHENTAI_HOME, 'proxy')):
|
||||
with open(os.path.join(constant.NHENTAI_HOME, 'proxy'), 'r') as f:
|
||||
link = f.read()
|
||||
constant.PROXY = {'http': link, 'https': link}
|
||||
|
||||
if args.proxy:
|
||||
try:
|
||||
if not os.path.exists(constant.NHENTAI_HOME):
|
||||
os.mkdir(constant.NHENTAI_HOME)
|
||||
|
||||
proxy_url = urlparse(args.proxy)
|
||||
if proxy_url.scheme not in ('http', 'https'):
|
||||
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
|
||||
else:
|
||||
with open(os.path.join(constant.NHENTAI_HOME, 'proxy'), 'w') as f:
|
||||
f.write(args.proxy)
|
||||
except Exception as e:
|
||||
logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
|
||||
exit(1)
|
||||
|
||||
logger.info('Proxy \'{0}\' saved.'.format(args.proxy))
|
||||
exit(0)
|
||||
|
||||
'''
|
||||
if args.login:
|
||||
try:
|
||||
@ -168,16 +191,4 @@ def cmd_parser():
|
||||
logger.critical('Maximum number of used threads is 15')
|
||||
exit(1)
|
||||
|
||||
if args.proxy:
|
||||
proxy_url = urlparse(args.proxy)
|
||||
if args.proxy == 'default' or 'd':
|
||||
constant.PROXY = {
|
||||
'http': "http://127.0.0.1:1080",
|
||||
'https': "http://127.0.0.1:1080"
|
||||
}
|
||||
elif proxy_url.scheme not in ('http', 'https'):
|
||||
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
|
||||
else:
|
||||
constant.PROXY = {'http': args.proxy, 'https': args.proxy}
|
||||
|
||||
return args
|
||||
|
@ -61,6 +61,7 @@ def main():
|
||||
generate_html(options.output_dir, doujinshi)
|
||||
elif options.is_cbz:
|
||||
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
|
||||
if options.main_viewer:
|
||||
generate_main_html(options.output_dir)
|
||||
if not platform.system() == 'Windows':
|
||||
logger.log(15, '🍻 All done.')
|
||||
|
@ -84,8 +84,7 @@ def generate_html(output_dir='.', doujinshi_obj=None):
|
||||
def generate_main_html(output_dir='.'):
|
||||
"""Generete a main html to show all the contain doujinshi.
|
||||
With a link to thier `index.html`.
|
||||
Default output folder will be the CLI path.
|
||||
"""
|
||||
Default output folder will be the CLI path."""
|
||||
count = 0
|
||||
image_html = ''
|
||||
main = readfile('viewer/main.html')
|
||||
@ -115,7 +114,7 @@ def generate_main_html(output_dir='.'):
|
||||
if 'index.html' in files:
|
||||
count += 1
|
||||
else:
|
||||
logger.warning('{} folder does not have index.html, try use --html arg first.'\
|
||||
logger.warning('{} folder does not have index.html (try use --html arg first).'
|
||||
.format(folder))
|
||||
continue
|
||||
image = files[0] # 001.jpg or 001.png
|
||||
@ -138,10 +137,10 @@ def generate_main_html(output_dir='.'):
|
||||
else:
|
||||
with open('./main.html', 'wb') as f:
|
||||
f.write(data.encode('utf-8'))
|
||||
logger.log(15, 'Main Viewer has been write to \'{0}/main.html\''.format(output_dir))
|
||||
logger.log(
|
||||
15, 'Main Viewer has been write to \'{0}/main.html\''.format(output_dir))
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user