def main(): banner() options = cmd_parser() doujinshi_ids = [] doujinshi_list = [] if options.keyword: doujinshis = search_parser(options.keyword, options.page) print_doujinshi(doujinshis) if options.is_download: doujinshi_ids = map(lambda d: d['id'], doujinshis) else: doujinshi_ids = options.ids if doujinshi_ids: for id in doujinshi_ids: doujinshi_info = doujinshi_parser(id) doujinshi_list.append(Doujinshi(**doujinshi_info)) else: exit(0) if options.is_download: downloader = Downloader(path=options.saved_path, thread=options.threads, timeout=options.timeout) for doujinshi in doujinshi_list: doujinshi.downloader = downloader doujinshi.download() else: map(lambda doujinshi: doujinshi.show(), doujinshi_list) logger.log(15, u'🍺 All done.')
def main(): banner() logger.info('Using mirror: {0}'.format(BASE_URL)) options = cmd_parser() doujinshi_ids = [] doujinshi_list = [] if options.login: username, password = options.login.split(':', 1) logger.info('Logging in to nhentai using credential pair \'%s:%s\'' % (username, '*' * len(password))) login(username, password) if options.is_download: for doujinshi_info in login_parser(): doujinshi_list.append(Doujinshi(**doujinshi_info)) if options.tag: doujinshis = tag_parser(options.tag, max_page=options.max_page) print_doujinshi(doujinshis) if options.is_download: doujinshi_ids = map(lambda d: d['id'], doujinshis) if options.keyword: doujinshis = search_parser(options.keyword, options.page) print_doujinshi(doujinshis) if options.is_download: doujinshi_ids = map(lambda d: d['id'], doujinshis) if not doujinshi_ids: doujinshi_ids = options.id if doujinshi_ids: for id_ in doujinshi_ids: doujinshi_info = doujinshi_parser(id_) doujinshi_list.append(Doujinshi(**doujinshi_info)) if not options.is_show: 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_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() 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 download(keyword='', pages=1, save_dir=''): with open(local_data, 'r+') as f: data = json.load(f) if not keyword: keyword = data['keyword'] else: data['keyword'] = keyword if not save_dir: save_dir = data['save_dir'] else: data['save_dir'] = save_dir downloader = Downloader(path=save_dir, thread=5, timeout=30) for page in range(1, pages + 1): print('\rIndexing...', end='') doujinshi_list = [] doujinshis = search_parser(keyword, page) doujinshi_ids = map(lambda d: d['id'], doujinshis) for id_ in doujinshi_ids: if str(id_) in data: continue doujinshi_info = doujinshi_parser(id_) data[str(id_)] = doujinshi_info doujinshi_list.append( Doujinshi(name_format='[%i] %s', **doujinshi_info)) print('Finished.') bar = tqdm( doujinshi_list, bar_format='{l_bar}{bar}{{{n_fmt}/{total_fmt}{postfix}}}', dynamic_ncols=True) for doujinshi in bar: bar.set_description(f'{doujinshi.id}, {doujinshi.pages} pages') doujinshi.downloader = downloader bar.set_postfix_str('Downloading...') doujinshi.download() bar.set_postfix_str('Packaging...') generate_cbz(save_dir, doujinshi, True) bar.set_postfix_str('Finished.') for k in data.keys(): if "ext" in data[k]: data[k].pop("ext") f.seek(0) json.dump(data, f, indent=4, ensure_ascii=False) f.truncate()
def main(): banner() logger.info('Using mirror: {0}'.format(BASE_URL)) options = cmd_parser() doujinshi_ids = [] doujinshi_list = [] if options.keyword: doujinshis = search_parser(options.keyword, options.page) print_doujinshi(doujinshis) if options.is_download: doujinshi_ids = map(lambda d: d['id'], doujinshis) else: doujinshi_ids = options.id if doujinshi_ids: for id in doujinshi_ids: doujinshi_info = doujinshi_parser(id) doujinshi_list.append(Doujinshi(**doujinshi_info)) else: exit(0) if not options.is_show: downloader = Downloader(path=options.output_dir, thread=options.threads, timeout=options.timeout) for doujinshi in doujinshi_list: doujinshi.downloader = downloader doujinshi.download() generate_html(options.output_dir, doujinshi) 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]
def main(): banner() logger.info('Using mirror: {0}'.format(BASE_URL)) options = cmd_parser() doujinshi_ids = [] doujinshi_list = [] if options.keyword: doujinshis = search_parser(options.keyword, options.page) print_doujinshi(doujinshis) if options.is_download: doujinshi_ids = map(lambda d: d['id'], doujinshis) else: doujinshi_ids = options.id if doujinshi_ids: for id in doujinshi_ids: doujinshi_info = doujinshi_parser(id) doujinshi_list.append(Doujinshi(**doujinshi_info)) else: exit(0) if not options.is_show: downloader = Downloader(path=options.output_dir, thread=options.threads, timeout=options.timeout) for doujinshi in doujinshi_list: doujinshi.downloader = downloader doujinshi.download() image_html = '' previous = '' doujinshi_dir = os.path.join(options.output_dir, str(doujinshi.id)) file_list = os.listdir(doujinshi_dir) file_list.sort() for index, image in enumerate(file_list): try: next_ = file_list[file_list.index(image) + 1] except IndexError: next_ = '' image_html += '<img src="{0}" class="image-item {1}" attr-prev="{2}" attr-next="{3}">\n'\ .format(image, 'current' if index == 0 else '', previous, next_) previous = image with open(os.path.join(os.path.dirname(__file__), 'doujinshi.html'), 'r') as template: html = template.read() data = html.format(TITLE=doujinshi.name, IMAGES=image_html) with open(os.path.join(doujinshi_dir, 'index.html'), 'w') as f: f.write(data) logger.log(15, 'HTML Viewer has been write to \'{0}\''.format(os.path.join(doujinshi_dir, 'index.html'))) if not platform.system() == 'Windows': logger.log(15, '🍺 All done.') else: logger.log(15, 'All done.') else: [doujinshi.show() for doujinshi in doujinshi_list]