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