async def img_search(client, message): pablo = await edit_or_reply(message, "`Processing...`") query = get_text(message) if not query: await pablo.edit("`Give Text For Image Search!`") return if "|" in query: lim = query.split("|")[1] if (query.split("|")[1]).isdigit() else 5 else: lim = 5 response = googleimagesdownload() arguments = { "keywords": query, "limit": lim, "format": "jpg", "silent_mode": True, "no_directory": "no_directory", } paths = response.download(arguments) lst = paths[0][query] Beast = [] for x in lst: try: Beast.append(InputMediaPhoto(str(x))) except: pass await client.send_media_group(message.chat.id, media=Beast) shutil.rmtree(os.path.dirname(os.path.abspath(lst[0]))) await pablo.delete()
def download_imgs_from_google(query: str, lim: int): response = googleimagesdownload() arguments = { "keywords": query, "silent_mode": True, "limit": lim, "format": "jpg", "no_directory": "no_directory", } paths = response.download(arguments) path_ = paths[0][query] Beast = [InputMediaPhoto(str(x)) for x in path_] return path_, Beast
async def reverseing(client, message): pablo = await edit_or_reply(message, "`Searching For The Image.....`") if not message.reply_to_message or not message.reply_to_message.photo: await pablo.edit("Reply to A image...") return imoge = await message.reply_to_message.download() try: image = Image.open(imoge) except OSError: return name = "okgoogle.png" image.save(name, "PNG") image.close() searchUrl = "https://www.google.com/searchbyimage/upload" multipart = {"encoded_image": (name, open(name, "rb")), "image_content": ""} response = requests.post(searchUrl, files=multipart, allow_redirects=False) fetchUrl = response.headers["Location"] if response != 400: await pablo.edit( "`Image successfully uploaded to Google. Maybe.`" "\n`Parsing source now. Maybe.`" ) else: await pablo.edit("`Google told me to f**k off.`") return os.remove(name) match = await ParseSauce(fetchUrl + "&preferences?hl=en&fg=1#languages") guess = match["best_guess"] imgspage = match["similar_images"] if guess and imgspage: await pablo.edit(f"[{guess}]({fetchUrl})\n\n`Looking for this Image...`") else: await pablo.edit("`Can't find this piece of shit.`") return lim = findall(r"lim=\d+", guess) try: lim = lim[0] lim = lim.replace("lim=", "") guess = guess.replace("lim=" + lim[0], "") except IndexError: lim = 5 response = googleimagesdownload() arguments = { "keywords": guess, "silent_mode": True, "limit": lim, "format": "jpg", "no_directory": "no_directory", } paths = response.download(arguments) lst = paths[0][guess] await pablo.edit(f"[{guess}]({fetchUrl})\n\n[Visually similar images]({imgspage})") Beast = [] for x in lst: Beast.append(InputMediaPhoto(f"{x}")) await client.send_media_group(message.chat.id, media=Beast) shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))