mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-30 08:10:46 +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」∠)_')
|
logger.critical(u'并没有做这个功能_(:3」∠)_')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
args.ids = (args.id, ) if not args.ids else args.ids
|
||||||
|
|
||||||
return args
|
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))
|
download_queue.put('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext))
|
||||||
self.downloader.download(download_queue, self.id)
|
self.downloader.download(download_queue, self.id)
|
||||||
else:
|
else:
|
||||||
raise Exception('Downloader has not be loaded')
|
logger.critical('Downloader has not be loaded')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -7,9 +7,15 @@ import requests
|
|||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from hentai.logger import logger
|
from hentai.logger import logger
|
||||||
|
|
||||||
shutdown = threading.Event()
|
|
||||||
|
|
||||||
class Downloader(object):
|
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):
|
def __init__(self, path='', thread=1):
|
||||||
if not isinstance(thread, (int, )) or thread < 1 or thread > 10:
|
if not isinstance(thread, (int, )) or thread < 1 or thread > 10:
|
||||||
raise ValueError('Invalid threads count')
|
raise ValueError('Invalid threads count')
|
||||||
@ -18,9 +24,6 @@ class Downloader(object):
|
|||||||
self.threads = []
|
self.threads = []
|
||||||
|
|
||||||
def _download(self, url, folder='', filename=''):
|
def _download(self, url, folder='', filename=''):
|
||||||
if shutdown.is_set():
|
|
||||||
return
|
|
||||||
|
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
try:
|
try:
|
||||||
os.mkdir(folder)
|
os.mkdir(folder)
|
||||||
@ -83,4 +86,3 @@ class Downloader(object):
|
|||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
logger.log(15, u'🍺 All done, saved to \'%s\'!' % folder)
|
logger.log(15, u'🍺 All done, saved to \'%s\'!' % folder)
|
||||||
|
|
||||||
|
19
nhentai.py
19
nhentai.py
@ -12,23 +12,26 @@ __version__ = '0.1'
|
|||||||
def main():
|
def main():
|
||||||
banner()
|
banner()
|
||||||
options = cmd_parser()
|
options = cmd_parser()
|
||||||
dojinshi = None
|
|
||||||
|
|
||||||
logger.log(15, 'nHentai: あなたも変態。 いいね?')
|
logger.log(15, 'nHentai: あなたも変態。 いいね?')
|
||||||
if options.id:
|
|
||||||
dojinshi_info = dojinshi_parser(options.id)
|
dojinshi_list = []
|
||||||
dojinshi = Dojinshi(**dojinshi_info)
|
if options.ids:
|
||||||
|
for id in options.ids:
|
||||||
|
dojinshi_info = dojinshi_parser(id)
|
||||||
|
dojinshi_list.append(Dojinshi(**dojinshi_info))
|
||||||
elif options.keyword:
|
elif options.keyword:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
if options.is_download:
|
if options.is_download:
|
||||||
dojinshi.downloader = Downloader(path=options.saved_path,
|
downloader = Downloader(path=options.saved_path, thread=options.threads)
|
||||||
thread=options.threads)
|
for dojinshi in dojinshi_list:
|
||||||
dojinshi.download()
|
dojinshi.downloader = downloader
|
||||||
|
dojinshi.download()
|
||||||
else:
|
else:
|
||||||
dojinshi.show()
|
map(lambda dojinshi: dojinshi.show(), dojinshi_list)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user