mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-07-02 08:29:27 +02:00
feature of download dojinshi
This commit is contained in:
@ -44,4 +44,6 @@ def cmd_parser():
|
||||
logger.critical(u'并没有做这个功能_(:3」∠)_')
|
||||
sys.exit()
|
||||
|
||||
args.ids = (args.id, ) if not args.ids else args.ids
|
||||
|
||||
return args
|
||||
|
@ -32,7 +32,7 @@ class Dojinshi(object):
|
||||
download_queue.put('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext))
|
||||
self.downloader.download(download_queue, self.id)
|
||||
else:
|
||||
raise Exception('Downloader has not be loaded')
|
||||
logger.critical('Downloader has not be loaded')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -7,9 +7,15 @@ import requests
|
||||
from urlparse import urlparse
|
||||
from hentai.logger import logger
|
||||
|
||||
shutdown = threading.Event()
|
||||
|
||||
class Downloader(object):
|
||||
_instance = None
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if not cls._instance:
|
||||
cls._instance = super(Downloader, cls).__new__(cls, *args, **kwargs)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self, path='', thread=1):
|
||||
if not isinstance(thread, (int, )) or thread < 1 or thread > 10:
|
||||
raise ValueError('Invalid threads count')
|
||||
@ -18,9 +24,6 @@ class Downloader(object):
|
||||
self.threads = []
|
||||
|
||||
def _download(self, url, folder='', filename=''):
|
||||
if shutdown.is_set():
|
||||
return
|
||||
|
||||
if not os.path.exists(folder):
|
||||
try:
|
||||
os.mkdir(folder)
|
||||
@ -83,4 +86,3 @@ class Downloader(object):
|
||||
thread.join()
|
||||
|
||||
logger.log(15, u'🍺 All done, saved to \'%s\'!' % folder)
|
||||
|
||||
|
Reference in New Issue
Block a user