From 049ab4d9ad35355bf61675273a0277a1c4bad538 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 19:34:54 +0800
Subject: [PATCH 01/25] using cookie rather than login #54

---
 nhentai/cmdline.py  | 64 +++++++++++++++++++++++++++++++++++----------
 nhentai/command.py  | 10 ++++---
 nhentai/constant.py |  5 ++++
 nhentai/parser.py   | 24 +++++++----------
 4 files changed, 71 insertions(+), 32 deletions(-)

diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py
index 533b3c8..3e2c512 100644
--- a/nhentai/cmdline.py
+++ b/nhentai/cmdline.py
@@ -1,14 +1,15 @@
 # coding: utf-8
 from __future__ import print_function
+import os
 import sys
 from optparse import OptionParser
-from nhentai import __version__
 try:
     from itertools import ifilter as filter
 except ImportError:
     pass
 
 import nhentai.constant as constant
+from nhentai import __version__
 from nhentai.utils import urlparse, generate_html
 from nhentai.logger import logger
 
@@ -40,16 +41,25 @@ def cmd_parser():
                           '\n  nhentai --file [filename]'    
                           '\n\nEnvironment Variable:\n'
                           '  NHENTAI                 nhentai mirror url')
+    # operation options
     parser.add_option('--download', dest='is_download', action='store_true',
                       help='download doujinshi (for search results)')
-    parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information')
+    parser.add_option('--show', dest='is_show', action='store_true', help='just show the doujinshi information')
+
+    # doujinshi options
     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('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag')
+    parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
+                      help='list or download your favorites.')
+
+    # page options
     parser.add_option('--page', type='int', dest='page', action='store', default=1,
                       help='page number of search results')
-    parser.add_option('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag')
     parser.add_option('--max-page', type='int', dest='max_page', action='store', default=1,
                       help='The max page when recursive download tagged doujinshi')
+
+    # download options
     parser.add_option('--output', type='string', dest='output_dir', action='store', default='',
                       help='output dir')
     parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
@@ -58,20 +68,21 @@ def cmd_parser():
                       help='timeout for downloading doujinshi')
     parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
                       help='uses a proxy, for example: http://127.0.0.1:1080')
+    parser.add_option('--file',  '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
+
+    # generate options
     parser.add_option('--html', dest='html_viewer', action='store_true',
                       help='generate a html viewer at current directory')
-
-    parser.add_option('--login', '-l', type='str', dest='login', action='store',
-                      help='username:password pair of nhentai account')
-
     parser.add_option('--nohtml', dest='is_nohtml', action='store_true',
-                      help='Don\'t generate HTML')
-
+                      help='don\'t generate HTML')
     parser.add_option('--cbz', dest='is_cbz', action='store_true',
-                      help='Generate Comic Book CBZ File')
+                      help='generate Comic Book CBZ File')
     parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
-                      help='Remove downloaded doujinshi dir when generated CBZ file.')
-    parser.add_option('--file',  '-f', type='string', dest='file', action='store', help='Read gallery IDs from file.')
+                      help='remove downloaded doujinshi dir when generated CBZ file.')
+
+    # nhentai options
+    parser.add_option('--cookie', type='str', dest='cookie', action='store',
+                      help='set cookie of nhentai to bypass Google recaptcha')
 
     try:
         sys.argv = list(map(lambda x: unicode(x.decode(sys.stdin.encoding)), sys.argv))
@@ -86,6 +97,25 @@ def cmd_parser():
         generate_html()
         exit(0)
 
+    if os.path.exists(os.path.join(constant.NHENTAI_HOME, 'cookie')):
+        with open(os.path.join(constant.NHENTAI_HOME, 'cookie'), 'r') as f:
+            constant.COOKIE = f.read()
+
+    if args.cookie:
+        try:
+            if not os.path.exists(constant.NHENTAI_HOME):
+                os.mkdir(constant.NHENTAI_HOME)
+
+            with open(os.path.join(constant.NHENTAI_HOME, 'cookie'), 'w') as f:
+                f.write(args.cookie)
+        except Exception as e:
+            logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
+            exit(1)
+
+        logger.info('Cookie saved.')
+        exit(0)
+
+    '''
     if args.login:
         try:
             _, _ = args.login.split(':', 1)
@@ -95,6 +125,12 @@ def cmd_parser():
 
         if not args.is_download:
             logger.warning('YOU DO NOT SPECIFY `--download` OPTION !!!')
+    '''
+
+    if args.favorites:
+        if not constant.COOKIE:
+            logger.warning('Cookie has not been set, please use `nhentai --cookie \'COOKIE\'` to set it.')
+            exit(1)
 
     if args.id:
         _ = map(lambda id_: id_.strip(), args.id.split(','))
@@ -106,12 +142,12 @@ def cmd_parser():
             args.id = set(map(int, filter(lambda id_: id_.isdigit(), _)))
 
     if (args.is_download or args.is_show) and not args.id and not args.keyword and \
-            not args.login and not args.tag:
+            not args.tag and not args.favorites:
         logger.critical('Doujinshi id(s) are required for downloading')
         parser.print_help()
         exit(1)
 
-    if not args.keyword and not args.id and not args.login and not args.tag:
+    if not args.keyword and not args.id and not args.tag and not args.favorites:
         parser.print_help()
         exit(1)
 
diff --git a/nhentai/command.py b/nhentai/command.py
index a325f64..dc3ea99 100644
--- a/nhentai/command.py
+++ b/nhentai/command.py
@@ -5,7 +5,7 @@ import signal
 import platform
 
 from nhentai.cmdline import cmd_parser, banner
-from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, login_parser, tag_parser, login
+from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser, tag_parser, login
 from nhentai.doujinshi import Doujinshi
 from nhentai.downloader import Downloader
 from nhentai.logger import logger
@@ -21,13 +21,15 @@ def main():
     doujinshi_ids = []
     doujinshi_list = []
 
-    if options.login:
+    if options.favorites:
+        '''
         username, password = options.login.split(':', 1)
         logger.info('Logging in to nhentai using credential pair \'%s:%s\'' % (username, '*' * len(password)))
         login(username, password)
+        '''
 
         if options.is_download or options.is_show:
-            for doujinshi_info in login_parser():
+            for doujinshi_info in favorites_parser():
                 doujinshi_list.append(Doujinshi(**doujinshi_info))
 
             if options.is_show and not options.is_download:
@@ -37,7 +39,7 @@ def main():
     if options.tag:
         doujinshis = tag_parser(options.tag, max_page=options.max_page)
         print_doujinshi(doujinshis)
-        if options.is_download:
+        if options.is_download and doujinshis:
             doujinshi_ids = map(lambda d: d['id'], doujinshis)
 
     if options.keyword:
