mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
add delay #55
This commit is contained in:
parent
56dace81f1
commit
5df58780d9
12
README.rst
12
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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user