2 from __future__ import print_function
3 from optparse import OptionParser
4 from logger import logger
6 from itertools import ifilter as filter
15 logger.info('''nHentai: あなたも変態。 いいね?
17 _ __ | | | | ___ _ __ | |_ __ _(_)
18 | '_ \| |_| |/ _ \ '_ \| __/ _` | |
19 | | | | _ | __/ | | | || (_| | |
20 |_| |_|_| |_|\___|_| |_|\__\__,_|_|
25 parser = OptionParser()
26 parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not')
27 parser.add_option('--id', type='int', dest='id', action='store', help='doujinshi id of nhentai')
28 parser.add_option('--ids', type='str', dest='ids', action='store', help='doujinshi id set, e.g. 1,2,3')
29 parser.add_option('--search', type='string', dest='keyword', action='store', help='keyword searched')
30 parser.add_option('--page', type='int', dest='page', action='store', default=1,
31 help='page number of search result')
32 parser.add_option('--path', type='string', dest='saved_path', action='store', default='',
33 help='path which save the doujinshi')
34 parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
35 help='thread count of download doujinshi')
36 parser.add_option('--timeout', type='int', dest='timeout', action='store', default=30,
37 help='timeout of download doujinshi')
38 parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
39 help='use proxy, example: http://127.0.0.1:1080')
40 args, _ = parser.parse_args()
43 _ = map(lambda id: id.strip(), args.ids.split(','))
44 args.ids = set(map(int, filter(lambda id: id.isdigit(), _)))
46 if args.is_download and not args.id and not args.ids and not args.keyword:
47 logger.critical('Doujinshi id/ids is required for downloading')
52 args.ids = (args.id, ) if not args.ids else args.ids
54 if not args.keyword and not args.ids:
60 elif args.threads > 10:
61 logger.critical('Maximum number of used threads is 10')
66 proxy_url = urlparse.urlparse(args.proxy)
67 if proxy_url.scheme not in ('http', 'https'):
68 logger.error('Invalid protocol \'{}\' of proxy, ignored'.format(proxy_url.scheme))
70 constant.PROXY = {proxy_url.scheme: args.proxy}