Spaces:
Paused
Paused
| # | |
| # Copyright (C) 2021-2022 by TeamYukki@Github, < https://github.com/TeamYukki >. | |
| # | |
| # This file is part of < https://github.com/TeamYukki/YukkiMusicBot > project, | |
| # and is released under the "GNU v3.0 License Agreement". | |
| # Please see < https://github.com/TeamYukki/YukkiMusicBot/blob/master/LICENSE > | |
| # | |
| # All rights reserved. | |
| from pyrogram.types import (InlineKeyboardButton, | |
| InlineKeyboardMarkup, | |
| InlineQueryResultPhoto) | |
| from youtubesearchpython.__future__ import VideosSearch | |
| from config import BANNED_USERS, MUSIC_BOT_NAME | |
| from YukkiMusic import app | |
| from YukkiMusic.utils.inlinequery import answer | |
| async def inline_query_handler(client, query): | |
| text = query.query.strip().lower() | |
| answers = [] | |
| if text.strip() == "": | |
| try: | |
| await client.answer_inline_query( | |
| query.id, results=answer, cache_time=10 | |
| ) | |
| except: | |
| return | |
| else: | |
| a = VideosSearch(text, limit=20) | |
| result = (await a.next()).get("result") | |
| for x in range(15): | |
| title = (result[x]["title"]).title() | |
| duration = result[x]["duration"] | |
| views = result[x]["viewCount"]["short"] | |
| thumbnail = result[x]["thumbnails"][0]["url"].split("?")[ | |
| 0 | |
| ] | |
| channellink = result[x]["channel"]["link"] | |
| channel = result[x]["channel"]["name"] | |
| link = result[x]["link"] | |
| published = result[x]["publishedTime"] | |
| description = f"{views} | {duration} Mins | {channel} | {published}" | |
| buttons = InlineKeyboardMarkup( | |
| [ | |
| [ | |
| InlineKeyboardButton( | |
| text="π₯ Watch on Youtube", | |
| url=link, | |
| ) | |
| ], | |
| ] | |
| ) | |
| searched_text = f""" | |
| βοΈ**Title:** [{title}]({link}) | |
| β³**Duration:** {duration} Mins | |
| π**Views:** `{views}` | |
| β°**Published Time:** {published} | |
| π₯**Channel Name:** {channel} | |
| π**Channel Link:** [Visit From Here]({channellink}) | |
| __Reply with /play on this searched message to stream it on voice chat.__ | |
| β‘οΈ ** Inline Search By {MUSIC_BOT_NAME} **""" | |
| answers.append( | |
| InlineQueryResultPhoto( | |
| photo_url=thumbnail, | |
| title=title, | |
| thumb_url=thumbnail, | |
| description=description, | |
| caption=searched_text, | |
| reply_markup=buttons, | |
| ) | |
| ) | |
| try: | |
| return await client.answer_inline_query( | |
| query.id, results=answers | |
| ) | |
| except: | |
| return | |