This commit is contained in:
BarsTiger
2021-04-16 14:59:03 +03:00
parent 858e0be4ba
commit b8bc669658

50
main.py
View File

@@ -24,6 +24,14 @@ ffmpeg_options = {
'options': '-vn'
}
ffmpeg_super_bass_options = {
'options': '-af "equalizer=f=160:width_type=o:width=1:g=10, equalizer=f=30:width_type=o:width=1:g=5, equalizer=f=50:width_type=o:width=1:g=5"'
}
ffmpeg_bass_options = {
'options': '-af "equalizer=f=160:width_type=o:width=1:g=10, equalizer=f=30:width_type=o:width=1:g=3, equalizer=f=50:width_type=o:width=1:g=3"'
}
ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
@@ -48,6 +56,30 @@ class YTDLSource(discord.PCMVolumeTransformer):
filename = data['url'] if stream else ytdl.prepare_filename(data)
return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)
@classmethod
async def bass_from_url(cls, url, *, loop=None, stream=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
if 'entries' in data:
# take first item from a playlist
data = data['entries'][0]
filename = data['url'] if stream else ytdl.prepare_filename(data)
return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_bass_options), data=data)
@classmethod
async def superbass_from_url(cls, url, *, loop=None, stream=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
if 'entries' in data:
# take first item from a playlist
data = data['entries'][0]
filename = data['url'] if stream else ytdl.prepare_filename(data)
return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_super_bass_options), data=data)
class Music(commands.Cog):
def __init__(self, bot):
@@ -67,6 +99,22 @@ class Music(commands.Cog):
await ctx.send('Now playing: {}'.format(player.title))
@commands.command()
async def bassboost(self, ctx, *, url):
async with ctx.typing():
player = await YTDLSource.bass_from_url(url, loop=self.bot.loop, stream=True)
ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send('Now playing: {}'.format(player.title))
@commands.command()
async def superbass(self, ctx, *, url):
async with ctx.typing():
player = await YTDLSource.superbass_from_url(url, loop=self.bot.loop, stream=True)
ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send('Now playing: {}'.format(player.title))
@commands.command()
async def volume(self, ctx, volume: int):
"""Changes the player's volume"""
@@ -84,6 +132,8 @@ class Music(commands.Cog):
await ctx.voice_client.disconnect()
@play.before_invoke
@bassboost.before_invoke
@superbass.before_invoke
async def ensure_voice(self, ctx):
if ctx.voice_client is None:
if ctx.author.voice: