mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 11:01:17 +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,
|
parser.add_option('--delay', '-d', type='int', dest='delay', action='store', default=0,
|
||||||
help='slow down between downloading every doujinshi')
|
help='slow down between downloading every doujinshi')
|
||||||
parser.add_option('--proxy', '-p', type='string', dest='proxy', action='store', default='',
|
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('--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',
|
parser.add_option('--format', type='string', dest='name_format', action='store',
|
||||||
help='format the saved folder name', default='[%i][%a][%t]')
|
help='format the saved folder name', default='[%i][%a][%t]')
|
||||||
@ -125,6 +125,29 @@ def cmd_parser():
|
|||||||
logger.info('Cookie saved.')
|
logger.info('Cookie saved.')
|
||||||
exit(0)
|
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:
|
if args.login:
|
||||||
try:
|
try:
|
||||||
@ -168,16 +191,4 @@ def cmd_parser():
|
|||||||
logger.critical('Maximum number of used threads is 15')
|
logger.critical('Maximum number of used threads is 15')
|
||||||
exit(1)
|
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
|
return args
|
||||||
|
@ -61,7 +61,8 @@ def main():
|
|||||||
generate_html(options.output_dir, doujinshi)
|
generate_html(options.output_dir, doujinshi)
|
||||||
elif options.is_cbz:
|
elif options.is_cbz:
|
||||||
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
|
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
|
||||||
generate_main_html(options.output_dir)
|
if options.main_viewer:
|
||||||
|
generate_main_html(options.output_dir)
|
||||||
if not platform.system() == 'Windows':
|
if not platform.system() == 'Windows':
|
||||||
logger.log(15, '🍻 All done.')
|
logger.log(15, '🍻 All done.')
|
||||||
else:
|
else:
|
||||||
|
@ -84,8 +84,7 @@ def generate_html(output_dir='.', doujinshi_obj=None):
|
|||||||
def generate_main_html(output_dir='.'):
|
def generate_main_html(output_dir='.'):
|
||||||
"""Generete a main html to show all the contain doujinshi.
|
"""Generete a main html to show all the contain doujinshi.
|
||||||
With a link to thier `index.html`.
|
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
|
count = 0
|
||||||
image_html = ''
|
image_html = ''
|
||||||
main = readfile('viewer/main.html')
|
main = readfile('viewer/main.html')
|
||||||
@ -99,13 +98,13 @@ def generate_main_html(output_dir='.'):
|
|||||||
</a>\n\
|
</a>\n\
|
||||||
</div>\n\
|
</div>\n\
|
||||||
</div>\n'
|
</div>\n'
|
||||||
|
|
||||||
if output_dir == '':
|
if output_dir == '':
|
||||||
os.chdir('.')
|
os.chdir('.')
|
||||||
else:
|
else:
|
||||||
os.chdir(output_dir)
|
os.chdir(output_dir)
|
||||||
# switch to given 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
|
# https://stackoverflow.com/questions/141291/how-to-list-only-top-level-directories-in-python
|
||||||
|
|
||||||
for folder in doujinshi_dirs:
|
for folder in doujinshi_dirs:
|
||||||
@ -115,10 +114,10 @@ def generate_main_html(output_dir='.'):
|
|||||||
if 'index.html' in files:
|
if 'index.html' in files:
|
||||||
count += 1
|
count += 1
|
||||||
else:
|
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))
|
.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):
|
# if sys.version_info > (3, 0):
|
||||||
@ -138,10 +137,10 @@ def generate_main_html(output_dir='.'):
|
|||||||
else:
|
else:
|
||||||
with open('./main.html', 'wb') as f:
|
with open('./main.html', 'wb') as f:
|
||||||
f.write(data.encode('utf-8'))
|
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:
|
except Exception as e:
|
||||||
logger.warning('Writen Main Viewer failed ({})'.format(str(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):
|
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user