async def trace_bek(message: Message): """ Reverse Search Anime Clips/Photos """ replied = message.reply_to_message if not replied: await message.edit("Ara Ara... Reply to a Media Senpai") return if not (replied.photo or replied.video or replied.animation): await message.err("Nani, reply to gif/photo/video") return if not os.path.isdir(Config.DOWN_PATH): os.makedirs(Config.DOWN_PATH) await message.edit("He he, let me use my skills") dls = await message.client.download_media( message=message.reply_to_message, file_name=Config.DOWN_PATH, progress=progress, progress_args=(message, "Downloading Media") ) dls_loc = os.path.join(Config.DOWN_PATH, os.path.basename(dls)) if replied.animation or replied.video: img_loc = os.path.join(Config.DOWN_PATH, "trace.png") await take_screen_shot(dls_loc, 0, img_loc) if not os.path.lexists(img_loc): await message.err("Media not found...", del_in=5) return os.remove(dls_loc) dls_loc = img_loc if dls_loc: async with ClientSession() as session: tracemoe = tracemoepy.AsyncTrace(session=session) try: search = await tracemoe.search(dls_loc, upload_file=True) except ServerError: try: search = await tracemoe.search(dls_loc, upload_file=True) except ServerError: await message.reply('Couldnt parse results!!!') return result = search["result"][0] caption_ = ( f"**Title**: {result['anilist']['title']['english']}" f" (`{result['anilist']['title']['native']}`)\n" f"\n**Anilist ID:** `{result['anilist']['id']}`" f"\n**Similarity**: `{(str(result['similarity']*100))[:5]}`" f"\n**Episode**: `{result['episode']}`" ) preview = result['video'] await message.reply_video(preview, caption=caption_) await message.delete()
async def trace_bek(message: Message): """ Reverse Search Anime Clips/Photos """ dls_loc = await media_to_image(message) if dls_loc: async with ClientSession() as session: tracemoe = tracemoepy.AsyncTrace(session=session) search = await tracemoe.search(dls_loc, upload_file=True) os.remove(dls_loc) result = search["docs"][0] caption = ( f"**Title**: **{result['title_english']}**\n" f" 🇯🇵 (`{result['title_romaji']} - {result['title_native']}`)\n" f"\n**Anilist ID:** `{result['anilist_id']}`" f"\n**Similarity**: `{result['similarity']*100}`" f"\n**Episode**: `{result['episode']}`") preview = await tracemoe.natural_preview(search) with open("preview.mp4", "wb") as f: f.write(preview) await message.reply_video("preview.mp4", caption=caption) os.remove("preview.mp4") await message.delete()
def __init__(self, bot: Red): self.bot = bot self.logger = logging.getLogger("red.eilacogs.Source") self.tracemoe = tracemoepy.AsyncTrace()
async def tracemoe_rs(client, message): dis_loc = '' if message.reply_to_message: message_ = message.reply_to_message if message_.sticker and message_.sticker.file_name.endswith('.tgs'): await message.delete() return if (message_.photo or message_.animation or message_.sticker): dis = await client.download_media( message=message_, file_name=screen_shot, ) dis_loc = os.path.join(screen_shot, os.path.basename(dis)) if message_.animation: await edit_or_reply(message, text='`Converting this Gif`') img_file = os.path.join(screen_shot, 'grs.jpg') await take_screen_shot(dis_loc, 0, img_file) if not os.path.lexists(img_file): await edit_or_reply( message, text='`Something went wrong in Conversion`', ) await asyncio.sleep(5) await message.delete() return dis_loc = img_file if message_.video: nama = 'video_{}-{}.mp4'.format( message.reply_to_message.video.date, message.reply_to_message.video.file_size, ) await client.download_media( message.reply_to_message.video, file_name='nana/downloads/' + nama, ) dis_loc = 'nana/downloads/' + nama img_file = os.path.join(screen_shot, 'grs.jpg') await take_screen_shot(dis_loc, 0, img_file) if not os.path.lexists(img_file): await edit_or_reply( message, text='`Something went wrong in Conversion`', ) await asyncio.sleep(5) await message.delete() return session = aiohttp.ClientSession() tracemoe = tracemoepy.AsyncTrace(session=session) if message_.video: search = await tracemoe.search(img_file, upload_file=True) os.remove(img_file) else: search = await tracemoe.search(dis_loc, upload_file=True) os.remove(dis_loc) result = search['docs'][0] ms_g = (f"**Title**: {result['title_english']}" f"\n**Similarity**: {result['similarity']*100}" f"\n**Episode**: {result['episode']}") preview = await tracemoe.natural_preview(search) with open('preview.mp4', 'wb') as f: f.write(preview) await message.delete() await client.send_video( message.chat.id, 'preview.mp4', caption=ms_g, reply_to_message_id=ReplyCheck(message), ) await asyncio.gather( tracemoe.aio_session.close(), asyncio.sleep(5), message.delete(), ) os.remove('preview.mp4') else: await edit_or_reply(message, text='`Reply to a message to proceed`') await asyncio.sleep(5) await message.delete() return