add cookie check

This commit is contained in:
RicterZ 2019-06-12 22:45:44 +08:00
parent 58b2b644c1
commit 1af195d727
2 changed files with 14 additions and 1 deletions

View File

@ -11,7 +11,7 @@ from nhentai.doujinshi import Doujinshi
from nhentai.downloader import Downloader from nhentai.downloader import Downloader
from nhentai.logger import logger from nhentai.logger import logger
from nhentai.constant import BASE_URL from nhentai.constant import BASE_URL
from nhentai.utils import generate_html, generate_cbz, generate_main_html from nhentai.utils import generate_html, generate_cbz, generate_main_html, check_cookie
def main(): def main():
@ -24,6 +24,9 @@ def main():
if PROXY != {}: if PROXY != {}:
logger.info('Using proxy: {0}'.format(PROXY)) logger.info('Using proxy: {0}'.format(PROXY))
# check your cookie
check_cookie()
doujinshi_ids = [] doujinshi_ids = []
doujinshi_list = [] doujinshi_list = []

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals, print_function from __future__ import unicode_literals, print_function
import sys import sys
import re
import os import os
import string import string
import zipfile import zipfile
@ -22,6 +23,15 @@ def request(method, url, **kwargs):
return getattr(session, method)(url, proxies=constant.PROXY, verify=False, **kwargs) return getattr(session, method)(url, proxies=constant.PROXY, verify=False, **kwargs)
def check_cookie():
response = request('get', constant.BASE_URL).text
username = re.findall('"/users/\d+/(.*?)"', response)
if not username:
logger.error('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie')
else:
logger.info('Login successfully! Your username: {}'.format(username[0]))
class _Singleton(type): class _Singleton(type):
""" A metaclass that creates a Singleton base class when called. """ """ A metaclass that creates a Singleton base class when called. """
_instances = {} _instances = {}