mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-19 18:31:24 +02:00
Merge pull request #244 from krrr/master
This commit is contained in:
commit
ea356a1ca2
@ -72,7 +72,7 @@ Set your nhentai cookie against captcha:
|
|||||||
|
|
||||||
nhentai --cookie "YOUR COOKIE FROM nhentai.net"
|
nhentai --cookie "YOUR COOKIE FROM nhentai.net"
|
||||||
|
|
||||||
**NOTE**: The format of the cookie is `"csrftoken=TOKEN; sessionid=ID"`
|
**NOTE**: The format of the cookie is `"csrftoken=TOKEN; sessionid=ID; cf_chl_2=CLOUDFLARE; cf_chl_prog=CLOUDFLARE; cf_clearance=CLOUDFLARE"`
|
||||||
|
|
||||||
| To get csrftoken and sessionid, first login to your nhentai account in web browser, then:
|
| To get csrftoken and sessionid, first login to your nhentai account in web browser, then:
|
||||||
| (Chrome) |ve| |ld| More tools |ld| Developer tools |ld| Application |ld| Storage |ld| Cookies |ld| https://nhentai.net
|
| (Chrome) |ve| |ld| More tools |ld| Developer tools |ld| Application |ld| Storage |ld| Cookies |ld| https://nhentai.net
|
||||||
|
@ -109,7 +109,9 @@ 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 Cloudflare captcha')
|
||||||
|
parser.add_option('--useragent', type='str', dest='useragent', action='store',
|
||||||
|
help='set useragent to bypass Cloudflare captcha')
|
||||||
parser.add_option('--language', type='str', dest='language', action='store',
|
parser.add_option('--language', type='str', dest='language', action='store',
|
||||||
help='set default language to parse doujinshis')
|
help='set default language to parse doujinshis')
|
||||||
parser.add_option('--clean-language', dest='clean_language', action='store_true', default=False,
|
parser.add_option('--clean-language', dest='clean_language', action='store_true', default=False,
|
||||||
@ -148,20 +150,24 @@ def cmd_parser():
|
|||||||
# --- set config ---
|
# --- set config ---
|
||||||
if args.cookie is not None:
|
if args.cookie is not None:
|
||||||
constant.CONFIG['cookie'] = args.cookie
|
constant.CONFIG['cookie'] = args.cookie
|
||||||
|
write_config()
|
||||||
logger.info('Cookie saved.')
|
logger.info('Cookie saved.')
|
||||||
write_config()
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
elif args.useragent is not None:
|
||||||
if args.language is not None:
|
constant.CONFIG['useragent'] = args.useragent
|
||||||
constant.CONFIG['language'] = args.language
|
|
||||||
logger.info('Default language now set to \'{0}\''.format(args.language))
|
|
||||||
write_config()
|
write_config()
|
||||||
|
logger.info('Useragent saved.')
|
||||||
|
exit(0)
|
||||||
|
elif args.language is not None:
|
||||||
|
constant.CONFIG['language'] = args.language
|
||||||
|
write_config()
|
||||||
|
logger.info('Default language now set to \'{0}\''.format(args.language))
|
||||||
exit(0)
|
exit(0)
|
||||||
# TODO: search without language
|
# TODO: search without language
|
||||||
|
|
||||||
if args.proxy is not None:
|
if args.proxy is not None:
|
||||||
proxy_url = urlparse(args.proxy)
|
proxy_url = urlparse(args.proxy)
|
||||||
if not args.proxy == '' and proxy_url.scheme not in ('http', 'https'):
|
if not args.proxy == '' and proxy_url.scheme not in ('http', 'https', 'socks5', 'socks5h', 'socks4', 'socks4a'):
|
||||||
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
|
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
|
||||||
exit(0)
|
exit(0)
|
||||||
else:
|
else:
|
||||||
|
@ -93,9 +93,6 @@ def main():
|
|||||||
doujinshi.downloader = downloader
|
doujinshi.downloader = downloader
|
||||||
doujinshi.download()
|
doujinshi.download()
|
||||||
|
|
||||||
doujinshi.downloader = downloader
|
|
||||||
doujinshi.download()
|
|
||||||
|
|
||||||
if options.generate_metadata:
|
if options.generate_metadata:
|
||||||
table = doujinshi.table
|
table = doujinshi.table
|
||||||
generate_metadata_file(options.output_dir, table, doujinshi)
|
generate_metadata_file(options.output_dir, table, doujinshi)
|
||||||
|
@ -34,6 +34,7 @@ CONFIG = {
|
|||||||
'cookie': '',
|
'cookie': '',
|
||||||
'language': '',
|
'language': '',
|
||||||
'template': '',
|
'template': '',
|
||||||
|
'useragent': 'nhentai command line client (https://github.com/RicterZ/nhentai)'
|
||||||
}
|
}
|
||||||
|
|
||||||
LANGUAGEISO ={
|
LANGUAGEISO ={
|
||||||
|
@ -17,7 +17,7 @@ def request(method, url, **kwargs):
|
|||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.headers.update({
|
session.headers.update({
|
||||||
'Referer': constant.LOGIN_URL,
|
'Referer': constant.LOGIN_URL,
|
||||||
'User-Agent': 'nhentai command line client (https://github.com/RicterZ/nhentai)',
|
'User-Agent': constant.CONFIG['useragent'],
|
||||||
'Cookie': constant.CONFIG['cookie']
|
'Cookie': constant.CONFIG['cookie']
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -28,10 +28,14 @@ def request(method, url, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def check_cookie():
|
def check_cookie():
|
||||||
response = request('get', constant.BASE_URL).text
|
response = request('get', constant.BASE_URL)
|
||||||
username = re.findall('"/users/\d+/(.*?)"', response)
|
if response.status_code == 503 and 'cf-browser-verification' in response.text:
|
||||||
|
logger.error('Blocked by Cloudflare captcha, please set your cookie and useragent')
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
username = re.findall('"/users/\d+/(.*?)"', response.text)
|
||||||
if not username:
|
if not username:
|
||||||
logger.error('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie')
|
logger.warning('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie')
|
||||||
else:
|
else:
|
||||||
logger.info('Login successfully! Your username: {}'.format(username[0]))
|
logger.info('Login successfully! Your username: {}'.format(username[0]))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user