diff --git a/nhentai/constant.py b/nhentai/constant.py
index 6eb3dee..11c0d02 100644
--- a/nhentai/constant.py
+++ b/nhentai/constant.py
@@ -1,6 +1,7 @@
 # coding: utf-8
 from __future__ import unicode_literals, print_function
 import os
+import tempfile
 from nhentai.utils import urlparse
 
 BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net')
@@ -20,4 +21,8 @@ FAV_URL = '%s/favorites/' % BASE_URL
 u = urlparse(BASE_URL)
 IMAGE_URL = '%s://i.%s/galleries' % (u.scheme, u.hostname)
 
+NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
+
 PROXY = {}
+
+COOKIE = ''
diff --git a/nhentai/parser.py b/nhentai/parser.py
index 9feb89c..03f9426 100644
--- a/nhentai/parser.py
+++ b/nhentai/parser.py
@@ -25,6 +25,7 @@ def request(method, url, **kwargs):
     if not hasattr(session, method):
         raise AttributeError('\'requests.Session\' object has no attribute \'{0}\''.format(method))
 
+    session.headers.update({'Cookie': constant.COOKIE})
     return getattr(session, method)(url, proxies=constant.PROXY, verify=False, **kwargs)
 
 
@@ -37,6 +38,7 @@ def _get_csrf_token(content):
 
 
 def login(username, password):
+    logger.warning('This feature is deprecated, please use --cookie to set your cookie.')
     csrf_token = _get_csrf_token(request('get', url=constant.LOGIN_URL).text)
     if os.getenv('DEBUG'):
         logger.info('Getting CSRF token ...')
@@ -51,7 +53,7 @@ def login(username, password):
     }
     resp = request('post', url=constant.LOGIN_URL, data=login_dict)
 
-    if 'You\'re loading pages way too quickly.' in resp.text:
+    if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
         csrf_token = _get_csrf_token(resp.text)
         resp = request('post', url=resp.url, data={'csrfmiddlewaretoken': csrf_token, 'next': '/'})
 
@@ -59,13 +61,12 @@ def login(username, password):
         logger.error('Login failed, please check your username and password')
         exit(1)
 
-    if 'You\'re loading pages way too quickly.' in resp.text:
-        logger.error('You meet challenge insistently, please submit a issue'
-                     ' at https://github.com/RicterZ/nhentai/issues')
+    if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
+        logger.error('Using nhentai --cookie \'YOUR_COOKIE_HERE\' to save your Cookie.')
         exit(2)
 
 
-def login_parser():
+def favorites_parser():
     html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser')
     count = html.find('span', attrs={'class': 'count'})
     if not count:
@@ -91,20 +92,15 @@ def login_parser():
     ret = []
     doujinshi_id = re.compile('data-id="([\d]+)"')
 
-    def _callback(request, result):
-        ret.append(result)
-
-    # TODO: reduce threads number ...
-    thread_pool = threadpool.ThreadPool(1)
-
     for page in range(1, pages + 1):
         try:
             logger.info('Getting doujinshi ids of page %d' % page)
             resp = request('get', constant.FAV_URL + '?page=%d' % page).text
             ids = doujinshi_id.findall(resp)
-            requests_ = threadpool.makeRequests(doujinshi_parser, ids, _callback)
-            [thread_pool.putRequest(req) for req in requests_]
-            thread_pool.wait()
+
+            for i in ids:
+                ret.append(doujinshi_parser(i))
+
         except Exception as e:
             logger.error('Error: %s, continue', str(e))
 

From 263dba51f3fd82307bfd5a1c2c8162d13583dc3b Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 19:40:09 +0800
Subject: [PATCH 02/25] modify tests #54

---
 .travis.yml        |  6 +++---
 nhentai/command.py | 19 +++++++------------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index e8a0921..b0b5eef 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,9 +13,9 @@ install:
 
 script:
     - echo 268642 > /tmp/test.txt
+    - NHENTAI=https://nhentai.net nhentai --cookie '__cfduid=da09f237ceb0f51c75980b0b3fda3ce571558179357; _ga=GA1.2.2000087053.1558179358; _gid=GA1.2.717818542.1558179358; csrftoken=iSxrTFOjrujJqauhAqWvTTI9dl3sfWnxdEFoMuqgmlBrbMin5Gj9wJW4r61cmH1X; sessionid=ewuaayfewbzpiukrarx9d52oxwlz2esd'
     - NHENTAI=https://nhentai.net nhentai --search umaru
-    - NHENTAI=https://nhentai.net nhentai --id=152503,146134 -t 10 --output=/tmp/
-    - NHENTAI=https://nhentai.net nhentai -l nhentai_test:nhentai --download --output=/tmp/
+    - NHENTAI=https://nhentai.net nhentai --id=152503,146134 -t 10 --output=/tmp/ --cbz
     - NHENTAI=https://nhentai.net nhentai --tag lolicon
-    - NHENTAI=https://nhentai.net nhentai --id 92066 --output=/tmp/ --cbz
+    - NHENTAI=https://nhentai.net nhentai -F
     - NHENTAI=https://nhentai.net nhentai --file /tmp/test.txt
diff --git a/nhentai/command.py b/nhentai/command.py
index dc3ea99..55074cf 100644
--- a/nhentai/command.py
+++ b/nhentai/command.py
@@ -22,19 +22,15 @@ def main():
     doujinshi_list = []
 
     if options.favorites:
-        '''
-        username, password = options.login.split(':', 1)
-        logger.info('Logging in to nhentai using credential pair \'%s:%s\'' % (username, '*' * len(password)))
-        login(username, password)
-        '''
+        if not options.is_download:
+            logger.warning('You do not specify --download option')
 
-        if options.is_download or options.is_show:
-            for doujinshi_info in favorites_parser():
-                doujinshi_list.append(Doujinshi(**doujinshi_info))
+        for doujinshi_info in favorites_parser():
+            doujinshi_list.append(Doujinshi(**doujinshi_info))
 
-            if options.is_show and not options.is_download:
-                print_doujinshi([{'id': i.id, 'title': i.name} for i in doujinshi_list])
-                exit(0)
+        if not options.is_download:
+            print_doujinshi([{'id': i.id, 'title': i.name} for i in doujinshi_list])
+            exit(0)
 
     if options.tag:
         doujinshis = tag_parser(options.tag, max_page=options.max_page)
@@ -44,7 +40,6 @@ def main():
 
     if options.keyword:
         doujinshis = search_parser(options.keyword, options.page)
-        print(doujinshis)
         print_doujinshi(doujinshis)
         if options.is_download:
             doujinshi_ids = map(lambda d: d['id'], doujinshis)

From 475e4db9af1ee283e23ac9a8fadc61e16f564d5c Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 19:47:04 +0800
Subject: [PATCH 03/25] 0.3.2 #54

