def main(): banner() logger.info('Using mirror: {0}'.format(BASE_URL)) options = cmd_parser() doujinshi_ids = [] doujinshi_list = [] if options.favorites: if not options.is_download: logger.warning('You do not specify --download option') doujinshi_ids = favorites_parser() elif options.tag: doujinshis = tag_parser(options.tag, max_page=options.max_page) print_doujinshi(doujinshis) if options.is_download and doujinshis: doujinshi_ids = map(lambda d: d['id'], doujinshis) elif options.keyword: doujinshis = search_parser(options.keyword, options.page) print_doujinshi(doujinshis) if options.is_download: doujinshi_ids = map(lambda d: d['id'], doujinshis) elif not doujinshi_ids: doujinshi_ids = options.id if doujinshi_ids: for id_ in doujinshi_ids: if options.delay: time.sleep(options.delay) doujinshi_info = doujinshi_parser(id_) doujinshi_list.append(Doujinshi(name_format=options.name_format, path=options.output_dir, **doujinshi_info)) if not options.is_show: downloader = Downloader(path=options.output_dir, thread=options.threads, timeout=options.timeout, delay=options.delay) for doujinshi in doujinshi_list: doujinshi.downloader = downloader doujinshi.download() if not options.is_nohtml and not options.is_cbz: generate_html(options.output_dir, doujinshi) elif options.is_cbz: generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir) if not platform.system() == 'Windows': logger.log(15, '🍻 All done.') else: logger.log(15, 'All done.') else: [doujinshi.show() for doujinshi in doujinshi_list]
def main(): banner() options = cmd_parser() logger.info('Using mirror: {0}'.format(BASE_URL)) from nhentai.constant import PROXY # constant.PROXY will be changed after cmd_parser() if PROXY != {}: logger.info('Using proxy: {0}'.format(PROXY)) # check your cookie check_cookie() index = 0 index_value = None doujinshis = [] doujinshi_ids = [] doujinshi_list = [] if options.favorites: if not options.is_download: logger.warning('You do not specify --download option') doujinshis = favorites_parser(options.page_range) elif options.tag: doujinshis = tag_parser(options.tag, sorting=options.sorting, max_page=options.max_page) elif options.artist: index = 1 index_value = options.artist elif options.character: index = 2 index_value = options.character elif options.parody: index = 3 index_value = options.parody elif options.group: index = 4 index_value = options.group elif options.language: index = 5 index_value = options.language elif options.keyword: doujinshis = search_parser(options.keyword, sorting=options.sorting, page=options.page) elif not doujinshi_ids: doujinshi_ids = options.id if index: doujinshis = tag_parser(index_value, max_page=options.max_page, index=index) print_doujinshi(doujinshis) if options.is_download and doujinshis: doujinshi_ids = [i['id'] for i in doujinshis] if options.is_save_download_history: with DB() as db: data = set(db.get_all()) doujinshi_ids = list(set(doujinshi_ids) - data) if doujinshi_ids: for i, id_ in enumerate(doujinshi_ids): if options.delay: time.sleep(options.delay) doujinshi_info = doujinshi_parser(id_) if doujinshi_info: doujinshi_list.append( Doujinshi(name_format=options.name_format, **doujinshi_info)) if (i + 1) % 10 == 0: logger.info('Progress: %d / %d' % (i + 1, len(doujinshi_ids))) if not options.is_show: downloader = Downloader(path=options.output_dir, size=options.threads, timeout=options.timeout, delay=options.delay) for doujinshi in doujinshi_list: doujinshi.downloader = downloader doujinshi.download() if options.is_save_download_history: with DB() as db: db.add_one(doujinshi.id) if not options.is_nohtml and not options.is_cbz: generate_html(options.output_dir, doujinshi) elif options.is_cbz: generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir, options.write_comic_info) if options.main_viewer: generate_main_html(options.output_dir) if not platform.system() == 'Windows': logger.log(15, '🍻 All done.') else: logger.log(15, 'All done.') else: [doujinshi.show() for doujinshi in doujinshi_list]
def main(): banner() if sys.version_info < (3, 0, 0): logger.error('nhentai now only support Python 3.x') exit(1) options = cmd_parser() logger.info('Using mirror: {0}'.format(BASE_URL)) # CONFIG['proxy'] will be changed after cmd_parser() if constant.CONFIG['proxy']['http']: logger.info('Using proxy: {0}'.format( constant.CONFIG['proxy']['http'])) if not constant.CONFIG['template']: constant.CONFIG['template'] = 'default' logger.info('Using viewer template "{}"'.format( constant.CONFIG['template'])) # check your cookie check_cookie() doujinshis = [] doujinshi_ids = [] doujinshi_list = [] page_list = paging(options.page) if options.favorites: if not options.is_download: logger.warning('You do not specify --download option') doujinshis = favorites_parser(page=page_list) elif options.keyword: if constant.CONFIG['language']: logger.info('Using default language: {0}'.format( constant.CONFIG['language'])) options.keyword += ' language:{}'.format( constant.CONFIG['language']) doujinshis = search_parser(options.keyword, sorting=options.sorting, page=page_list, is_page_all=options.page_all) elif not doujinshi_ids: doujinshi_ids = options.id print_doujinshi(doujinshis) if options.is_download and doujinshis: doujinshi_ids = [i['id'] for i in doujinshis] if options.is_save_download_history: with DB() as db: data = map(int, db.get_all()) doujinshi_ids = list(set(map(int, doujinshi_ids)) - set(data)) if doujinshi_ids: for i, id_ in enumerate(doujinshi_ids): if options.delay: time.sleep(options.delay) doujinshi_info = doujinshi_parser(id_) if doujinshi_info: doujinshi_list.append( Doujinshi(name_format=options.name_format, **doujinshi_info)) if (i + 1) % 10 == 0: logger.info('Progress: %d / %d' % (i + 1, len(doujinshi_ids))) if not options.is_show: downloader = Downloader(path=options.output_dir, size=options.threads, timeout=options.timeout, delay=options.delay) for doujinshi in doujinshi_list: if not options.dryrun: doujinshi.downloader = downloader doujinshi.download() doujinshi.downloader = downloader doujinshi.download() if options.generate_metadata: table = doujinshi.table generate_metadata_file(options.output_dir, table, doujinshi) if options.is_save_download_history: with DB() as db: db.add_one(doujinshi.id) if not options.is_nohtml and not options.is_cbz and not options.is_pdf: generate_html(options.output_dir, doujinshi, template=constant.CONFIG['template']) elif options.is_cbz: generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir) elif options.is_pdf: generate_pdf(options.output_dir, doujinshi, options.rm_origin_dir) if options.main_viewer: generate_main_html(options.output_dir) if not platform.system() == 'Windows': logger.log(15, '🍻 All done.') else: logger.log(15, 'All done.') else: [doujinshi.show() for doujinshi in doujinshi_list]