add a new option #111

This commit is contained in:
RicterZ 2020-04-09 20:32:20 +08:00
parent d5f41bf37c
commit 5c7bdae0d7
2 changed files with 15 additions and 8 deletions

View File

@ -52,10 +52,12 @@ def cmd_parser():
help='search doujinshi by keyword') help='search doujinshi by keyword')
parser.add_option('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag') parser.add_option('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag')
parser.add_option('--artist', type='string', dest='artist', action='store', help='download doujinshi by artist') parser.add_option('--artist', type='string', dest='artist', action='store', help='download doujinshi by artist')
parser.add_option('--character', type='string', dest='character', action='store', help='download doujinshi by character') parser.add_option('--character', type='string', dest='character', action='store',
help='download doujinshi by character')
parser.add_option('--parody', type='string', dest='parody', action='store', help='download doujinshi by parody') parser.add_option('--parody', type='string', dest='parody', action='store', help='download doujinshi by parody')
parser.add_option('--group', type='string', dest='group', action='store', help='download doujinshi by group') parser.add_option('--group', type='string', dest='group', action='store', help='download doujinshi by group')
parser.add_option('--language', type='string', dest='language', action='store', help='download doujinshi by language') parser.add_option('--language', type='string', dest='language', action='store',
help='download doujinshi by language')
parser.add_option('--favorites', '-F', action='store_true', dest='favorites', parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
help='list or download your favorites.') help='list or download your favorites.')
@ -99,6 +101,8 @@ def cmd_parser():
# nhentai options # nhentai options
parser.add_option('--cookie', type='str', dest='cookie', action='store', parser.add_option('--cookie', type='str', dest='cookie', action='store',
help='set cookie of nhentai to bypass Google recaptcha') help='set cookie of nhentai to bypass Google recaptcha')
parser.add_option('--save-download-states', dest='is_save_download_states', action='store_true',
default=False, help='save downloaded doujinshis, whose will be skipped if you re-download them')
try: try:
sys.argv = [unicode(i.decode(sys.stdin.encoding)) for i in sys.argv] sys.argv = [unicode(i.decode(sys.stdin.encoding)) for i in sys.argv]
@ -120,8 +124,8 @@ def cmd_parser():
generate_main_html() generate_main_html()
exit(0) exit(0)
if os.path.exists(os.path.join(constant.NHENTAI_HOME, 'cookie')): if os.path.exists(constant.NHENTAI_COOKIE):
with open(os.path.join(constant.NHENTAI_HOME, 'cookie'), 'r') as f: with open(constant.NHENTAI_COOKIE, 'r') as f:
constant.COOKIE = f.read() constant.COOKIE = f.read()
if args.cookie: if args.cookie:
@ -129,7 +133,7 @@ def cmd_parser():
if not os.path.exists(constant.NHENTAI_HOME): if not os.path.exists(constant.NHENTAI_HOME):
os.mkdir(constant.NHENTAI_HOME) os.mkdir(constant.NHENTAI_HOME)
with open(os.path.join(constant.NHENTAI_HOME, 'cookie'), 'w') as f: with open(constant.NHENTAI_COOKIE, 'w') as f:
f.write(args.cookie) f.write(args.cookie)
except Exception as e: except Exception as e:
logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e))) logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
@ -138,8 +142,8 @@ 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')): if os.path.exists(constant.NHENTAI_PROXY):
with open(os.path.join(constant.NHENTAI_HOME, 'proxy'), 'r') as f: with open(constant.NHENTAI_PROXY, 'r') as f:
link = f.read() link = f.read()
constant.PROXY = {'http': link, 'https': link} constant.PROXY = {'http': link, 'https': link}
@ -152,8 +156,9 @@ def cmd_parser():
if proxy_url.scheme not in ('http', 'https'): if proxy_url.scheme not in ('http', 'https'):
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme)) logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
else: else:
with open(os.path.join(constant.NHENTAI_HOME, 'proxy'), 'w') as f: with open(constant.NHENTAI_PROXY, 'w') as f:
f.write(args.proxy) f.write(args.proxy)
except Exception as e: except Exception as e:
logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e))) logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
exit(1) exit(1)

View File

@ -33,6 +33,8 @@ u = urlparse(BASE_URL)
IMAGE_URL = '%s://i.%s/galleries' % (u.scheme, u.hostname) IMAGE_URL = '%s://i.%s/galleries' % (u.scheme, u.hostname)
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai') NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
NHENTAI_PROXY = os.path.join(NHENTAI_HOME, 'proxy')
NHENTAI_COOKIE = os.path.join(NHENTAI_HOME, 'cookie')
PROXY = {} PROXY = {}