Exemplo n.º 1
0
async def img_sampler(event):
    """ For .img command, search and return images matching the query. """
    await event.edit("`Processing...`")
    query = event.pattern_match.group(1)
    lim = findall(r"lim=\d+", query)
    try:
        lim = lim[0]
        lim = lim.replace("lim=", "")
        query = query.replace("lim=" + lim[0], "")
    except IndexError:
        lim = 7
    response = googleimagesdownload()
 
    # creating list of arguments
    arguments = {
        "keywords": query,
        "limit": lim,
        "format": "jpg",
        "no_directory": "no_directory"
    }
 
    # passing the arguments to the function
    paths = response.download(arguments)
    lst = paths[0][query]
    await event.client.send_file(
        await event.client.get_input_entity(event.chat_id), lst)
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
    await event.delete()
Exemplo n.º 2
0
async def img_sampler(event):
    """ For .img command, search and return images matching the query. """
    await event.edit("`Processing...`")
    query = event.pattern_match.group(1)
    lim = findall(r"lim=\d+", query)
    try:
        lim = lim[0]
        lim = lim.replace("lim=", "")
        query = query.replace("lim=" + lim[0], "")
    except IndexError:
        lim = 8
    response = googleimagesdownload()

    # creating list of arguments
    arguments = {
        "keywords": query,
        "limit": lim,
        "format": "jpg",
        "no_directory": "no_directory",
    }

    # if the query contains some special characters, googleimagesdownload errors out
    # this is a temporary workaround for it (maybe permanent)
    try:
        paths = response.download(arguments)
    except Exception as e:
        return await event.edit(f"`Error: {e}`")

    lst = paths[0][query]
    await event.client.send_file(
        await event.client.get_input_entity(event.chat_id), lst)
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
    await event.delete()
Exemplo n.º 3
0
async def img_sampler(event):
    """For .img command, search and return images matching the query."""
    await event.edit("`Processing...`")
    try:
        lim = int(event.pattern_match.group(1))
    except (TypeError, ValueError):
        lim = 5
    query = event.pattern_match.group(2)
    response = googleimagesdownload()

    # creating list of arguments
    arguments = {
        "keywords": query,
        "limit": lim,
        "format": "jpg",
        "no_directory": "no_directory",
    }

    # passing the arguments to the function
    paths = response.download(arguments)
    lst = paths[0][query.replace(",", " ")]
    try:
        await event.client.send_file(event.chat_id, lst)
    except MediaEmptyError:
        for i in lst:
            try:
                await event.client.send_file(event.chat_id, i)
            except MediaEmptyError:
                pass
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
    await event.delete()
Exemplo n.º 4
0
async def img_sampler(event):
    xx = await edit_or_reply(event, "`Sedang Mencari Gambar Yang Anda Cari...`")
    query = event.pattern_match.group(1)
    lim = findall(r"lim=\d+", query)
    try:
        lim = lim[0]
        lim = lim.replace("lim=", "")
        query = query.replace("lim=" + lim[0], "")
    except IndexError:
        lim = 15
    response = googleimagesdownload()
    # creating list of arguments
    arguments = {
        "keywords": query,
        "limit": lim,
        "format": "jpg",
        "no_directory": "no_directory",
    }
    # passing the arguments to the function
    paths = response.download(arguments)
    lst = paths[0][query]
    await event.client.send_file(
        await event.client.get_input_entity(event.chat_id), lst
    )
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
    await xx.delete()
Exemplo n.º 5
0
async def img_sampler(event):
    """For .img command, search and return images matching the query."""

    if event.is_reply and not event.pattern_match.group(2):
        query = await event.get_reply_message()
        query = str(query.message)
    else:
        query = str(event.pattern_match.group(2))

    if not query:
        return await event.edit("**Reply to a message or pass a query to search!**")

    await event.edit("**Processing...**")

    if event.pattern_match.group(1) != "":
        counter = int(event.pattern_match.group(1))
        if counter > 10:
            counter = int(10)
        if counter <= 0:
            counter = int(1)
    else:
        counter = int(3)

    response = googleimagesdownload()

    # creating list of arguments
    arguments = {
        "keywords": query,
        "limit": counter,
        "format": "png",
        "no_directory": "no_directory",
    }

    # if the query contains some special characters, googleimagesdownload errors out
    # this is a temporary workaround for it (maybe permanent)
    try:
        paths = response.download(arguments)
    except Exception as e:
        return await event.edit(f"**Error:** `{e}`")

    lst = paths[0][query.replace(",", " ")]
    try:
        await event.client.send_file(event.chat_id, lst)
    except MediaEmptyError:
        for i in lst:
            try:
                await event.client.send_file(event.chat_id, i)
            except MediaEmptyError:
                pass
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
    await event.delete()
