video-stream/program/ytsearch.py

51 lines
1.6 KiB
Python
Raw Permalink Normal View History

2021-10-11 03:16:54 +00:00
import logging
from config import BOT_USERNAME
2021-10-28 05:30:17 +00:00
from driver.filters import command, other_filters
2021-10-25 11:55:09 +00:00
from pyrogram import Client
from pyrogram.types import (
InlineKeyboardButton,
InlineKeyboardMarkup,
Message,
)
2021-10-11 03:16:54 +00:00
from youtube_search import YoutubeSearch
logging.basicConfig(
2021-10-25 11:55:09 +00:00
level=logging.DEBUG,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
2021-10-11 03:16:54 +00:00
logger = logging.getLogger(__name__)
logging.getLogger("pyrogram").setLevel(logging.WARNING)
@Client.on_message(command(["search", f"search@{BOT_USERNAME}"]))
async def ytsearch(_, message: Message):
2021-10-25 11:55:09 +00:00
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"🗑 Close", callback_data="cls",
)
]
]
)
2021-10-11 03:16:54 +00:00
try:
if len(message.command) < 2:
await message.reply_text("/search **needs an argument !**")
return
query = message.text.split(None, 1)[1]
m = await message.reply_text("🔎 **Searching...**")
results = YoutubeSearch(query, max_results=5).to_dict()
i = 0
text = ""
while i < 5:
text += f"🏷 **Name:** __{results[i]['title']}__\n"
text += f"⏱ **Duration:** `{results[i]['duration']}`\n"
text += f"👀 **Views:** `{results[i]['views']}`\n"
text += f"📣 **Channel:** {results[i]['channel']}\n"
text += f"🔗: https://www.youtube.com{results[i]['url_suffix']}\n\n"
i += 1
2021-10-25 11:55:09 +00:00
await m.edit(text, reply_markup=keyboard, disable_web_page_preview=True)
2021-10-11 03:16:54 +00:00
except Exception as e:
await m.edit(str(e))