def start_download(): #main declare _doujin = nhentai.get_doujin(_startint) print("[!] Checking for dupes..") if path.exists(f"[{_startint}] {_doujin.titles['english']}"): print("[!] Dupe Found -- Skipping!") return; print(f"[!] Preparing download for ID {_startint}") # loli check _length_loli_check = len(_doujin.tags) is_loli = False if _check_for_loli: for tag_content in range(1, _length_loli_check): if tag_content == _length_loli_check: break; if _doujin.tags[tag_content].type == "tag": if _doujin.tags[tag_content].name == "lolicon": is_loli = True break; else: print(f"[!] Ignored non-Loli tag ({_doujin.tags[tag_content].name})") else: print(f"[!] Ignored non-tag object ({str(_length_loli_check)})") if is_loli: print(f"[!] Loli Doujin was removed from list: ({_doujin.titles['english']})") else: download_doujin(_startint)
def doujin_search(sauce): try: doujin_result = nhDetail(nhentai.get_doujin(int(sauce))) embed = doujin_embed(doujin_result, False) return embed except Exception as e: #err for invalid value return error_embed(f"{type(e).__name__}: {e}.", "doujin_search(sauce)")
def search_ndoujin(query: str): nid = 1 if not query: nid = nhentai.get_random_id() elif query.isnumeric(): nid = int(query) else: nid = choice(nhentai.search(query=query)).id return nhentai.get_doujin(id=nid)
async def tags(self, ctx, code: int): if ctx.author.id in data['bannedids']: await ctx.send( ':no_entry_sign: **Sorry, but you are banned from using Nen!**\n **Please contact the owner on the official server to appeal for unban**' ) return if isinstance(code, int): nsfwlogo = File("assets/images/nsfwlogo.png", filename="nsfwlogo.png") try: doujin = nh.get_doujin(code) title = doujin.titles['pretty'] tagmsg = '' for tag in doujin.tags: if tag.count > 999: tagnum = str(tag.count)[:-3] + 'k' else: tagnum = str(tag.count) tagmsg += f'**`{tag.name}: `**`{tagnum},` ' embed = Embed(title=f'Tags of {code}', color=Color.darker_gray()) embed.url = doujin.url embed.add_field(name='Tags of doujin:', value=tagmsg, inline=False) if ctx.channel.is_nsfw( ) or ctx.channel.id in data['pseudo_nsfw']: embed.set_thumbnail(url=doujin.thumbnail) else: embed.set_thumbnail(url='attachment://nsfwlogo.png') embed.set_footer( text= f'Requested by {ctx.author.name}#{ctx.author.discriminator}', icon_url=ctx.author.avatar_url) if ctx.channel.is_nsfw( ) or ctx.channel.id in data['pseudo_nsfw']: await ctx.send(embed=embed) else: await ctx.send(file=nsfwlogo, embed=embed) except Exception as e: print(e) if str(e) == 'A doujin with the given id wasn\'t found': await ctx.send( '`Sorry senpai, but the doujin was not found!`') else: await ctx.send('`I don\'t think thats a code, senpai....`')
async def doujin_generate(): try: sauce = await rand_id_generate() doujin_result = nhDetail(nhentai.get_doujin(sauce)) embed = doujin_embed(doujin_result, False) return embed except Exception as e: return error_embed(f"{type(e).__name__}: {e}.", "doujin_generate(param_type, parameter)")
async def gib(ctx, *, args): if args.isdigit(): try: await ctx.send("processing code...") doujin=nhentai.get_doujin(int(args)) thumb=doujin.thumbnail name=doujin.titles['english'] res = [] for i in doujin.tags: if i[0] not in res and (i != ''): res.append(i[2]) await ctx.send(name+"\n"+thumb+"\n"+str(res)) except Exception as e: logging.error("gib code failed: %s",e) await ctx.send("unable to fulfil request") elif isinstance(args,str): try: await ctx.send("processing tag...") o=1 ret=[] tag=1 while tag==1: listo=nhentai.search(args,o) if listo==[]: tag=0 for i in listo: ret.append(str(i.id)) o=o+1 key=random.randint(0,len(ret)-1) doujin=nhentai.get_doujin(int(ret[key])) name=doujin.titles['english'] thumb=doujin.thumbnail res = [] for i in doujin.tags: if i[0] not in res and (i != ''): res.append(i[2]) await ctx.send(name+"\n"+thumb+"\n"+ret[key]+"\n"+str(res)) except Exception as e: await ctx.send("unable to fulfil request") logging.error("gib tag failed: %s",e) else: await ctx.send("WTF are you asking for?")
async def again(_arg): try: _random = nhentai.get_doujin(_arg) _img = _random.cover return _random, _img except Exception as e: # await ctx.channel.send(e) # await asyncio.sleep(1) # await ctx.channel.send(f'{random.choice(errors)} <@256713166149386240> {e}') # await asyncio.sleep(2) await again(random.randint(0, 400000))
def get_doujin_data(doujin_numbers): doujin = nhentai.get_doujin(doujin_numbers) dataset = { "name": doujin.titles["pretty"], "tags": [doujin.tags[i][2] for i in range(len(doujin.tags))], "page_count": len(doujin.pages), "image_gallery": [doujin.pages[i].url for i in range(len(doujin.pages))], "cover": doujin.cover } return dataset
async def read(self, ctx, code: int): if ctx.author.id in data['bannedids']: await ctx.send( ':no_entry_sign: **Sorry, but you are banned from using Nen!**\n **Please contact the owner on the official server to appeal for unban**' ) return if ctx.channel.is_nsfw() or ctx.channel.id in data['pseudo_nsfw']: if isinstance(code, int): try: doujin = nh.get_doujin(code) # Wrapping the title title = doujin.titles['pretty'] titlelist = wrapper.wrap(text=title) wrappedtitle = '' for titlepart in titlelist: wrappedtitle += f'{titlepart}\n' pages = [] for page in doujin.pages: embed = Embed(title=f"Reading: {wrappedtitle}", color=Color.darker_gray()) embed.url = doujin.url embed.set_image(url=page.url) pages.append(embed) paginator = BotEmbedPaginator(ctx, pages) await paginator.run() except Exception as e: print(e) if str(e) == 'A doujin with the given id wasn\'t found': await ctx.send( '`Sorry senpai, but the doujin was not found!`') else: await ctx.send('`I don\'t think thats a code, senpai....`') else: await ctx.send( "`Sorry but senpai needs to be in a NSFW channel to read this :(`" )
async def nh(self, ctx, tag): """Displays the nhentai doujin with id <tag>""" itag = int(tag) try: doujin = nhentai.get_doujin(itag) e = ArgentaEmbed(ctx.author, title=doujin.titles["english"], url=doujin.url) e.add_field(name="Magic number", value=doujin.id) e.add_field(name="Tags", value=', '.join([i.name for i in doujin.tags])) e.set_image(url=doujin.cover) e.colour = discord.Colour.teal() log.info("Doujin requested.") print(e) await ctx.reply(embed=e) except ValueError: log.info(f"Requested: {tag}. Doujin not found.") await ctx.reply("Doujinshi not found.")
def nuke_gui(self, code): dataset = nhentai.get_doujin(code) metadata = {"artist": "Not Found", "tags": "Not Found", "language": "found"} for x in dataset.__dict__["tags"]: if x[1] == "artist": metadata["artist"] = x[2] if x[1] == "tag": if metadata["tags"] == "Not Found": metadata["tags"] = x[2] else: metadata["tags"] = metadata["tags"] + f", {x[2]}" if x[1] == "language": if metadata["language"] == "found": metadata["language"] = x[2] embedvar = discord.Embed(title=f"{Emoji[metadata['language']].value} {dataset.titles['pretty']}", description=dataset.url, colour=0x039e00) embedvar.set_image(url=dataset.thumbnail) embedvar.add_field(name="Author", value=metadata["artist"]) embedvar.add_field(name="Favorites", value=dataset.favorites) embedvar.set_footer(text=f"Tags: {metadata['tags']}") return embedvar
def download_doujin(_id): print(f"[!] Starting Download of ID {_id} - Preparing") _doujin_temp = nhentai.get_doujin(_id) print(f"[!] Making Title directory: {_doujin_temp.titles['english']}") os.mkdir(f"[{_id}] {_doujin_temp.titles['english']}") print(f"[!] Making Index: {_doujin_temp.titles['english']}") shutil.copyfile("index.php", f"./[{_id}] {_doujin_temp.titles['english']}/index.php") _doujin_pages_length = len(_doujin_temp.pages) for x in range(1, _doujin_pages_length): if x > _doujin_pages_length: print(f"[!] Doujin {_doujin_temp.titles['english']}) was downloaded!") break; print(f"[!] Downloading Page {x} from: {_doujin_temp.titles['english']}") urllib.request.urlretrieve(_doujin_temp[x].url, f"./[{_id}] {_doujin_temp.titles['english']}/{x}.png") print(f"[!] Downloading of '{_doujin_temp.titles['english']}' Complete!")
async def decode(self, ctx, sauce=None): if sauce is None: await ctx.send('Please enter the sauce first: \n' f'```{config["PREFIX"]}decode <sauce>```') else: try: hentai = nhentai.get_doujin(int(sauce)) cover = hentai.cover english_title = hentai.titles.get("english") japanese_title = hentai.titles.get("japanese") pages = str(len(hentai.pages)) link = "||https://nhentai.net/g/" + sauce + "||" tags = [getattr(i, 'name') for i in hentai.tags] await ctx.send( f'Cover: {cover} \n' f'**English Title:** {english_title if english_title else "none"} \n' f'**Japanese Title:** {japanese_title if japanese_title else "none"} \n' f'**Pages:** {pages} \n' f'**Link:** {link} \n' f'**Tags:** {", ".join(tags)}') except ValueError: await ctx.send( "Sorry, I'm unable to decode the sauce that you sent.")
def download_specific_doujin(): doujin_id_temp = input("Doujin ID:" ) print(f"[!] Attempting to get Doujin ({doujin_id_temp})") doujin_try = nhentai.get_doujin(doujin_id_temp) if path.exists(doujin_try.titles["english"]): print("[!] Dupe Found -- Quitting!") exit() os.mkdir(f"[{doujin_id_temp}] {doujin_try.titles['english']}") shutil.copyfile("index.php", f"./[{doujin_id_temp}] {doujin_try.titles['english']}/index.php") _custom_length = len(doujin_try.pages) for x in range(1, _custom_length): if x > _custom_length: print("[!] Download Complete") exit() print(f"[!] Downloading Page {x} from: {doujin_try.titles['english']}") urllib.request.urlretrieve(doujin_try[x].url, f"./[{doujin_id_temp}] {doujin_try.titles['english']}/{str(x)}.png") exit()
async def preview(self, ctx, arg='259049', req_page=1): _page = '' _dojin = '' _tot_page = '' if str(arg).startswith('http'): _sparg = str(arg).split(sep='/') print(_sparg) if len(_sparg) == 5: if _sparg[-1] == '': print('[!] Are you sure it\'s the id is correct?') await ctx.send('is the id correct?') elif _sparg[-1] != '': arg = int(_sparg[-1]) _page = 1 _link = str("/".join(_sparg)) + '/' + str(_page) print(arg, _link, _page) elif len(_sparg) == 6: if _sparg[-1] == '': _page = 1 _link = str("/".join(_sparg)) + str(_page) else: arg = int(_sparg[-2]) _page = _sparg[-1] _link = str("/".join(_sparg)) print(arg, _link, _page) elif len(_sparg) < 5 or len(_sparg) > 7: print('[!] Are you sure it\'s the correct link?') arg = int(arg) _page = int(_page) _dojin = nhentai.get_doujin(arg) _tot_page = len(_dojin.pages) else: _page = req_page _dojin = nhentai.get_doujin(arg) _tot_page = len(_dojin.pages) def get_img(_code, _page, _url=None): if _url is not None: return str((BeautifulSoup( (get(f'{_url}')).content, 'html.parser')).find_all('img', src=True)[-1]['src']) else: return str((BeautifulSoup( (get(f'https://nhentai.net/g/{_code}/{_page}')).content, 'html.parser')).find_all('img', src=True)[-1]['src']) _view = Embed(title=f'[{arg}]{_dojin.titles["english"]} page {_page}', color=0x87CEEB) _view.set_image(url=get_img(arg, _page)) try: await ctx.message.delete() except discord.errors.NotFound: pass _interactive_buttons = await ctx.send(embed=_view) _next_re = '▶' _prev_re = '◀' _pin = '📌' _close = '❌' _valid_reactions = ['▶', '◀', '📌', '❌'] _guide = await ctx.send(" ◀ Previous | ▶ Next | 📌 save") await _interactive_buttons.add_reaction('◀') await _interactive_buttons.add_reaction('▶') await _interactive_buttons.add_reaction('📌') await _interactive_buttons.add_reaction('❌') timeout = time.time() + 60 * 2 # 5 minutes from now while True: if time.time() > timeout: break done_tasks = None check_react = lambda reaction, user: user == ctx.author and str( reaction.emoji) in _valid_reactions check_button = lambda interaction, button: interaction.author == ctx.author and interaction.message == _interactive_buttons pending_tasks = [ self.bot.wait_for('button_click', check=check_button), self.bot.wait_for('reaction_add', check=check_react) ] done_tasks, pending_tasks = await asyncio.wait( pending_tasks, return_when=asyncio.FIRST_COMPLETED) for task in pending_tasks: task.cancel() timeout = time.time() + 60 * 2 # 5 minutes from now for task in done_tasks: reaction, user = await task interaction, button = await task if reaction and user: if time.time() > timeout: await ctx.send( 'Ah i forgot the link, you took too long') break elif str(reaction.emoji) == _pin: await _interactive_buttons.remove_reaction('📌', user) await user.send(f'https://nhentai.net/g/{arg}/{_page}') elif str(reaction.emoji) == _close: await _interactive_buttons.delete() await _guide.delete() elif _page == 1: if str(reaction.emoji) == _next_re: await _interactive_buttons.remove_reaction( '▶', user) _page += 1 _view = Embed( title= f'[{arg}]{_dojin.titles["english"]} page {_page}', color=0x87CEEB) _view.set_image(url=get_img(arg, _page)) await _interactive_buttons.edit(embed=_view) else: await _interactive_buttons.remove_reaction( '◀', user) elif _page == _tot_page: if str(reaction.emoji) == _prev_re: await _interactive_buttons.remove_reaction( '◀', user) _page -= 1 _view = Embed( title= f'[{arg}]{_dojin.titles["english"]} page {_page}', color=0x87CEEB) _view.set_image(url=get_img(arg, _page)) await _interactive_buttons.edit(embed=_view) else: await _interactive_buttons.remove_reaction( '◀', user) else: if str(reaction.emoji) == _prev_re: await _interactive_buttons.remove_reaction( '◀', user) _page -= 1 _view = Embed( title= f'[{arg}]{_dojin.titles["english"]} page {_page}', color=0x87CEEB) _view.set_image(url=get_img(arg, _page)) await _interactive_buttons.edit(embed=_view) elif str(reaction.emoji) == _next_re: await _interactive_buttons.remove_reaction( '▶', user) _page += 1 _view = Embed( title= f'[{arg}]{_dojin.titles["english"]} page {_page}', color=0x87CEEB) _view.set_image(url=get_img(arg, _page)) await _interactive_buttons.edit(embed=_view) else: ctx.send('How did you get here?')
async def info(self, ctx, code: int): if ctx.author.id in data['bannedids']: await ctx.send( ':no_entry_sign: **Sorry, but you are banned from using Nen!**\n **Please contact the owner on the official server to appeal for unban**' ) return if isinstance(code, int): nsfwlogo = File("assets/images/nsfwlogo.png", filename="nsfwlogo.png") try: doujin = nh.get_doujin(code) title = doujin.titles['pretty'] engtitle = doujin.titles['english'] japtitle = doujin.titles['japanese'] language = '' for tag in doujin.tags: if tag.type == 'language': language += tag.name.capitalize() + ' \n' artist = '' for tag in doujin.tags: if tag.type == 'artist': artist += string.capwords(tag.name) + ' \n' pagecount = 0 for page in doujin.pages: pagecount += 1 tagcount = 0 for tag in doujin.tags: tagcount += 1 tagmsg = '' for tag in doujin.tags: if tag.count > 999: tagnum = str(tag.count)[:-3] + 'k' else: tagnum = str(tag.count) tagmsg += f'**`{tag.name}: `**`{tagnum},` ' embed = Embed( title=f'{title}', description= f'Full English Title: `{engtitle}`\nJapanese Title: `{japtitle}`\n\u200b', color=Color.darker_gray()) embed.url = doujin.url embed.add_field(name='Code', value=doujin.id, inline=True) embed.add_field(name='Media ID', value=doujin.media_id, inline=True) embed.add_field(name='Artist', value=artist, inline=True) embed.add_field(name='Language', value=language, inline=True) embed.add_field(name='Pages', value=pagecount, inline=True) embed.add_field(name='Favorites', value=doujin.favorites, inline=True) embed.add_field(name='Tags', value=tagmsg, inline=False) if ctx.channel.is_nsfw( ) or ctx.channel.id in data['pseudo_nsfw']: embed.set_thumbnail(url=doujin.thumbnail) else: embed.set_thumbnail(url='attachment://nsfwlogo.png') embed.set_footer( text= f'Requested by {ctx.author.name}#{ctx.author.discriminator}', icon_url=ctx.author.avatar_url) if ctx.channel.is_nsfw( ) or ctx.channel.id in data['pseudo_nsfw']: await ctx.send(embed=embed) else: await ctx.send(file=nsfwlogo, embed=embed) except Exception as e: print(e) if str(e) == 'A doujin with the given id wasn\'t found': await ctx.send( '`Sorry senpai, but the doujin was not found!`') else: await ctx.send('`I don\'t think thats a code, senpai....`')
async def nukemedaddy(ctx): await ctx.send("Hacking the NNSA...") valid = False while valid == False: code = '' for i in range(6): code += str(random.randint(0,9)) url = 'https://nhentai.net/g/'+code+'/' r = requests.get(url) if r.status_code != 404: valid = True doujin=nhentai.get_doujin(int(code)) name=doujin.titles['english'] thumb=doujin.thumbnail res = [] for i in doujin.tags: if i[0] not in res and (i != ''): res.append(i[2]) user=ctx.message.author.id logging.debug('user=%s',user) server=ctx.guild.id logging.debug('server=%s',server) add=0 blessadd=0 istomboy=0 for ind,tag in enumerate(res): if tag in cursed: add=add+1 logging.info('add=%s',add) res[ind]='**'+tag+'**' if tag in blessed: blessadd=blessadd+1 logging.info('blessadd=%s',blessadd) res[ind]='***__'+tag+'__***' if tag == "tomboy": istomboy=1 userCursedVal,userBlessedVal,userTomboyVal=0,0,0 try: userCursed=open(fileDir+"/servers"+"/"+str(server)+"/"+str(user),"r") userList=userCursed.readlines() userCursedVal=int(userList[0].strip('\n ')) userBlessedVal=int(userList[1].strip('\n ')) userTomboyVal=int(userList[2].strip('\n ')) userCursed.close() userCursed=open(fileDir+"/servers"+"/"+str(server)+"/"+str(user),"w") logging.debug('added to users cursed value') except: try: userCursed=open(fileDir+"/servers"+"/"+str(server)+"/"+str(user),"w") userCursed.write("0\n0\n0") userCursedVal=0 userBlessedVal=0 logging.debug('initialised new user') except: os.mkdir(fileDir+"/servers"+"/"+str(server)) userCursed=open(fileDir+"/servers"+"/"+str(server)+"/"+str(user),"w") userCursed.write("0\n0\n0") userCursedVal=0 userBlessedVal=0 logging.debug('made new server directory and initialised new user') cursedMessage="Cursed Value: "+str(add) blessedMessage="Blessed Value: "+str(blessadd) await ctx.send(name+"\n"+thumb+"\n"+code+"\n"+str(res)+"\n"+cursedMessage+"\n"+blessedMessage) newCursedVal=str(userCursedVal+add)+"\n"+str(userBlessedVal+blessadd)+"\n"+str(userTomboyVal+istomboy) userCursed.write(newCursedVal) userCursed.close() logging.info('nukemedaddy finished')