Exemplo n.º 6
0
async def okgoogle(img):
    """ For .reverse command, Google search images and stickers. """
    if os.path.isfile("okgoogle.png"):
        os.remove("okgoogle.png")

    message = await img.get_reply_message()

    if not message or not message.media:
        return await img.edit("`Balas foto atau stiker.`")

    photo = io.BytesIO()
    await bot.download_media(message, photo)
    if not photo:
        return await img.edit("`Tidak dapat mengunduh gambar.`")

    await img.edit("`Sedang memproses...`")

    try:
        image = Image.open(photo)
    except OSError:
        return await img.edit(
            "`Kemungkinan besar yang berkaitan seksual tidak didukung.`")

    name = "okgoogle.png"
    image.save(name, "PNG")
    image.close()

    # https://stackoverflow.com/questions/23270175/google-reverse-image-search-using-post-request#28792943
    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:
        return await img.edit("`Google menyuruhku pergi.`")

    await img.edit("`Gambar berhasil diunggah ke Google, mungkin.`"
                   "\n`Sedang mengurai sumber, mungkin.`")
    os.remove(name)
    match = await ParseSauce(fetchUrl + "&preferences?hl=en&fg=1#languages")
    guess = str(match["best_guess"])
    imgspage = match["similar_images"]

    if not guess and not imgspage:
        return await img.edit("`Tidak dapat menemukan apa pun!`")

    try:
        counter = int(img.pattern_match.group(1))
    except BaseException:
        counter = int(3)
    counter = int(10) if counter > 10 else counter
    counter = int(3) if counter < 0 else counter

    if counter == 0:
        return await img.edit(f"**Kecocokan terbaik :** `{guess}`"
                              "\n\n[Gambar mirip secara visual]({fetchUrl})"
                              "\n\n[Hasil untuk {guess}]({imgspage})")

    await img.edit(f"**Kecocokan terbaik :** `{guess}`"
                   "\n\n[Gambar mirip secara visual]({fetchUrl})"
                   "\n\n[Hasil untuk {guess}]({imgspage})"
                   "\n\n`Mengambil gambar...`")

    response = googleimagesdownload()

    # creating list of arguments
    arguments = {
        "keywords": guess,
        "limit": counter,
        "format": "png",
        "no_directory": "no_directory",
    }

    try:
        paths = response.download(arguments)
    except Exception as e:
        return await img.edit(f"**Kecocokan terbaik :** `{guess}`"
                              "\n\n[Gambar mirip secara visual]({fetchUrl})"
                              "\n\n[Hasil untuk {guess}]({imgspage})"
                              "\n\n**Kesalahan :** `{e}`**.**")

    lst = paths[0][guess]
    await img.client.send_file(
        entity=img.chat_id,
        file=lst,
        reply_to=img,
    )
    await img.edit(f"**Kecocokan terbaik :** `{guess}`"
                   "\n\n[Gambar mirip secara visual]({fetchUrl})"
                   "\n\n[Hasil untuk {guess}]({imgspage})")
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
Exemplo n.º 7
0
async def okgoogle(img):
    """For .reverse command, Google search images and stickers."""
    if os.path.isfile("okgoogle.png"):
        os.remove("okgoogle.png")

    message = await img.get_reply_message()

    if not message or not message.media:
        return await img.edit("`Reply foto atau stiker.`")

    photo = io.BytesIO()
    await bot.download_media(message, photo)
    if not photo:
        return await img.edit("`Gagal mendownload gambar.`")

    await img.edit("`Processing...`")

    try:
        image = Image.open(photo)
    except OSError:
        return await img.edit("`sexuality tidak didukung, kemungkinan besar.`")

    name = "okgoogle.png"
    image.save(name, "PNG")
    image.close()

    # https://stackoverflow.com/questions/23270175/google-reverse-image-search-using-post-request#28792943
    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:
        return await img.edit("`Google menyuruhku pergi.`")

    await img.edit("**Image successfully uploaded to Google. Maybe.**"
                   "\n**Parsing source now. Maybe.**")
    os.remove(name)
    match = await ParseSauce(fetchUrl + "&preferences?hl=en&fg=1#languages")
    guess = str(match["best_guess"])
    imgspage = match["similar_images"]

    if not guess and not imgspage:
        return await img.edit("`Tidak dapat menemukan apa pun untuk si jelek.`"
                              )

    try:
        counter = int(img.pattern_match.group(1))
    except BaseException:
        counter = int(3)
    counter = int(10) if counter > 10 else counter
    counter = int(3) if counter < 0 else counter

    if counter == 0:
        return await img.edit(f"**Best match:** `{guess}`\
                              \n\n[Visually similar images]({fetchUrl})\
                              \n\n[Results for {guess}]({imgspage})")

    await img.edit(f"**Best match:** `{guess}`\
                   \n\n[Visually similar images]({fetchUrl})\
                   \n\n[Results for {guess}]({imgspage})\
                   \n\n**Fetching images...**")

    response = googleimagesdownload()

    # creating list of arguments
    arguments = {
        "keywords": guess,
        "limit": counter,
        "format": "png",
        "no_directory": "no_directory",
    }

    try:
        paths = response.download(arguments)
    except Exception as e:
        return await img.edit(f"**Best match:** `{guess}`\
                              \n\n[Visually similar images]({fetchUrl})\
                              \n\n[Results for {guess}]({imgspage})\
                              \n\n**Error:** `{e}`**.**")

    lst = paths[0][guess]
    await img.client.send_file(
        entity=img.chat_id,
        file=lst,
        reply_to=img,
    )
    await img.edit(f"**Best match:** `{guess}`\
                   \n\n[Visually similar images]({fetchUrl})\
                   \n\n[Results for {guess}]({imgspage})")
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
Exemplo n.º 8
0
async def okgoogle(img):
    """For .reverse command, Google search images and stickers."""
    if os.path.isfile("okgoogle.png"):
        os.remove("okgoogle.png")

    message = await img.get_reply_message()

    if not message or not message.media:
        return await img.edit("**Responda a uma foto ou adesivo.**")

    photo = io.BytesIO()
    await bot.download_media(message, photo)
    if not photo:
        return await img.edit("**Não foi possível baixar a imagem.**")

    await img.edit("**Processando...**")

    try:
        image = Image.open(photo)
    except OSError:
        return await img.edit("**Arquivo não suportado.**")

    name = "okgoogle.png"
    image.save(name, "PNG")
    image.close()

    # https://stackoverflow.com/questions/23270175/google-reverse-image-search-using-post-request#28792943
    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:
        return await img.edit("**Erro do Google.**")

    await img.edit("**Imagem carregada com sucesso para o Google.**"
                   "\n**Analisando fonte agora**")
    os.remove(name)
    match = await ParseSauce(fetchUrl + "&preferences?hl=en&fg=1#languages")
    guess = str(match["best_guess"])
    imgspage = match["similar_images"]

    if not guess and not imgspage:
        return await img.edit("**Não foram encontrados resultados**")

    try:
        counter = int(img.pattern_match.group(1))
    except:
        counter = int(3)
    counter = int(10) if counter > 10 else counter
    counter = int(3) if counter < 0 else counter

    if counter == 0:
        return await img.edit(f"**Melhor combinação:** `{guess}`\
                              \n\n[Imagens visualmente semelhantes]({fetchUrl})\
                              \n\n[Resultados para {guess}]({imgspage})")

    await img.edit(f"**Melhor combinação:** `{guess}`\
                   \n\n[Imagens visualmente semelhantes]({fetchUrl})\
                   \n\n[Resultados para {guess}]({imgspage})\
                   \n\n**Buscando imagens...**")

    response = googleimagesdownload()

    # creating list of arguments
    arguments = {
        "keywords": guess,
        "limit": counter,
        "format": "png",
        "no_directory": "no_directory",
    }

    try:
        paths = response.download(arguments)
    except Exception as e:
        return await img.edit(f"**Melhor combinação:** `{guess}`\
                              \n\n[Imagens visualmente semelhantes]({fetchUrl})\
                              \n\n[Resultados para {guess}]({imgspage})\
                              \n\n**Erro:** `{e}`**.**")

    lst = paths[0][guess]
    await img.client.send_file(
        entity=img.chat_id,
        file=lst,
        reply_to=img,
    )
    await img.edit(f"**Melhor combinação:** `{guess}`\
                   \n\n[Imagens visualmente semelhantes]({fetchUrl})\
                   \n\n[Resultados para {guess}]({imgspage})")
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))