diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 02c54da..19c3e9d 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -23,10 +23,12 @@ def banner(): def cmd_parser(): parser = OptionParser() 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('--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, 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='', help='output dir') 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') args, _ = parser.parse_args() + if args.tags: + logger.warning('`--tags` is under construction') + exit(0) + if args.id: _ = map(lambda id: id.strip(), args.id.split(',')) 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') parser.print_help() exit(0) diff --git a/nhentai/command.py b/nhentai/command.py index 2c8adc0..73d2e14 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -31,13 +31,18 @@ def main(): else: exit(0) - downloader = Downloader(path=options.output_dir, - thread=options.threads, timeout=options.timeout) - for doujinshi in doujinshi_list: - doujinshi.downloader = downloader - doujinshi.download() + if not options.is_show: + downloader = Downloader(path=options.output_dir, + thread=options.threads, timeout=options.timeout) - logger.log(15, u'🍺 All done.') + for doujinshi in doujinshi_list: + doujinshi.downloader = downloader + doujinshi.download() + + logger.log(15, u'🍺 All done.') + + else: + [doujinshi.show() for doujinshi in doujinshi_list] def signal_handler(signal, frame): diff --git a/nhentai/constant.py b/nhentai/constant.py index 66656a3..0dab75a 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -1,10 +1,9 @@ import os -SCHEMA = os.getenv('NHENTAI_SCHEMA', 'https://') -BASE_URL = os.getenv('NHENTAI', 'nhentai.net') +BASE_URL = os.getenv('NHENTAI', 'https://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 = {} diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index 4bcee71..1e557f2 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -43,7 +43,7 @@ class Doujinshi(object): ["URL", self.url], ["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): logger.info('Start download doujinshi: %s' % self.name) diff --git a/nhentai/utils.py b/nhentai/utils.py index dfbc21d..ee3d060 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -1,10 +1,14 @@ # coding: utf-8 + + class _Singleton(type): """ A metaclass that creates a Singleton base class when called. """ _instances = {} + def __call__(cls, *args, **kwargs): if cls not in cls._instances: cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] + class Singleton(_Singleton('SingletonMeta', (object,), {})): pass \ No newline at end of file