# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
# █▀█ █ █ █ █▀█ █▀▄ █
# © Copyright 2022
# https://t.me/hikariatama
#
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# meta pic: https://static.dan.tatar/anisearch_icon.png
# meta banner: https://mods.hikariatama.ru/badges/anisearch.jpg
# meta developer: @hikarimods
# scope: hikka_only
# scope: hikka_min 1.2.10
import requests
from telethon.tl.types import Message
from .. import loader, utils
@loader.tds
class AniSearchMod(loader.Module):
"""Searches for anime exact moment by only frame screenshot"""
strings = {
"name": "AniSearch",
"404": (
"😢 I don't know which"
" anime it is..."
),
"searching": (
"👀 Let me take a"
" look..."
),
"result": (
"😎 I think, it is..."
" {} episode {} at"
" {}\nI'm sure at {}%"
),
"media_not_found": (
"🚫 Media not found"
),
}
strings_ru = {
"404": (
"😢 Я не знаю, что это за"
" аниме..."
),
"searching": (
"👀 Дай глянуть..."
),
"result": (
"😎 Я думаю, что это..."
" {} эпизод {} на"
" {}\nЯ уверен на {}%"
),
"media_not_found": (
"🚫 Медиа не найдено"
),
"_cmd_doc_anisearch": "Поиск аниме по скриншоту",
"_cls_doc": "Ищет конкретную серию и тайм-код аниме по скриншоту",
}
strings_de = {
"404": (
"😢 Ich weiß nicht,"
" welcher Anime das ist..."
),
"searching": (
"👀 Lass mich mal"
" schauen..."
),
"result": (
"😎 Ich denke, es ist..."
" {} Folge {} um"
" {}\nIch bin mir zu {}% sicher"
),
"media_not_found": (
"🚫 Medien nicht"
" gefunden"
),
"_cmd_doc_anisearch": "Suche Anime nach einem Screenshot",
"_cls_doc": (
"Sucht nach einer bestimmten Folge und Zeitstempel eines Anime nach einem"
" Screenshot"
),
}
strings_hi = {
"404": (
"😢 मैं नहीं जानता कि यह"
" कौन सी एनीमे है..."
),
"searching": (
"👀 मुझे देखने के लिए दें..."
),
"result": (
"😎 मैं सोचता हूँ कि..."
" {} एपिसोड {} में"
" {}\nमैं {}% सुनिश्चित हूँ"
),
"media_not_found": (
"🚫 मीडिया नहीं मिला"
),
"_cmd_doc_anisearch": "एक स्क्रीनशॉट के लिए एनीमे खोजें",
"_cls_doc": "एक स्क्रीनशॉट के लिए एक विशिष्ट एपिसोड और समय-स्टैंप खोजता है",
}
strings_uz = {
"404": (
"😢 Bu anime haqida"
" gapirishim mumkin emas..."
),
"searching": (
"👀 Qarashimni ko'rish"
" uchun beraman..."
),
"result": (
"😎 Aytaman..."
" {} {} da"
" {}\nMenga %{} hisoblanadi"
),
"media_not_found": (
"🚫 Media topilmadi"
),
"_cmd_doc_anisearch": "Ekran rasmini ishlatib anime qidirish",
"_cls_doc": (
"Ekran rasmini ishlatib biror animening biror qismi va vaqtini qidiradi"
),
}
strings_tr = {
"404": (
"😢 Bu anime hakkında"
" bilgim yok..."
),
"searching": (
"👀 Göz atayım..."
),
"result": (
"😎 Sanırım..."
" {} {} da"
" {}\n%{} ihtimalle"
),
"media_not_found": (
"🚫 Medya bulunamadı"
),
"_cmd_doc_anisearch": "Bir ekran görüntüsü kullanarak anime arama",
"_cls_doc": (
"Bir ekran görüntüsü kullanarak bir anime serisinin ve zaman damgasının bir"
" kısmını arar"
),
}
async def anisearchcmd(self, message: Message):
"""Search anime by frame"""
reply = await message.get_reply_message()
if not message.media and (not reply or not reply.media):
await utils.answer(message, self.strings("media_not_found"))
return
message = await utils.answer(message, self.strings("searching"))
search_result = requests.post(
"https://api.trace.moe/search",
files={
"image": await self._client.download_media(
message if message.media else reply,
bytes,
)
},
).json()
if not search_result or not search_result.get("result", False):
await utils.answer(message, self.strings("404"))
return
anilist = requests.post(
"https://graphql.anilist.co",
json={
"query": (
"query($id: Int) {Media(id: $id, type: ANIME) {id idMal title"
" {native romaji english } synonyms isAdult } }"
),
"variables": {"id": search_result["result"][0]["anilist"]},
},
).json()
title = (
anilist["data"]["Media"]["title"]["english"]
or anilist["data"]["Media"]["title"]["romaji"]
or anilist["data"]["Media"]["title"]["native"]
)
if not title:
await utils.answer(message, self.strings("media_not_found"))
return
pos = search_result["result"][0]["from"]
episode = search_result["result"][0]["episode"]
conf = search_result["result"][0]["similarity"]
await utils.answer(
message,
self.strings("result").format(
title,
episode,
f"{round(pos // 60)}:{round(pos % 60)}",
round(conf * 100, 2),
),
)