|
@@ -4,21 +4,19 @@ from random import randint
|
|
|
import aiofiles
|
|
import aiofiles
|
|
|
import aiohttp
|
|
import aiohttp
|
|
|
import requests
|
|
import requests
|
|
|
|
|
+from asyncio import get_running_loop
|
|
|
from bs4 import BeautifulSoup
|
|
from bs4 import BeautifulSoup
|
|
|
from pyrogram import filters
|
|
from pyrogram import filters
|
|
|
|
|
|
|
|
-from wbb import SUDOERS, app
|
|
|
|
|
|
|
+from wbb import app
|
|
|
from wbb.core.decorators.errors import capture_err
|
|
from wbb.core.decorators.errors import capture_err
|
|
|
|
|
+from wbb.modules.nsfw import get_file_id_from_message
|
|
|
|
|
|
|
|
-__MODULE__ = "Reverse"
|
|
|
|
|
-__HELP__ = "/reverse - Reverse search an image. [SUDOERS ONLY]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.on_message(filters.command("reverse"))
|
|
@app.on_message(filters.command("reverse"))
|
|
|
@capture_err
|
|
@capture_err
|
|
|
async def reverse_image_search(_, message):
|
|
async def reverse_image_search(_, message):
|
|
|
- if message.from_user.id not in SUDOERS:
|
|
|
|
|
- return await message.reply_text("THIS FEATURE IS ONLY FOR SUDO USERS.")
|
|
|
|
|
if not message.reply_to_message:
|
|
if not message.reply_to_message:
|
|
|
return await message.reply_text(
|
|
return await message.reply_text(
|
|
|
"Reply to a message to reverse search it."
|
|
"Reply to a message to reverse search it."
|
|
@@ -34,37 +32,12 @@ async def reverse_image_search(_, message):
|
|
|
return await message.reply_text(
|
|
return await message.reply_text(
|
|
|
"Reply to an image/document/sticker/animation to reverse search it."
|
|
"Reply to an image/document/sticker/animation to reverse search it."
|
|
|
)
|
|
)
|
|
|
- m = await message.reply_text("Searching")
|
|
|
|
|
- if reply.document:
|
|
|
|
|
- if int(reply.document.file_size) > 3145728:
|
|
|
|
|
- return await m.edit("File too large")
|
|
|
|
|
- mime_type = reply.document.mime_type
|
|
|
|
|
- if mime_type != "image/png" and mime_type != "image/jpeg":
|
|
|
|
|
- return await m.edit("Document Mimetype Invalid")
|
|
|
|
|
- file_id = reply.document.file_id
|
|
|
|
|
- if reply.sticker:
|
|
|
|
|
- if reply.sticker.is_animated:
|
|
|
|
|
- if not reply.sticker.thumbs:
|
|
|
|
|
- return await m.edit("Sticker Has No Thumb")
|
|
|
|
|
- file_id = reply.sticker.thumbs[0].file_id
|
|
|
|
|
- else:
|
|
|
|
|
- file_id = reply.sticker.file_id
|
|
|
|
|
-
|
|
|
|
|
- if reply.photo:
|
|
|
|
|
- file_id = reply.photo.file_id
|
|
|
|
|
-
|
|
|
|
|
- if reply.animation:
|
|
|
|
|
- if not reply.animation.thumbs:
|
|
|
|
|
- return await m.edit(
|
|
|
|
|
- "Gif Has No Thumbnail, so it cannot be reverse searched"
|
|
|
|
|
- )
|
|
|
|
|
- file_id = reply.animation.thumbs[0].file_id
|
|
|
|
|
-
|
|
|
|
|
- if reply.video:
|
|
|
|
|
- if not reply.video.thumbs:
|
|
|
|
|
- return
|
|
|
|
|
- file_id = reply.video.thumbs[0].file_id
|
|
|
|
|
|
|
+ m = await message.reply_text("Downloading")
|
|
|
|
|
+ file_id = await get_file_id_from_message(reply)
|
|
|
|
|
+ if not file_id:
|
|
|
|
|
+ return m.edit("Can't reverse that")
|
|
|
image = await app.download_media(file_id, f"{randint(1000, 10000)}.jpg")
|
|
image = await app.download_media(file_id, f"{randint(1000, 10000)}.jpg")
|
|
|
|
|
+ await m.edit("Uploading to google's server")
|
|
|
async with aiofiles.open(image, "rb") as f:
|
|
async with aiofiles.open(image, "rb") as f:
|
|
|
if image:
|
|
if image:
|
|
|
search_url = "http://www.google.com/searchbyimage/upload"
|
|
search_url = "http://www.google.com/searchbyimage/upload"
|
|
@@ -72,9 +45,12 @@ async def reverse_image_search(_, message):
|
|
|
"encoded_image": (image, await f.read()),
|
|
"encoded_image": (image, await f.read()),
|
|
|
"image_content": "",
|
|
"image_content": "",
|
|
|
}
|
|
}
|
|
|
- response = requests.post(
|
|
|
|
|
- search_url, files=multipart, allow_redirects=False
|
|
|
|
|
|
|
+ def post_non_blocking():
|
|
|
|
|
+ return requests.post(
|
|
|
|
|
+ search_url, files=multipart, allow_redirects=False
|
|
|
)
|
|
)
|
|
|
|
|
+ loop = get_running_loop()
|
|
|
|
|
+ response = await loop.run_in_executor(None, post_non_blocking)
|
|
|
location = response.headers.get("Location")
|
|
location = response.headers.get("Location")
|
|
|
os.remove(image)
|
|
os.remove(image)
|
|
|
else:
|
|
else:
|
|
@@ -82,6 +58,7 @@ async def reverse_image_search(_, message):
|
|
|
headers = {
|
|
headers = {
|
|
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"
|
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"
|
|
|
}
|
|
}
|
|
|
|
|
+ await m.edit("Scraping query")
|
|
|
async with aiohttp.ClientSession() as session:
|
|
async with aiohttp.ClientSession() as session:
|
|
|
async with session.get(location, headers=headers) as resp:
|
|
async with session.get(location, headers=headers) as resp:
|
|
|
soup = BeautifulSoup(await resp.text(), "html.parser")
|
|
soup = BeautifulSoup(await resp.text(), "html.parser")
|
|
@@ -89,12 +66,15 @@ async def reverse_image_search(_, message):
|
|
|
anchor_element = div.find("a")
|
|
anchor_element = div.find("a")
|
|
|
text = anchor_element.text
|
|
text = anchor_element.text
|
|
|
try:
|
|
try:
|
|
|
|
|
+ await m.edit("Trying to send a photo")
|
|
|
await app.send_photo(
|
|
await app.send_photo(
|
|
|
message.chat.id,
|
|
message.chat.id,
|
|
|
photo=f"https://webshot.amanoteam.com/print?q={location}",
|
|
photo=f"https://webshot.amanoteam.com/print?q={location}",
|
|
|
- caption=f"**Query** [{text}]({location})",
|
|
|
|
|
|
|
+ caption=f"**Result**: [{text}]({location})",
|
|
|
)
|
|
)
|
|
|
await m.delete()
|
|
await m.delete()
|
|
|
except Exception:
|
|
except Exception:
|
|
|
text = f"**Result**: [Link]({location})"
|
|
text = f"**Result**: [Link]({location})"
|
|
|
await m.edit(text)
|
|
await m.edit(text)
|
|
|
|
|
+
|
|
|
|
|
+
|