""" This plugin provides a command to search for YouTube videos in the room """ # plugins/youtube_search.py import logging import simplematrixbotlib as botlib from youtube_search import YoutubeSearch async def handle_command(room, message, bot, PREFIX, config): match = botlib.MessageMatch(room, message, bot, PREFIX) if match.is_not_from_this_bot() and match.prefix() and match.command("yt"): args = match.args() if len(args) < 1: await bot.api.send_text_message(room.room_id, "Usage: !yt ") else: search_terms = " ".join(args) logging.info(f"Performing YouTube search for: {search_terms}") results = YoutubeSearch(search_terms, max_results=3).to_dict() if results: output = generate_output(results) await send_collapsible_message(room, bot, output) else: await bot.api.send_text_message(room.room_id, "No results found.") def generate_output(results): output = "" for video in results: output += f'' output += f'
' output += f'{video["title"]}
' output += f'Length: {video["duration"]} | Views: {video["views"]}
' if video["long_desc"]: output += f'Description: {video["long_desc"]}
' output += "

" return output async def send_collapsible_message(room, bot, content): message = f'
🍄Funguy ▶YouTube Search🍄
⤵︎Click Here To See Results⤵︎
{content}
' await bot.api.send_markdown_message(room.room_id, message)