---
 nhentai/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nhentai/__init__.py b/nhentai/__init__.py
index b6f0dc4..074c9e1 100644
--- a/nhentai/__init__.py
+++ b/nhentai/__init__.py
@@ -1,3 +1,3 @@
-__version__ = '0.3.1'
+__version__ = '0.3.2'
 __author__ = 'RicterZ'
 __email__ = 'ricterzheng@gmail.com'

From f3141d572654aa85cc0861ef351f5a87602606fe Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 20:04:16 +0800
Subject: [PATCH 04/25] add rst

---
 README.rst | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 README.rst

diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..fbba1f3
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,87 @@
+nhentai
+=======
+
+.. code-block::
+           _   _            _        _
+     _ __ | | | | ___ _ __ | |_ __ _(_)
+    | '_ \| |_| |/ _ \ '_ \| __/ _` | |
+    | | | |  _  |  __/ | | | || (_| | |
+    |_| |_|_| |_|\___|_| |_|\__\__,_|_|
+
+
+あなたも変態。 いいね?  
+[![Build Status](https://travis-ci.org/RicterZ/nhentai.svg?branch=master)](https://travis-ci.org/RicterZ/nhentai) ![nhentai PyPI Downloads](https://img.shields.io/pypi/dm/nhentai.svg) [![license](https://img.shields.io/cocoapods/l/AFNetworking.svg)](https://github.com/RicterZ/nhentai/blob/master/LICENSE)
+
+
+nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhentai.net).
+
+### Installation
+
+    git clone https://github.com/RicterZ/nhentai
+    cd nhentai
+    python setup.py install
+    
+### Installation (Gentoo)
+
+    layman -fa glicOne
+    sudo emerge net-misc/nhentai
+
+### Usage
+**IMPORTANT**: To bypass the nhentai frequency limit, you should use `--login` option to log into nhentai.net.
+
+*The default download folder will be the path where you run the command (CLI path).*
+
+Download specified doujinshi:
+
+.. code-block:: bash
+    nhentai --id=123855,123866
+
+Download doujinshi with ids specified in a file:
+
+.. code-block:: bash
+    nhentai --file=doujinshi.txt
+
+Search a keyword and download the first page:
+
+.. code-block:: bash
+    nhentai --search="tomori" --page=1 --download
+
+Download your favourite doujinshi (login required):
+
+.. code-block:: bash
+    nhentai --login "username:password" --download
+
+Download by tag name:
+
+.. code-block:: bash
+    nhentai --tag lolicon --download
+
+### Options
+
++ `-t, --thread`: Download threads, max: 10  
++ `--output`:Output dir of saving doujinshi  
++ `--tag`:Download by tag name  
++ `--timeout`: Timeout of downloading each image   
++ `--proxy`: Use proxy, example: http://127.0.0.1:8080/  
++ `--login`: username:password pair of your nhentai account  
++ `--nohtml`: Do not generate HTML  
++ `--cbz`: Generate Comic Book CBZ File  
+
+### nHentai Mirror
+If you want to use a mirror, you should set up a reverse proxy of `nhentai.net` and `i.nhentai.net`.
+For example:
+
+    i.h.loli.club -> i.nhentai.net
+    h.loli.club -> nhentai.net
+
+Set `NHENTAI` env var to your nhentai mirror.
+
+.. code-block:: bash
+    NHENTAI=http://h.loli.club nhentai --id 123456
+
+![](./images/search.png)  
+![](./images/download.png)  
+![](./images/viewer.png)  
+
+### あなたも変態
+![](./images/image.jpg)

From 8d5f12292c0dd1fac37f698af652a72a16c8dcd5 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 20:06:10 +0800
Subject: [PATCH 05/25] update rst

---
 README.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/README.rst b/README.rst
index fbba1f3..eec6aa9 100644
--- a/README.rst
+++ b/README.rst
@@ -17,12 +17,16 @@ nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhenta
 
 ### Installation
 
+.. code-block::
+
     git clone https://github.com/RicterZ/nhentai
     cd nhentai
     python setup.py install
     
 ### Installation (Gentoo)
 
+.. code-block::
+
     layman -fa glicOne
     sudo emerge net-misc/nhentai
 
@@ -34,26 +38,31 @@ nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhenta
 Download specified doujinshi:
 
 .. code-block:: bash
+
     nhentai --id=123855,123866
 
 Download doujinshi with ids specified in a file:
 
 .. code-block:: bash
+
     nhentai --file=doujinshi.txt
 
 Search a keyword and download the first page:
 
 .. code-block:: bash
+
     nhentai --search="tomori" --page=1 --download
 
 Download your favourite doujinshi (login required):
 
 .. code-block:: bash
+
     nhentai --login "username:password" --download
 
 Download by tag name:
 
 .. code-block:: bash
+
     nhentai --tag lolicon --download
 
 ### Options
@@ -77,6 +86,7 @@ For example:
 Set `NHENTAI` env var to your nhentai mirror.
 
 .. code-block:: bash
+
     NHENTAI=http://h.loli.club nhentai --id 123456
 
 ![](./images/search.png)  

From 53c23bb6dc4bb09e09682cd6e5cea91ef001679c Mon Sep 17 00:00:00 2001
From: Ricter Zheng <RicterZheng@gmail.com>
Date: Sat, 18 May 2019 20:07:45 +0800
Subject: [PATCH 06/25] Update README.rst

---
 README.rst | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/README.rst b/README.rst
index eec6aa9..72ed080 100644
--- a/README.rst
+++ b/README.rst
@@ -15,7 +15,9 @@ nhentai
 
 nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhentai.net).
 
-### Installation
+============
+Installation
+============
 
 .. code-block::
 
@@ -23,14 +25,18 @@ nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhenta
     cd nhentai
     python setup.py install
     
-### Installation (Gentoo)
+=====================
+Installation (Gentoo)
+=====================
 
 .. code-block::
 
     layman -fa glicOne
     sudo emerge net-misc/nhentai
 
-### Usage
+=====
+Usage
+=====
 **IMPORTANT**: To bypass the nhentai frequency limit, you should use `--login` option to log into nhentai.net.
 
 *The default download folder will be the path where you run the command (CLI path).*
@@ -65,7 +71,9 @@ Download by tag name:
 
     nhentai --tag lolicon --download
 
-### Options
+=======
+Options
+=======
 
 + `-t, --thread`: Download threads, max: 10  
 + `--output`:Output dir of saving doujinshi  
@@ -76,7 +84,10 @@ Download by tag name:
 + `--nohtml`: Do not generate HTML  
 + `--cbz`: Generate Comic Book CBZ File  
 
-### nHentai Mirror
+==============
+nHentai Mirror
+==============
+
 If you want to use a mirror, you should set up a reverse proxy of `nhentai.net` and `i.nhentai.net`.
 For example:
 

From 795f80752fd0feb6263d6fd457ecb382d19b48a4 Mon Sep 17 00:00:00 2001
From: Ricter Zheng <RicterZheng@gmail.com>
Date: Sat, 18 May 2019 20:22:55 +0800
Subject: [PATCH 07/25] Update README.rst

---
 README.rst | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/README.rst b/README.rst
index 72ed080..e32c8a7 100644
--- a/README.rst
+++ b/README.rst
@@ -2,6 +2,7 @@ nhentai
 =======
 
 .. code-block::
+
            _   _            _        _
      _ __ | | | | ___ _ __ | |_ __ _(_)
     | '_ \| |_| |/ _ \ '_ \| __/ _` | |
@@ -10,15 +11,16 @@ nhentai
 
 
 あなたも変態。 いいね?  
-[![Build Status](https://travis-ci.org/RicterZ/nhentai.svg?branch=master)](https://travis-ci.org/RicterZ/nhentai) ![nhentai PyPI Downloads](https://img.shields.io/pypi/dm/nhentai.svg) [![license](https://img.shields.io/cocoapods/l/AFNetworking.svg)](https://github.com/RicterZ/nhentai/blob/master/LICENSE)
-
+|travis|
+|pypi|
+|license|
+[![license](https://img.shields.io/cocoapods/l/AFNetworking.svg)](https://github.com/RicterZ/nhentai/blob/master/LICENSE)
 
 nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhentai.net).
 
 ============
 Installation
 ============
-
 .. code-block::
 
     git clone https://github.com/RicterZ/nhentai
@@ -28,7 +30,6 @@ Installation
 =====================
 Installation (Gentoo)
 =====================
-
 .. code-block::
 
     layman -fa glicOne
@@ -38,11 +39,15 @@ Installation (Gentoo)
 Usage
 =====
 **IMPORTANT**: To bypass the nhentai frequency limit, you should use `--login` option to log into nhentai.net.
-
 *The default download folder will be the path where you run the command (CLI path).*
 
 Download specified doujinshi:
 
+Set your nhentai cookie aginest captcha:
+.. code-block:: bash
+
+    nhentai --cookie 'YOUR COOKIE FROM nhentai.net'
+
 .. code-block:: bash
 
     nhentai --id=123855,123866
@@ -59,22 +64,21 @@ Search a keyword and download the first page:
 
     nhentai --search="tomori" --page=1 --download
 
-Download your favourite doujinshi (login required):
-
-.. code-block:: bash
-
-    nhentai --login "username:password" --download
-
 Download by tag name:
 
 .. code-block:: bash
 
     nhentai --tag lolicon --download
 
+Download your favorites:
+
+.. code-block:: bash
+
+    nhentai --favorites --download
+
 =======
 Options
 =======
-
 + `-t, --thread`: Download threads, max: 10  
 + `--output`:Output dir of saving doujinshi  
 + `--tag`:Download by tag name  
@@ -87,7 +91,6 @@ Options
 ==============
 nHentai Mirror
 ==============
-
 If you want to use a mirror, you should set up a reverse proxy of `nhentai.net` and `i.nhentai.net`.
 For example:
 
@@ -104,5 +107,17 @@ Set `NHENTAI` env var to your nhentai mirror.
 ![](./images/download.png)  
 ![](./images/viewer.png)  
 
-### あなたも変態
+===========
+あなたも変態
+===========
 ![](./images/image.jpg)
+
+
+.. |travis| image:: https://travis-ci.org/RicterZ/nhentai.svg?branch=master
+   :target: https://travis-ci.org/RicterZ/nhentai
+
+.. |pypi| image:: https://img.shields.io/pypi/dm/nhentai.svg
+   :target: https://pypi.org/project/nhentai/
+
+.. |license| image:: https://img.shields.io/github/license/ricterz/nhentai.svg
+   :target: https://github.com/RicterZ/nhentai/blob/master/LICENS

From ef274a672b6b1352c200b224782586a323013a38 Mon Sep 17 00:00:00 2001
From: Ricter Zheng <RicterZheng@gmail.com>
Date: Sat, 18 May 2019 20:23:19 +0800
Subject: [PATCH 08/25] Update README.rst

---
 README.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.rst b/README.rst
index e32c8a7..b03115b 100644
--- a/README.rst
+++ b/README.rst
@@ -14,7 +14,7 @@ nhentai
 |travis|
 |pypi|
 |license|
-[![license](https://img.shields.io/cocoapods/l/AFNetworking.svg)](https://github.com/RicterZ/nhentai/blob/master/LICENSE)
+
 
 nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhentai.net).
 

From 5d294212e69670fcfabab570145ada31f1101f31 Mon Sep 17 00:00:00 2001
From: Ricter Zheng <RicterZheng@gmail.com>
Date: Sat, 18 May 2019 20:24:15 +0800
Subject: [PATCH 09/25] Update README.rst

---
 README.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.rst b/README.rst
index b03115b..dc91ba6 100644
--- a/README.rst
+++ b/README.rst
@@ -16,7 +16,7 @@ nhentai
 |license|
 
 
-nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhentai.net).
+nHentai is a CLI tool for downloading doujinshi from <http://nhentai.net>
 
 ============
 Installation
@@ -120,4 +120,4 @@ Set `NHENTAI` env var to your nhentai mirror.
    :target: https://pypi.org/project/nhentai/
 
 .. |license| image:: https://img.shields.io/github/license/ricterz/nhentai.svg
-   :target: https://github.com/RicterZ/nhentai/blob/master/LICENS
+   :target: https://github.com/RicterZ/nhentai/blob/master/LICENSE

From 1f76a8a70e9536431160c7f59c2836c8b6ac4a80 Mon Sep 17 00:00:00 2001
From: Ricter Zheng <RicterZheng@gmail.com>
Date: Sat, 18 May 2019 20:24:49 +0800
Subject: [PATCH 10/25] Update README.rst

---
 README.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.rst b/README.rst
index dc91ba6..4fe4f1f 100644
--- a/README.rst
+++ b/README.rst
@@ -41,13 +41,15 @@ Usage
 **IMPORTANT**: To bypass the nhentai frequency limit, you should use `--login` option to log into nhentai.net.
 *The default download folder will be the path where you run the command (CLI path).*
 
-Download specified doujinshi:
 
 Set your nhentai cookie aginest captcha:
+
 .. code-block:: bash
 
     nhentai --cookie 'YOUR COOKIE FROM nhentai.net'
 
+Download specified doujinshi:
+
 .. code-block:: bash
 
     nhentai --id=123855,123866

From 086e4692755d2c594cc4387f081e1f234c132e30 Mon Sep 17 00:00:00 2001
From: Ricter Zheng <RicterZheng@gmail.com>
Date: Sat, 18 May 2019 20:27:08 +0800
Subject: [PATCH 11/25] Update README.rst

---
 README.rst | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/README.rst b/README.rst
index 4fe4f1f..80ed14c 100644
--- a/README.rst
+++ b/README.rst
@@ -96,6 +96,8 @@ nHentai Mirror
 If you want to use a mirror, you should set up a reverse proxy of `nhentai.net` and `i.nhentai.net`.
 For example:
 
+.. code-block:: 
+
     i.h.loli.club -> i.nhentai.net
     h.loli.club -> nhentai.net
 
@@ -105,14 +107,24 @@ Set `NHENTAI` env var to your nhentai mirror.
 
     NHENTAI=http://h.loli.club nhentai --id 123456
 
-![](./images/search.png)  
-![](./images/download.png)  
-![](./images/viewer.png)  
+
+.. image:: ./images/search.png?raw=true
+    :alt: nhentai
+    :align: center
+.. image:: ./images/download.png?raw=true
+    :alt: nhentai
+    :align: center
+.. image:: ./images/viewer.png?raw=true
+    :alt: nhentai
+    :align: center
 
 ===========
 あなたも変態
 ===========
-![](./images/image.jpg)
+.. image:: ./images/image.jpg?raw=true
+    :alt: nhentai
+    :align: center
+
 
 
 .. |travis| image:: https://travis-ci.org/RicterZ/nhentai.svg?branch=master

From 56dace81f1e444b673fa58b1beccab6f016cd695 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 20:31:18 +0800
Subject: [PATCH 12/25] remove readme.md

---
 README.md  | 84 ------------------------------------------------------
 README.rst |  4 +--
 setup.py   |  5 ++--
 3 files changed, 4 insertions(+), 89 deletions(-)
 delete mode 100644 README.md

diff --git a/README.md b/README.md
deleted file mode 100644
index ac8aefc..0000000
--- a/README.md
+++ /dev/null
@@ -1,84 +0,0 @@
-nhentai
-=======
-           _   _            _        _
-     _ __ | | | | ___ _ __ | |_ __ _(_)
-    | '_ \| |_| |/ _ \ '_ \| __/ _` | |
-    | | | |  _  |  __/ | | | || (_| | |
-    |_| |_|_| |_|\___|_| |_|\__\__,_|_|
-
-あなたも変態。 いいね?  
-[![Build Status](https://travis-ci.org/RicterZ/nhentai.svg?branch=master)](https://travis-ci.org/RicterZ/nhentai) ![nhentai PyPI Downloads](https://img.shields.io/pypi/dm/nhentai.svg) [![license](https://img.shields.io/cocoapods/l/AFNetworking.svg)](https://github.com/RicterZ/nhentai/blob/master/LICENSE)
-
-
-nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhentai.net).
-
-### Installation
-
-    git clone https://github.com/RicterZ/nhentai
-    cd nhentai
-    python setup.py install
-    
-### Installation (Gentoo)
-
-    layman -fa glicOne
-    sudo emerge net-misc/nhentai
-
-### Usage
-**IMPORTANT**: To bypass the nhentai frequency limit, you should use `--login` option to log into nhentai.net.
-
-*The default download folder will be the path where you run the command (CLI path).*
-
-Download specified doujinshi:
-```bash
-nhentai --id=123855,123866
-```
-
-Download doujinshi with ids specified in a file:
-```bash
-nhentai --file=doujinshi.txt
-```
-
-Search a keyword and download the first page:
-```bash
-nhentai --search="tomori" --page=1 --download
-```
-
-Download your favourite doujinshi (login required):
-```bash
-nhentai --login "username:password" --download
-```
-
-Download by tag name:
-```bash
-nhentai --tag lolicon --download
-```
-
-### Options
-
-+ `-t, --thread`: Download threads, max: 10  
-+ `--output`:Output dir of saving doujinshi  
-+ `--tag`:Download by tag name  
-+ `--timeout`: Timeout of downloading each image   
-+ `--proxy`: Use proxy, example: http://127.0.0.1:8080/  
-+ `--login`: username:password pair of your nhentai account  
-+ `--nohtml`: Do not generate HTML  
-+ `--cbz`: Generate Comic Book CBZ File  
-
-### nHentai Mirror
-If you want to use a mirror, you should set up a reverse proxy of `nhentai.net` and `i.nhentai.net`.
-For example:
-
-    i.h.loli.club -> i.nhentai.net
-    h.loli.club -> nhentai.net
-
-Set `NHENTAI` env var to your nhentai mirror.
-```bash
-NHENTAI=http://h.loli.club nhentai --id 123456
-```
-
-![](./images/search.png)  
-![](./images/download.png)  
-![](./images/viewer.png)  
-
-### あなたも変態
-![](./images/image.jpg)
diff --git a/README.rst b/README.rst
index 80ed14c..091a8d5 100644
--- a/README.rst
+++ b/README.rst
@@ -118,9 +118,9 @@ Set `NHENTAI` env var to your nhentai mirror.
     :alt: nhentai
     :align: center
 
-===========
+============
 あなたも変態
-===========
+============
 .. image:: ./images/image.jpg?raw=true
     :alt: nhentai
     :align: center
diff --git a/setup.py b/setup.py
index d0f6562..f480537 100644
--- a/setup.py
+++ b/setup.py
@@ -11,9 +11,8 @@ with open('requirements.txt') as f:
 
 
 def long_description():
-    with codecs.open('README.md', 'rb') as f:
-        if sys.version_info >= (3, 0, 0):
-            return str(f.read())
+    with codecs.open('README.rst', 'r') as f:
+        return str(f.read())
 
 setup(
     name='nhentai',

From 5df58780d9d338d619d052ec25c21934806d0a56 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 21:51:38 +0800
Subject: [PATCH 13/25] add delay #55

---
 README.rst            | 12 ++++++------
 nhentai/cmdline.py    |  8 ++++++--
 nhentai/command.py    | 18 ++++++++----------
 nhentai/downloader.py |  7 ++++++-
 nhentai/parser.py     |  4 +---
 5 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/README.rst b/README.rst
index 091a8d5..85fd0c5 100644
--- a/README.rst
+++ b/README.rst
@@ -38,11 +38,11 @@ Installation (Gentoo)
 =====
 Usage
 =====
-**IMPORTANT**: To bypass the nhentai frequency limit, you should use `--login` option to log into nhentai.net.
+**IMPORTANT**: To bypass the nhentai frequency limit, you should use `--cookie` option to store your cookie.
 *The default download folder will be the path where you run the command (CLI path).*
 
 
-Set your nhentai cookie aginest captcha:
+Set your nhentai cookie against captcha:
 
 .. code-block:: bash
 
@@ -54,7 +54,7 @@ Download specified doujinshi:
 
     nhentai --id=123855,123866
 
-Download doujinshi with ids specified in a file:
+Download doujinshi with ids specified in a file (doujinshi ids split by line):
 
 .. code-block:: bash
 
@@ -70,13 +70,13 @@ Download by tag name:
 
 .. code-block:: bash
 
-    nhentai --tag lolicon --download
+    nhentai --tag lolicon --download --page=2
 
-Download your favorites:
+Download your favorites with delay:
 
 .. code-block:: bash
 
-    nhentai --favorites --download
+    nhentai --favorites --download --delay 1
 
 =======
 Options
diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py
index 3e2c512..3696fb6 100644
--- a/nhentai/cmdline.py
+++ b/nhentai/cmdline.py
@@ -66,15 +66,19 @@ def cmd_parser():
                       help='thread count for downloading doujinshi')
     parser.add_option('--timeout', type='int', dest='timeout', action='store', default=30,
                       help='timeout for downloading doujinshi')
+    parser.add_option('--delay', type='int', dest='delay', action='store', default=0,
+                      help='slow down between downloading every doujinshi')
     parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
                       help='uses a proxy, for example: http://127.0.0.1:1080')
     parser.add_option('--file',  '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
+    parser.add_option('--format', '-F', type='string', dest='name_format', action='store',
+                      help='format the saved folder name', default='[%i][%n]')
 
     # generate options
     parser.add_option('--html', dest='html_viewer', action='store_true',
                       help='generate a html viewer at current directory')
-    parser.add_option('--nohtml', dest='is_nohtml', action='store_true',
-                      help='don\'t generate HTML')
+    parser.add_option('--no-html', dest='is_nohtml', action='store_true',
+                      help='don\'t generate HTML after downloading')
     parser.add_option('--cbz', dest='is_cbz', action='store_true',
                       help='generate Comic Book CBZ File')
     parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
diff --git a/nhentai/command.py b/nhentai/command.py
index 55074cf..8d43552 100644
--- a/nhentai/command.py
+++ b/nhentai/command.py
@@ -3,6 +3,7 @@
 from __future__ import unicode_literals, print_function
 import signal
 import platform
+import time
 
 from nhentai.cmdline import cmd_parser, banner
 from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser, tag_parser, login
@@ -25,36 +26,33 @@ def main():
         if not options.is_download:
             logger.warning('You do not specify --download option')
 
-        for doujinshi_info in favorites_parser():
-            doujinshi_list.append(Doujinshi(**doujinshi_info))
+        doujinshi_ids = favorites_parser()
 
-        if not options.is_download:
-            print_doujinshi([{'id': i.id, 'title': i.name} for i in doujinshi_list])
-            exit(0)
-
-    if options.tag:
+    elif options.tag:
         doujinshis = tag_parser(options.tag, max_page=options.max_page)
         print_doujinshi(doujinshis)
         if options.is_download and doujinshis:
             doujinshi_ids = map(lambda d: d['id'], doujinshis)
 
-    if options.keyword:
+    elif options.keyword:
         doujinshis = search_parser(options.keyword, options.page)
         print_doujinshi(doujinshis)
         if options.is_download:
             doujinshi_ids = map(lambda d: d['id'], doujinshis)
 
-    if not doujinshi_ids:
+    elif not doujinshi_ids:
         doujinshi_ids = options.id
 
     if doujinshi_ids:
         for id_ in doujinshi_ids:
+            if options.delay:
+                time.sleep(options.delay)
             doujinshi_info = doujinshi_parser(id_)
             doujinshi_list.append(Doujinshi(**doujinshi_info))
 
     if not options.is_show:
         downloader = Downloader(path=options.output_dir,
-                                thread=options.threads, timeout=options.timeout)
+                                thread=options.threads, timeout=options.timeout, delay=options.delay)
 
         for doujinshi in doujinshi_list:
             doujinshi.downloader = downloader
diff --git a/nhentai/downloader.py b/nhentai/downloader.py
index 8095c5f..81037f8 100644
--- a/nhentai/downloader.py
+++ b/nhentai/downloader.py
@@ -4,6 +4,8 @@ from future.builtins import str as text
 import os
 import requests
 import threadpool
+import time
+
 try:
     from urllib.parse import urlparse
 except ImportError:
@@ -23,7 +25,7 @@ class NhentaiImageNotExistException(Exception):
 
 class Downloader(Singleton):
 
-    def __init__(self, path='', thread=1, timeout=30):
+    def __init__(self, path='', thread=1, timeout=30, delay=0):
         if not isinstance(thread, (int, )) or thread < 1 or thread > 15:
             raise ValueError('Invalid threads count')
         self.path = str(path)
@@ -31,8 +33,11 @@ class Downloader(Singleton):
         self.threads = []
         self.thread_pool = None
         self.timeout = timeout
+        self.delay = delay
 
     def _download(self, url, folder='', filename='', retried=0):
+        if self.delay:
+            time.sleep(self.delay)
         logger.info('Starting to download {0} ...'.format(url))
         filename = filename if filename else os.path.basename(urlparse(url).path)
         base_filename, extension = os.path.splitext(filename)
diff --git a/nhentai/parser.py b/nhentai/parser.py
index 03f9426..34555e0 100644
--- a/nhentai/parser.py
+++ b/nhentai/parser.py
@@ -97,9 +97,7 @@ def favorites_parser():
             logger.info('Getting doujinshi ids of page %d' % page)
             resp = request('get', constant.FAV_URL + '?page=%d' % page).text
             ids = doujinshi_id.findall(resp)
-
-            for i in ids:
-                ret.append(doujinshi_parser(i))
+            ret.extend(ids)
 
         except Exception as e:
             logger.error('Error: %s, continue', str(e))

From a7848c3cd08a810f8ab7bba061cbcd09684f3c40 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 21:52:36 +0800
Subject: [PATCH 14/25] fix bug

---
 nhentai/cmdline.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py
index 3696fb6..278e44a 100644
--- a/nhentai/cmdline.py
+++ b/nhentai/cmdline.py
@@ -71,7 +71,7 @@ def cmd_parser():
     parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
                       help='uses a proxy, for example: http://127.0.0.1:1080')
     parser.add_option('--file',  '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
-    parser.add_option('--format', '-F', type='string', dest='name_format', action='store',
+    parser.add_option('--format', type='string', dest='name_format', action='store',
                       help='format the saved folder name', default='[%i][%n]')
 
     # generate options

From 40a98881c6efa5bc28bf49422db807d205500f37 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 21:53:40 +0800
Subject: [PATCH 15/25] add some shortcut options

---
 nhentai/cmdline.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py
index 278e44a..357c143 100644
--- a/nhentai/cmdline.py
+++ b/nhentai/cmdline.py
@@ -42,13 +42,13 @@ def cmd_parser():
                           '\n\nEnvironment Variable:\n'
                           '  NHENTAI                 nhentai mirror url')
     # operation options
-    parser.add_option('--download', dest='is_download', action='store_true',
+    parser.add_option('--download', '-D', dest='is_download', action='store_true',
                       help='download doujinshi (for search results)')
-    parser.add_option('--show', dest='is_show', action='store_true', help='just show the doujinshi information')
+    parser.add_option('--show', '-S', dest='is_show', action='store_true', help='just show the doujinshi information')
 
     # doujinshi options
     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('--search', '-s', type='string', dest='keyword', action='store', help='search doujinshi by keyword')
     parser.add_option('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag')
     parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
                       help='list or download your favorites.')
@@ -60,15 +60,15 @@ def cmd_parser():
                       help='The max page when recursive download tagged doujinshi')
 
     # download options
-    parser.add_option('--output', type='string', dest='output_dir', action='store', default='',
+    parser.add_option('--output', '-o', type='string', dest='output_dir', action='store', default='',
                       help='output dir')
     parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
                       help='thread count for downloading doujinshi')
-    parser.add_option('--timeout', type='int', dest='timeout', action='store', default=30,
+    parser.add_option('--timeout', '-T', type='int', dest='timeout', action='store', default=30,
                       help='timeout for downloading doujinshi')
-    parser.add_option('--delay', type='int', dest='delay', action='store', default=0,
+    parser.add_option('--delay', '-d', type='int', dest='delay', action='store', default=0,
                       help='slow down between downloading every doujinshi')
-    parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
+    parser.add_option('--proxy', '-p', type='string', dest='proxy', action='store', default='',
                       help='uses a proxy, for example: http://127.0.0.1:1080')
     parser.add_option('--file',  '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
     parser.add_option('--format', type='string', dest='name_format', action='store',
@@ -79,7 +79,7 @@ def cmd_parser():
                       help='generate a html viewer at current directory')
     parser.add_option('--no-html', dest='is_nohtml', action='store_true',
                       help='don\'t generate HTML after downloading')
-    parser.add_option('--cbz', dest='is_cbz', action='store_true',
+    parser.add_option('--cbz', '-C', dest='is_cbz', action='store_true',
                       help='generate Comic Book CBZ File')
     parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
                       help='remove downloaded doujinshi dir when generated CBZ file.')

From 1e1d03064b63e58e8005990e08a1d3d96c66ced0 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 21:56:35 +0800
Subject: [PATCH 16/25] readme

---
 README.rst | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/README.rst b/README.rst
index 85fd0c5..21f0f80 100644
--- a/README.rst
+++ b/README.rst
@@ -78,6 +78,50 @@ Download your favorites with delay:
 
     nhentai --favorites --download --delay 1
 
+
+.. code-block::
+
+    Options:
+      # Operation options
+      -h, --help            show this help message and exit
+      -D, --download        download doujinshi (for search results)
+      -S, --show            just show the doujinshi information
+
+      # Doujinshi options
+      --id=ID               doujinshi ids set, e.g. 1,2,3
+      -s KEYWORD, --search=KEYWORD
+                            search doujinshi by keyword
+      --tag=TAG             download doujinshi by tag
+      -F, --favorites       list or download your favorites.
+
+      # Multi-page options
+      --page=PAGE           page number of search results
+      --max-page=MAX_PAGE   The max page when recursive download tagged doujinshi
+
+      # Download options
+      -o OUTPUT_DIR, --output=OUTPUT_DIR
+                            output dir
+      -t THREADS, --threads=THREADS
+                            thread count for downloading doujinshi
+      -T TIMEOUT, --timeout=TIMEOUT
+                            timeout for downloading doujinshi
+      -d DELAY, --delay=DELAY
+                            slow down between downloading every doujinshi
+      -p PROXY, --proxy=PROXY
+                            uses a proxy, for example: http://127.0.0.1:1080
+      -f FILE, --file=FILE  read gallery IDs from file.
+      --format=NAME_FORMAT  format the saved folder name
+
+      # Generating options
+      --html                generate a html viewer at current directory
+      --no-html             don't generate HTML after downloading
+      -C, --cbz             generate Comic Book CBZ File
+      --rm-origin-dir       remove downloaded doujinshi dir when generated CBZ
+                            file.
+
+      # nHentai options
+      --cookie=COOKIE       set cookie of nhentai to bypass Google recaptcha
+
 =======
 Options
 =======

From 57dc4a58b952a69b4937237ad824ca5881760060 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 21:56:59 +0800
Subject: [PATCH 17/25] remove Options block

---
 README.rst | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/README.rst b/README.rst
index 21f0f80..a75ddc0 100644
--- a/README.rst
+++ b/README.rst
@@ -122,17 +122,6 @@ Download your favorites with delay:
       # nHentai options
       --cookie=COOKIE       set cookie of nhentai to bypass Google recaptcha
 
-=======
-Options
-=======
-+ `-t, --thread`: Download threads, max: 10  
-+ `--output`:Output dir of saving doujinshi  
-+ `--tag`:Download by tag name  
-+ `--timeout`: Timeout of downloading each image   
-+ `--proxy`: Use proxy, example: http://127.0.0.1:8080/  
-+ `--login`: username:password pair of your nhentai account  
-+ `--nohtml`: Do not generate HTML  
-+ `--cbz`: Generate Comic Book CBZ File  
 
 ==============
 nHentai Mirror

From b5deca27040dc0665e2488269f8b1d9da0b5d10a Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 21:57:43 +0800
Subject: [PATCH 18/25] fix

---
 README.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.rst b/README.rst
index a75ddc0..73616a8 100644
--- a/README.rst
+++ b/README.rst
@@ -79,6 +79,7 @@ Download your favorites with delay:
     nhentai --favorites --download --delay 1
 
 
+Other options:
 .. code-block::
 
     Options:

From 450e3689a074732e20fb336cb32d5711c99450c5 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 22:00:33 +0800
Subject: [PATCH 19/25] fix

---
 README.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.rst b/README.rst
index 73616a8..b434cfd 100644
--- a/README.rst
+++ b/README.rst
@@ -80,6 +80,7 @@ Download your favorites with delay:
 
 
 Other options:
+
 .. code-block::
 
     Options:

From cf4291d3c2873c23569f827bd5cd8bc4ae6d262a Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 22:01:29 +0800
Subject: [PATCH 20/25] new line

---
 README.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/README.rst b/README.rst
index b434cfd..6eb59b9 100644
--- a/README.rst
+++ b/README.rst
@@ -10,7 +10,8 @@ nhentai
     |_| |_|_| |_|\___|_| |_|\__\__,_|_|
 
 
-あなたも変態。 いいね?  
+あなたも変態。 いいね?
+
 |travis|
 |pypi|
 |license|

From 2c61fd3a3fbe4c073f2777ea22e412ee72475211 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 22:13:23 +0800
Subject: [PATCH 21/25] add doujinshi folder formatter

---
 README.rst           | 13 +++++++++++++
 nhentai/cmdline.py   |  2 +-
 nhentai/command.py   |  2 +-
 nhentai/doujinshi.py | 11 ++++++++---
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/README.rst b/README.rst
index 6eb59b9..0bed282 100644
--- a/README.rst
+++ b/README.rst
@@ -79,6 +79,19 @@ Download your favorites with delay:
 
     nhentai --favorites --download --delay 1
 
+Format output doujinshi folder name:
+
+.. code-block:: bash
+    nhentai --id 261100 --format '[%i]%s'
+
+
+Supported doujinshi folder formatter:
+
+- %i: Doujinshi id
+- %t: Doujinshi name
+- %s: Doujinshi subtitle (translated name)
+- %a: Doujinshi authors' name
+
 
 Other options:
 
diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py
index 357c143..579c514 100644
--- a/nhentai/cmdline.py
+++ b/nhentai/cmdline.py
@@ -72,7 +72,7 @@ def cmd_parser():
                       help='uses a proxy, for example: http://127.0.0.1:1080')
     parser.add_option('--file',  '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
     parser.add_option('--format', type='string', dest='name_format', action='store',
-                      help='format the saved folder name', default='[%i][%n]')
+                      help='format the saved folder name', default='[%i][%a][%t]')
 
     # generate options
     parser.add_option('--html', dest='html_viewer', action='store_true',
diff --git a/nhentai/command.py b/nhentai/command.py
index 8d43552..e20c2b8 100644
--- a/nhentai/command.py
+++ b/nhentai/command.py
@@ -48,7 +48,7 @@ def main():
             if options.delay:
                 time.sleep(options.delay)
             doujinshi_info = doujinshi_parser(id_)
-            doujinshi_list.append(Doujinshi(**doujinshi_info))
+            doujinshi_list.append(Doujinshi(name_format=options.name_format, **doujinshi_info))
 
     if not options.is_show:
         downloader = Downloader(path=options.output_dir,
diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py
index 88e0925..0ee0598 100644
--- a/nhentai/doujinshi.py
+++ b/nhentai/doujinshi.py
@@ -27,7 +27,7 @@ class DoujinshiInfo(dict):
 
 
 class Doujinshi(object):
-    def __init__(self, name=None, id=None, img_id=None, ext='', pages=0, **kwargs):
+    def __init__(self, name=None, id=None, img_id=None, ext='', pages=0, name_format='[%i][%a][%t]', **kwargs):
         self.name = name
         self.id = id
         self.img_id = img_id
@@ -36,7 +36,12 @@ class Doujinshi(object):
         self.downloader = None
         self.url = '%s/%d' % (DETAIL_URL, self.id)
         self.info = DoujinshiInfo(**kwargs)
-        self.filename = format_filename('[%s][%s][%s]' % (self.id, self.info.artist, self.name))
+
+        name_format = name_format.replace('%i', str(self.id))
+        name_format = name_format.replace('%a', self.info.artists)
+        name_format = name_format.replace('%t', self.name)
+        name_format = name_format.replace('%s', self.info.subtitle)
+        self.filename = name_format
 
     def __repr__(self):
         return '<Doujinshi: {0}>'.format(self.name)
@@ -46,7 +51,7 @@ class Doujinshi(object):
             ["Doujinshi", self.name],
             ["Subtitle", self.info.subtitle],
             ["Characters", self.info.character],
-            ["Authors", self.info.artist],
+            ["Authors", self.info.artists],
             ["Language", self.info.language],
             ["Tags", self.info.tags],
             ["URL", self.url],

From 6bd37f384ce2011a2596b2aebae9ad1512ebbace Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 22:14:08 +0800
Subject: [PATCH 22/25] fix

---
 README.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.rst b/README.rst
index 0bed282..34d4ea4 100644
--- a/README.rst
+++ b/README.rst
@@ -82,8 +82,8 @@ Download your favorites with delay:
 Format output doujinshi folder name:
 
 .. code-block:: bash
-    nhentai --id 261100 --format '[%i]%s'
 
+    nhentai --id 261100 --format '[%i]%s'
 
 Supported doujinshi folder formatter:
 

From 57e930584929da98bf43f827883863b2681ac01d Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 22:15:42 +0800
Subject: [PATCH 23/25] 0.3.3

---
 nhentai/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nhentai/__init__.py b/nhentai/__init__.py
index 074c9e1..9ad6b6e 100644
--- a/nhentai/__init__.py
+++ b/nhentai/__init__.py
@@ -1,3 +1,3 @@
-__version__ = '0.3.2'
+__version__ = '0.3.3'
 __author__ = 'RicterZ'
 __email__ = 'ricterzheng@gmail.com'

From 01c0e738498bed496f4b31a127bbbec75cf6b4f0 Mon Sep 17 00:00:00 2001
From: RicterZ <ricterzheng@gmail.com>
Date: Sat, 18 May 2019 22:30:20 +0800
Subject: [PATCH 24/25] fix bug while installing on windows / python3

---
 nhentai/__init__.py | 2 +-
 setup.py            | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/nhentai/__init__.py b/nhentai/__init__.py
index 9ad6b6e..42ea186 100644
--- a/nhentai/__init__.py
+++ b/nhentai/__init__.py
@@ -1,3 +1,3 @@
-__version__ = '0.3.3'
+__version__ = '0.3.4'
 __author__ = 'RicterZ'
 __email__ = 'ricterzheng@gmail.com'
diff --git a/setup.py b/setup.py
index f480537..7b87d5c 100644
--- a/setup.py
+++ b/setup.py
@@ -11,8 +11,10 @@ with open('requirements.txt') as f:
 
 
 def long_description():
-    with codecs.open('README.rst', 'r') as f:
-        return str(f.read())
+    with codecs.open('README.rst', 'rb') as readme:
+        if not sys.version_info < (3, 0, 0):
+            return readme.read().decode('utf-8')
+
 
 setup(
     name='nhentai',

From a95396033bebdbd5c44331396490808047a04ae2 Mon Sep 17 00:00:00 2001
From: Ricter Zheng <RicterZheng@gmail.com>
Date: Sat, 18 May 2019 22:36:03 +0800
Subject: [PATCH 25/25] Update README.rst

---
 README.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.rst b/README.rst
index 34d4ea4..28b37ef 100644
--- a/README.rst
+++ b/README.rst
@@ -40,6 +40,7 @@ Installation (Gentoo)
 Usage
 =====
 **IMPORTANT**: To bypass the nhentai frequency limit, you should use `--cookie` option to store your cookie.
+
 *The default download folder will be the path where you run the command (CLI path).*