From 8bc45786b18be681ef4b5c507a62c9b40453f81a Mon Sep 17 00:00:00 2001 From: top1055 <123alexfeetham@gmail.com> Date: Thu, 25 May 2023 09:06:27 +0100 Subject: [PATCH] added translate interface, needs to fill functionality next --- cogs/music/main.py | 13 +++++++---- cogs/music/translate.py | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 cogs/music/translate.py diff --git a/cogs/music/main.py b/cogs/music/main.py index af91194..41fe26d 100644 --- a/cogs/music/main.py +++ b/cogs/music/main.py @@ -11,6 +11,11 @@ import yt_dlp from cogs.music.help import music_help +ydl_opts = { + 'format': 'bestaudio/best', + 'outtmpl': 'downloads/%(title)s.%(ext)s', +} + class music(commands.Cog): def __init__(self, client): self.client = client @@ -22,6 +27,7 @@ class music(commands.Cog): help_command.cog = self self.help_command = help_command + @commands.command( help="Displays latency from the bot", aliases=['delay']) @@ -49,6 +55,7 @@ class music(commands.Cog): await util.leave_vc(ctx) await ctx.message.add_reaction('👍') + @commands.command( help="Queues a song into the bot", aliases=['p', 'qeue', 'q']) @@ -56,12 +63,9 @@ class music(commands.Cog): if url is None: raise commands.CommandError("Must provide a link or search query") + await util.join_vc(ctx) - ydl_opts = { - 'format': 'bestaudio/best', - 'outtmpl': 'downloads/%(title)s.%(ext)s', - } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url, download=True) @@ -69,5 +73,6 @@ class music(commands.Cog): ctx.voice_client.play(discord.FFmpegPCMAudio(executable="ffmpeg", source=filename), after=self.test) + def test(self, error): print("Hello") diff --git a/cogs/music/translate.py b/cogs/music/translate.py new file mode 100644 index 0000000..1d2b37f --- /dev/null +++ b/cogs/music/translate.py @@ -0,0 +1,50 @@ +# Handles translating urls and search terms + +def main(url): + + url = url.lower() + + # Check if link or search + if url.startswith("https://") is False: + return search_song(url) + + #TODO add better regex or something + if 'spotify' in url: + if 'track' in url: + return spotify_song(url) + elif 'playlist' in url: + return spotify_playlist(url) + + soundcloud_song = 'soundcloud' in url and 'sets' not in url + soundcloud_playlist = 'soundcloud' in url and 'sets' in url + + youtube_song = 'watch?v=' in url or 'youtu.be/' in url + youtube_playlist = 'playlist?list=' in url + + if soundcloud_song or youtube_song: + return song_download(url) + + if youtube_playlist: + return playlist_download(url) + + return False + + +def search_song(search): + return None + + +def spotify_song(url): + return None + + +def spotify_playlist(url): + return None + + +def song_download(url): + return None + + +def playlist_download(url): + return None