Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
|
import yt_player
|
||||||
|
|
||||||
# this is a bot which posts the latest image post from ich_iel
|
# this is a bot which posts the latest image post from ich_iel
|
||||||
# the code probably sucks, but it works, so I don't care
|
# the code probably sucks, but it works, so I don't care
|
||||||
@@ -17,6 +18,7 @@ import random
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
prefix = os.getenv("COMMAND_PREFIX", "/")
|
prefix = os.getenv("COMMAND_PREFIX", "/")
|
||||||
bot = fluxer.Bot(command_prefix=prefix, intents=fluxer.Intents.GUILD_MESSAGES | fluxer.Intents.GUILDS | fluxer.Intents.MESSAGE_CONTENT)
|
bot = fluxer.Bot(command_prefix=prefix, intents=fluxer.Intents.GUILD_MESSAGES | fluxer.Intents.GUILDS | fluxer.Intents.MESSAGE_CONTENT)
|
||||||
|
yt_player.setup(bot)
|
||||||
|
|
||||||
task = None
|
task = None
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
fluxer.py
|
fluxer.py[voice]
|
||||||
requests
|
requests
|
||||||
asyncio
|
asyncio
|
||||||
dotenv
|
dotenv
|
||||||
aiohttp
|
aiohttp
|
||||||
|
yt-dlp
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# at this point this bot isn't just a reddit bot anymore, maybe i should start renaming it lol
|
||||||
|
import yt_dlp
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
AUDIO_DIR = "data/audio"
|
||||||
|
|
||||||
|
_bot = None
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
global _bot
|
||||||
|
_bot = bot
|
||||||
|
os.makedirs(AUDIO_DIR, exist_ok=True)
|
||||||
|
bot.command()(play)
|
||||||
|
|
||||||
|
async def play(ctx, channel_id: int, *, path: str):
|
||||||
|
channel = await _bot.fetch_channel(str(channel_id))
|
||||||
|
url = ctx.content[len("!play "):].strip()
|
||||||
|
logging.info(f"Playing {url}")
|
||||||
|
ydl_opts = {
|
||||||
|
'format': 'm4a/bestaudio/best',
|
||||||
|
'outtmpl': f'{AUDIO_DIR}/%(id)s.%(ext)s',
|
||||||
|
'postprocessors': [{ # Extract audio using ffmpeg
|
||||||
|
'key': 'FFmpegExtractAudio',
|
||||||
|
'preferredcodec': 'm4a',
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
info = ydl.extract_info(url, download=True)
|
||||||
|
filename = ydl.prepare_filename(info).rsplit('.', 1)[0] + '.m4a'
|
||||||
|
title = info.get('title', 'Unknown Title')
|
||||||
|
logging.info(f"Downloaded to {filename}")
|
||||||
|
|
||||||
|
ctx.send(f"Playing {title} in {channel.mention}")
|
||||||
|
|
||||||
|
async with await channel.connect(_bot) as vc:
|
||||||
|
await vc.play_file(filename)
|
||||||
Reference in New Issue
Block a user