[YouTube] Initial commit
This commit is contained in:
@@ -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
|
||||
|
||||
5
youtube/__init__.py
Normal file
5
youtube/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .youtube import YouTube
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(YouTube(bot))
|
||||
12
youtube/info.json
Normal file
12
youtube/info.json
Normal file
@@ -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"
|
||||
}
|
||||
46
youtube/youtube.py
Normal file
46
youtube/youtube.py
Normal file
@@ -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())
|
||||
Reference in New Issue
Block a user