]> git.lizzy.rs Git - nhentai.git/blobdiff - nhentai/cmdline.py
fix timeout
[nhentai.git] / nhentai / cmdline.py
index 10f5ace28012b6b7090bd68610ddbaf77c2ab71c..eca33ac2219886791ea471e95da04eec5f8573bc 100644 (file)
@@ -1,5 +1,6 @@
 # coding: utf-8
 from __future__ import print_function
+import sys
 from optparse import OptionParser
 try:
     from itertools import ifilter as filter
@@ -10,9 +11,16 @@ import nhentai.constant as constant
 from nhentai.utils import urlparse
 from nhentai.logger import logger
 
+try:
+    reload(sys)
+    sys.setdefaultencoding(sys.stdin.encoding)
+except NameError:
+    # python3
+    pass
+
 
 def banner():
-    logger.info('''nHentai: あなたも変態。 いいね?
+    logger.info(u'''nHentai: あなたも変態。 いいね?
        _   _            _        _
  _ __ | | | | ___ _ __ | |_ __ _(_)
 | '_ \| |_| |/ _ \ '_ \| __/ _` | |
@@ -22,10 +30,13 @@ def banner():
 
 
 def cmd_parser():
-    parser = OptionParser()
-    parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not')
-    parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information.')
-    parser.add_option('--id', type='str', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3')
+    parser = OptionParser('\n  nhentai --search [keyword] --download'
+                          '\n  NHENTAI=http://h.loli.club nhentai --id [ID ...]'
+                          '\n\nEnvironment Variable:\n'
+                          '  NHENTAI                 nhentai mirror url')
+    parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi (for search result)')
+    parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information')
+    parser.add_option('--id', type='string', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3')
     parser.add_option('--search', type='string', dest='keyword', action='store', help='search doujinshi by keyword')
     parser.add_option('--page', type='int', dest='page', action='store', default=1,
                       help='page number of search result')
@@ -38,7 +49,15 @@ def cmd_parser():
                       help='timeout of download doujinshi')
     parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
                       help='use proxy, example: http://127.0.0.1:1080')
-    args, _ = parser.parse_args()
+
+    try:
+        sys.argv = list(map(lambda x: unicode(x.decode(sys.stdin.encoding)), sys.argv))
+    except (NameError, TypeError):
+        pass
+    except UnicodeDecodeError:
+        exit(0)
+
+    args, _ = parser.parse_args(sys.argv[1:])
 
     if args.tags:
         logger.warning('`--tags` is under construction')
@@ -60,8 +79,8 @@ def cmd_parser():
     if args.threads <= 0:
         args.threads = 1
 
-    elif args.threads > 10:
-        logger.critical('Maximum number of used threads is 10')
+    elif args.threads > 15:
+        logger.critical('Maximum number of used threads is 15')
         exit(0)
 
     if args.proxy: