diff --git a/README.md b/README.md index 8d4aff5..1dac797 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ adventure - Originally by Locastan. My version is a collaboration between Trusty antiphoneclapper - Detects and removes bad GIFs posted in chat that have malformed frames. Thanks to Sitryk for all of the code that actually mattered for detection in this cog. Config stuff tacked on by me. Later iterations will include emoji recognizing and possibly link detection for these bad images. -away - Originally by Paddo, written for v3 by Axas, final tests by aikaterna. Set and unset a user as being "away". +away - Originally by Paddo, written for v3 by Axas, final tests by aikaterna, and large improvements by TrustyJAID. Set and unset a user as being "away". blurplefy - Make an avatar or an image upload blurple for Discord's 3rd anniversary. @@ -43,4 +43,6 @@ tools - A collection of mod and admin tools, ported from my v2 version. Sitryk i wolfram - A v3 port of Paddo's abandoned Wolfram Alpha cog. +youtube - A v3 port of Paddo's youtube search cog for v2. + Are you looking for the v3 lavalink music cog? It's been added to Red v3 as the audio module. Install from develop and ask in the Red support server for help if you need it, or join my server. https://discord.gg/th6eS3T diff --git a/youtube/__init__.py b/youtube/__init__.py new file mode 100644 index 0000000..375cccc --- /dev/null +++ b/youtube/__init__.py @@ -0,0 +1,5 @@ +from .youtube import YouTube + + +def setup(bot): + bot.add_cog(YouTube(bot)) diff --git a/youtube/info.json b/youtube/info.json new file mode 100644 index 0000000..47bae50 --- /dev/null +++ b/youtube/info.json @@ -0,0 +1,12 @@ +{ + "author": [ + "aikaterna" + ], + "description": "Search youtube for videos, originally by Paddo. This version also includes a ytsearch command to look through multiple results.", + "install_msg": "Thanks for installing, have fun.", + "short": "Search youtube for videos.", + "tags": [ + "youtube" + ], + "type": "COG" +} diff --git a/youtube/youtube.py b/youtube/youtube.py new file mode 100644 index 0000000..b9762ae --- /dev/null +++ b/youtube/youtube.py @@ -0,0 +1,46 @@ +import aiohttp +import re +from redbot.core import commands +from redbot.core.utils.menus import menu, DEFAULT_CONTROLS + + +class YouTube(commands.Cog): + """Search YouTube for videos.""" + + def __init__(self, bot): + self.bot = bot + self.session = aiohttp.ClientSession() + + async def _youtube_results(self, query: str): + try: + search_url = "https://www.youtube.com/results?" + payload = {"search_query": "".join(query)} + headers = {"user-agent": "Red-cog/3.0"} + async with self.session.get(search_url, params=payload, headers=headers) as r: + result = await r.text() + yt_find = re.findall(r"href=\"\/watch\?v=(.{11})", result) + + url_list = [] + for track in yt_find: + url = f"https://www.youtube.com/watch?v={track}" + url_list.append(url) + + except Exception as e: + url_list = [f"Something went terribly wrong! [{e}]"] + + return list(set(url_list)) + + @commands.command() + async def youtube(self, ctx, *, query: str): + """Search on Youtube.""" + result = await self._youtube_results(query) + await ctx.send(result[0]) + + @commands.command() + async def ytsearch(self, ctx, *, query: str): + """Search on Youtube, multiple results.""" + result = await self._youtube_results(query) + await menu(ctx, result, DEFAULT_CONTROLS) + + def cog_unload(self): + self.bot.loop.create_task(self.session.close())