feature of download dojinshi

This commit is contained in:
ricterz
2015-04-21 23:24:22 +08:00
parent d62d43d204
commit cb0972c2eb
4 changed files with 21 additions and 14 deletions

View File

@ -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

View File

@ -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__':

View File

@ -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)