mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-20 02:26:32 +01:00
Embed yt_dl
This commit is contained in:
parent
0215986e54
commit
a2ccb56316
1 changed files with 32 additions and 12 deletions
|
@ -752,6 +752,7 @@ class OtherCog(commands.Cog):
|
||||||
upload_log: bool = True
|
upload_log: bool = True
|
||||||
):
|
):
|
||||||
"""Downloads a video from <URL> using youtube-dl"""
|
"""Downloads a video from <URL> using youtube-dl"""
|
||||||
|
await ctx.defer()
|
||||||
with tempfile.TemporaryDirectory(prefix="jimmy-ytdl-") as tempdir:
|
with tempfile.TemporaryDirectory(prefix="jimmy-ytdl-") as tempdir:
|
||||||
video_format = video_format.lower()
|
video_format = video_format.lower()
|
||||||
OUTPUT_FILE = str(Path(tempdir) / f"{ctx.user.id}.%(ext)s")
|
OUTPUT_FILE = str(Path(tempdir) / f"{ctx.user.id}.%(ext)s")
|
||||||
|
@ -770,8 +771,15 @@ class OtherCog(commands.Cog):
|
||||||
else:
|
else:
|
||||||
options.extend(["--format", f"(bv*+ba/b/ba)[filesize<={MAX_SIZE}M]"])
|
options.extend(["--format", f"(bv*+ba/b/ba)[filesize<={MAX_SIZE}M]"])
|
||||||
|
|
||||||
await ctx.defer()
|
await ctx.edit(
|
||||||
await ctx.edit(content="Downloading video...")
|
embed=discord.Embed(
|
||||||
|
description="\u200b"
|
||||||
|
).set_author(
|
||||||
|
name="Downloading...",
|
||||||
|
icon_url="https://cdn.discordapp.com/emojis/1101463077586735174.gif?v=1",
|
||||||
|
url=url
|
||||||
|
)
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
venv = Path.cwd() / "venv" / ("Scripts" if os.name == "nt" else "bin")
|
venv = Path.cwd() / "venv" / ("Scripts" if os.name == "nt" else "bin")
|
||||||
if venv:
|
if venv:
|
||||||
|
@ -786,14 +794,20 @@ class OtherCog(commands.Cog):
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
)
|
)
|
||||||
stdout, stderr = await process.communicate()
|
async with ctx.channel.typing():
|
||||||
stdout_log = io.BytesIO(stdout)
|
stdout, stderr = await process.communicate()
|
||||||
stdout_log_file = discord.File(stdout_log, filename="stdout.txt")
|
stdout_log = io.BytesIO(stdout)
|
||||||
stderr_log = io.BytesIO(stderr)
|
stdout_log_file = discord.File(stdout_log, filename="stdout.txt")
|
||||||
stderr_log_file = discord.File(stderr_log, filename="stderr.txt")
|
stderr_log = io.BytesIO(stderr)
|
||||||
await process.wait()
|
stderr_log_file = discord.File(stderr_log, filename="stderr.txt")
|
||||||
|
await process.wait()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return await ctx.edit(content="Downloader not found.")
|
return await ctx.edit(
|
||||||
|
embed=discord.Embed(
|
||||||
|
description="Downloader not found.",
|
||||||
|
color=discord.Color.red()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
files = [
|
files = [
|
||||||
|
@ -822,7 +836,7 @@ class OtherCog(commands.Cog):
|
||||||
"\t- Resolution: {0[resolution]}\n"
|
"\t- Resolution: {0[resolution]}\n"
|
||||||
"\t- Size: {1!s}MB".format(fmt, fs)
|
"\t- Size: {1!s}MB".format(fmt, fs)
|
||||||
)
|
)
|
||||||
await ctx.edit(content="Invalid format. Available formats:")
|
await ctx.edit(content="Invalid format. Available formats:", embed=None)
|
||||||
for page in paginator.pages:
|
for page in paginator.pages:
|
||||||
await ctx.send(page)
|
await ctx.send(page)
|
||||||
return await ctx.send(files=files)
|
return await ctx.send(files=files)
|
||||||
|
@ -848,8 +862,14 @@ class OtherCog(commands.Cog):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not files:
|
if not files:
|
||||||
return await ctx.edit(content="No files found.")
|
return await ctx.edit(embed=discord.Embed(description="No files found.", color=discord.Colour.red()))
|
||||||
await ctx.edit(content="Here's your video!", files=files)
|
await ctx.edit(
|
||||||
|
embed=discord.Embed(
|
||||||
|
title="Here's your video!",
|
||||||
|
color=discord.Colour.green()
|
||||||
|
),
|
||||||
|
files=files
|
||||||
|
)
|
||||||
|
|
||||||
@commands.slash_command(name="text-to-mp3")
|
@commands.slash_command(name="text-to-mp3")
|
||||||
@commands.cooldown(5, 600, commands.BucketType.user)
|
@commands.cooldown(5, 600, commands.BucketType.user)
|
||||||
|
|
Loading…
Reference in a new issue