忘记干啥了..

This commit is contained in:
Ricter Z 2016-10-17 21:26:58 +08:00
parent 3eacd118ed
commit 0d185f465d
5 changed files with 29 additions and 15 deletions

View File

@ -23,10 +23,12 @@ def banner():
def cmd_parser(): def cmd_parser():
parser = OptionParser() parser = OptionParser()
parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not') parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not')
parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information.')
parser.add_option('--id', type='str', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3') parser.add_option('--id', type='str', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3')
parser.add_option('--search', type='string', dest='keyword', action='store', help='keyword searched') parser.add_option('--search', type='string', dest='keyword', action='store', help='search doujinshi by keyword')
parser.add_option('--page', type='int', dest='page', action='store', default=1, parser.add_option('--page', type='int', dest='page', action='store', default=1,
help='page number of search result') help='page number of search result')
parser.add_option('--tags', type='string', dest='tags', action='store', help='download doujinshi by tags')
parser.add_option('--output', type='string', dest='output_dir', action='store', default='', parser.add_option('--output', type='string', dest='output_dir', action='store', default='',
help='output dir') help='output dir')
parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5, parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
@ -37,11 +39,15 @@ def cmd_parser():
help='use proxy, example: http://127.0.0.1:1080') help='use proxy, example: http://127.0.0.1:1080')
args, _ = parser.parse_args() args, _ = parser.parse_args()
if args.tags:
logger.warning('`--tags` is under construction')
exit(0)
if args.id: if args.id:
_ = map(lambda id: id.strip(), args.id.split(',')) _ = map(lambda id: id.strip(), args.id.split(','))
args.id = set(map(int, filter(lambda id: id.isdigit(), _))) args.id = set(map(int, filter(lambda id: id.isdigit(), _)))
if args.is_download and not args.id and not args.keyword: if (args.is_download or args.is_show) and not args.id and not args.keyword:
logger.critical('Doujinshi id(s) are required for downloading') logger.critical('Doujinshi id(s) are required for downloading')
parser.print_help() parser.print_help()
exit(0) exit(0)

View File

@ -31,14 +31,19 @@ def main():
else: else:
exit(0) exit(0)
if not options.is_show:
downloader = Downloader(path=options.output_dir, downloader = Downloader(path=options.output_dir,
thread=options.threads, timeout=options.timeout) thread=options.threads, timeout=options.timeout)
for doujinshi in doujinshi_list: for doujinshi in doujinshi_list:
doujinshi.downloader = downloader doujinshi.downloader = downloader
doujinshi.download() doujinshi.download()
logger.log(15, u'🍺 All done.') logger.log(15, u'🍺 All done.')
else:
[doujinshi.show() for doujinshi in doujinshi_list]
def signal_handler(signal, frame): def signal_handler(signal, frame):
logger.error('Ctrl-C signal received. Quit.') logger.error('Ctrl-C signal received. Quit.')

View File

@ -1,10 +1,9 @@
import os import os
SCHEMA = os.getenv('NHENTAI_SCHEMA', 'https://') BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net')
BASE_URL = os.getenv('NHENTAI', 'nhentai.net')
DETAIL_URL = '%s/g' % BASE_URL
SEARCH_URL = '%s/search/' % BASE_URL
IMAGE_URL = 'https://i.%s/galleries' % BASE_URL
URL = '%s%s' % (SCHEMA, BASE_URL)
DETAIL_URL = '%s/g' % URL
SEARCH_URL = '%s/search/' % URL
IMAGE_URL = '%si.%s/galleries' % (SCHEMA, BASE_URL)
PROXY = {} PROXY = {}

View File

@ -43,7 +43,7 @@ class Doujinshi(object):
["URL", self.url], ["URL", self.url],
["Pages", self.pages], ["Pages", self.pages],
] ]
logger.info(u'Print doujinshi information\n{0}'.format(tabulate(table))) logger.info(u'Print doujinshi information of {0}\n{1}'.format(self.id, tabulate(table)))
def download(self): def download(self):
logger.info('Start download doujinshi: %s' % self.name) logger.info('Start download doujinshi: %s' % self.name)

View File

@ -1,10 +1,14 @@
# coding: utf-8 # coding: utf-8
class _Singleton(type): class _Singleton(type):
""" A metaclass that creates a Singleton base class when called. """ """ A metaclass that creates a Singleton base class when called. """
_instances = {} _instances = {}
def __call__(cls, *args, **kwargs): def __call__(cls, *args, **kwargs):
if cls not in cls._instances: if cls not in cls._instances:
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs) cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls] return cls._instances[cls]
class Singleton(_Singleton('SingletonMeta', (object,), {})): pass class Singleton(_Singleton('SingletonMeta', (object,), {})): pass