try chatgpts solution
This commit is contained in:
parent
c1d815e7d5
commit
d9968bd500
1 changed files with 24 additions and 6 deletions
30
cogs/ytdl.py
30
cogs/ytdl.py
|
|
@ -15,13 +15,31 @@ class YoutubeDL(BotBaseCog):
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def youtubedl(self, ctx):
|
async def youtubedl(self, ctx):
|
||||||
try:
|
try:
|
||||||
url = ctx.message.content.split(" ")[1]
|
# Expecting the command format to be !youtubedl <url> <video|audio>
|
||||||
url = '"' + url + '"'
|
parts = ctx.message.content.split(" ")
|
||||||
video_or_audio = ctx.message.content.split(" ")[2]
|
if len(parts) < 3:
|
||||||
process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio], cwd="data/ytdl", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
await ctx.send("Usage: !youtubedl <url> <video|audio>")
|
||||||
process.wait()
|
return
|
||||||
await ctx.send(f"std out: {process.stdout.read()}, std err: {process.stderr.read()}")
|
|
||||||
|
url = parts[1]
|
||||||
|
video_or_audio = parts[2]
|
||||||
|
|
||||||
|
# Run the subprocess
|
||||||
|
process = subprocess.Popen(
|
||||||
|
["python3", "youtubedl.py", url, video_or_audio],
|
||||||
|
cwd="data/ytdl",
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE
|
||||||
|
)
|
||||||
|
|
||||||
|
# Wait for the process to complete and read the output
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
|
||||||
|
# Send the output back to the user
|
||||||
|
await ctx.send(f"std out: {stdout.decode('utf-8')}") if stdout else await ctx.send("No stdout output")
|
||||||
|
await ctx.send(f"std err: {stderr.decode('utf-8')}") if stderr else await ctx.send("No stderr output")
|
||||||
await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True)
|
await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.send(f"Error: {e}")
|
await ctx.send(f"Error: {e}")
|
||||||
await ctx.send("Usage: !youtubedl <url> <video|audio>")
|
await ctx.send("Usage: !youtubedl <url> <video|audio>")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue