]> git.lizzy.rs Git - nhentai.git/commitdiff
add cookie check
authorRicterZ <ricterzheng@gmail.com>
Wed, 12 Jun 2019 14:45:44 +0000 (22:45 +0800)
committerRicterZ <ricterzheng@gmail.com>
Wed, 12 Jun 2019 14:45:44 +0000 (22:45 +0800)
nhentai/command.py
nhentai/utils.py

index d45d20f12b403b50f4603bd7980b299b2c2942c4..10176ea8deefae192892412d247e4fa39707ea00 100644 (file)
@@ -11,7 +11,7 @@ from nhentai.doujinshi import Doujinshi
 from nhentai.downloader import Downloader
 from nhentai.logger import logger
 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():
@@ -24,6 +24,9 @@ def main():
     if PROXY != {}:
         logger.info('Using proxy: {0}'.format(PROXY))
 
+    # check your cookie
+    check_cookie()
+
     doujinshi_ids = []
     doujinshi_list = []
 
index 63db14c5fed003028525712cf205726063dcecc9..3bdf278c9d33ec9cacba4bfaceac73c4275b2cf5 100644 (file)
@@ -2,6 +2,7 @@
 from __future__ import unicode_literals, print_function
 
 import sys
+import re
 import os
 import string
 import zipfile
@@ -22,6 +23,15 @@ def request(method, url, **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):
     """ A metaclass that creates a Singleton base class when called. """
     _instances = {}