mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-30 00:00:48 +02:00
feature of download dojinshi
This commit is contained in:
parent
d62d43d204
commit
cb0972c2eb
@ -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)
|
||||
|
||||
|
17
nhentai.py
17
nhentai.py
@ -12,23 +12,26 @@ __version__ = '0.1'
|
||||
def main():
|
||||
banner()
|
||||
options = cmd_parser()
|
||||
dojinshi = None
|
||||
|
||||
logger.log(15, 'nHentai: あなたも変態。 いいね?')
|
||||
if options.id:
|
||||
dojinshi_info = dojinshi_parser(options.id)
|
||||
dojinshi = Dojinshi(**dojinshi_info)
|
||||
|
||||
dojinshi_list = []
|
||||
if options.ids:
|
||||
for id in options.ids:
|
||||
dojinshi_info = dojinshi_parser(id)
|
||||
dojinshi_list.append(Dojinshi(**dojinshi_info))
|
||||
elif options.keyword:
|
||||
pass
|
||||
else:
|
||||
raise SystemExit
|
||||
|
||||
if options.is_download:
|
||||
dojinshi.downloader = Downloader(path=options.saved_path,
|
||||
thread=options.threads)
|
||||
downloader = Downloader(path=options.saved_path, thread=options.threads)
|
||||
for dojinshi in dojinshi_list:
|
||||
dojinshi.downloader = downloader
|
||||
dojinshi.download()
|
||||
else:
|
||||
dojinshi.show()
|
||||
map(lambda dojinshi: dojinshi.show(), dojinshi_list)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user