From b815f96c2e2b3aa2651ce038c3f57d2c75f86ad1 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 24 Jan 2024 21:17:37 +0000 Subject: [PATCH 1/9] Fix audio-only downloads --- src/cogs/ytdl.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index 94d2247..629bb00 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -341,8 +341,23 @@ class YTDLCog(commands.Cog): delete_after=120, ) try: - file = next(temp_dir.glob("*." + extracted_info["ext"])) + if audio_only is False: + file = next(temp_dir.glob("*." + extracted_info["ext"])) + else: + # can be .opus, .m4a, .mp3, .ogg, .oga + for _file in temp_dir.iterdir(): + if _file.suffix in (".opus", ".m4a", ".mp3", ".ogg", ".oga", ".aac", ".wav"): + file = _file + break + else: + raise StopIteration except StopIteration: + self.log.warning( + "Failed to locate downloaded file. Was supposed to be looking for a file extension of " + "%r amongst files %r, however none were found.", + extracted_info["ext"], + list(map(str, temp_dir.iterdir())) + ) return await ctx.edit( embed=discord.Embed( title="Error", @@ -381,7 +396,7 @@ class YTDLCog(commands.Cog): "-movflags", "faststart", "-b:a", - "48k", + "64k", "-y", "-strict", "2", From 7d87628ea249feb9f4e49f1a442ef56a831d2b3e Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 24 Jan 2024 21:21:17 +0000 Subject: [PATCH 2/9] Improve audio only downloads --- src/cogs/ytdl.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index 629bb00..b383293 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -155,6 +155,36 @@ class YTDLCog(commands.Cog): except IndexError: self.log.debug("Attachment index %d is out of range (%r)", attachment_index, message.attachments) return + + def convert_to_m4a(self, file: Path) -> Path: + """ + Converts a file to m4a format. + :param file: The file to convert + :return: The converted file + """ + new_file = file.with_suffix(".m4a") + args = [ + "-vn", + "-sn", + "-i", + str(file), + "-c:a", + "aac", + "-b:a", + "64k", + "-movflags", + "faststart", + "-y", + str(new_file) + ] + process = subprocess.run( + ["ffmpeg", *args], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + if process.returncode != 0: + raise RuntimeError(process.stderr.decode()) + return new_file @commands.slash_command(name="yt-dl") @commands.max_concurrency(1, wait=False) @@ -428,6 +458,10 @@ class YTDLCog(commands.Cog): ) ) file = new_file + + if audio_only and file.suffix != ".m4a": + self.log.info("Converting %r to m4a.", file) + file = await asyncio.to_thread(self.convert_to_m4a, file) stat = file.stat() size_bytes = stat.st_size From 5f662c1613e7a689108aa90360f1cd7892882b13 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 24 Jan 2024 21:23:10 +0000 Subject: [PATCH 3/9] Fix saving links after they've been deleted --- src/cogs/ytdl.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index b383293..74f7b69 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -106,6 +106,10 @@ class YTDLCog(commands.Cog): """ INSERT INTO downloads (key, message_id, channel_id, webpage_url, format_id, attachment_index) VALUES (?, ?, ?, ?, ?, ?) + ON CONFLICT (key) DO UPDATE SET + message_id=excluded.message_id, + channel_id=excluded.channel_id, + attachment_index=excluded.attachment_index """, (_hash, message.id, message.channel.id, webpage_url, format_id, attachment_index) ) From ddf559773b8bd45e3886138b7d24e0ff20b617ad Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 24 Jan 2024 21:24:01 +0000 Subject: [PATCH 4/9] Forgot to import subprocess --- src/cogs/ytdl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index 74f7b69..92ac0e7 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -4,6 +4,7 @@ import hashlib import logging import tempfile import textwrap +import subprocess import typing from pathlib import Path from urllib.parse import urlparse From dbbd0d53e8788a4da60b2b7b66361c3ab472e75e Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 24 Jan 2024 21:25:03 +0000 Subject: [PATCH 5/9] Improve audio quality (64k is still low) --- src/cogs/ytdl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index 92ac0e7..2c9c50b 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -176,7 +176,7 @@ class YTDLCog(commands.Cog): "-c:a", "aac", "-b:a", - "64k", + "96k", "-movflags", "faststart", "-y", @@ -431,7 +431,7 @@ class YTDLCog(commands.Cog): "-movflags", "faststart", "-b:a", - "64k", + "96k", "-y", "-strict", "2", From c0feda1ac7656268a6545be4365dcdd253ac4bb2 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Fri, 26 Jan 2024 19:05:23 +0000 Subject: [PATCH 6/9] Remove filesize hard limit --- src/cogs/ytdl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index 2c9c50b..d8f58bc 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -56,7 +56,7 @@ class YTDLCog(commands.Cog): "merge_output_format": "webm/mp4/mov/m4a/oga/ogg/mp3/mka/mkv", "source_address": "0.0.0.0", "concurrent_fragment_downloads": 4, - "max_filesize": (25 * 1024 * 1024) - 256 + # "max_filesize": (25 * 1024 * 1024) - 256 } self.colours = { "youtube.com": 0xff0000, From 87b95a81573abe876cc2d46ba02e4595c31d9162 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Fri, 26 Jan 2024 19:13:31 +0000 Subject: [PATCH 7/9] log ffmpeg commands --- src/cogs/ytdl.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index d8f58bc..3ff915a 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -182,6 +182,7 @@ class YTDLCog(commands.Cog): "-y", str(new_file) ] + self.log.debug("Running command: ffmpeg %s", " ".join(args)) process = subprocess.run( ["ffmpeg", *args], stdout=subprocess.PIPE, @@ -446,6 +447,7 @@ class YTDLCog(commands.Cog): timestamp=discord.utils.utcnow() ) ) + self.log.debug("Running command: ffmpeg %s", " ".join(args)) process = await asyncio.create_subprocess_exec( "ffmpeg", *args, From 502ca08bcd69705af62ae07a89d8fdb336af32a1 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Mon, 5 Feb 2024 15:15:20 +0000 Subject: [PATCH 8/9] Bring acid under control --- src/cogs/ollama.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cogs/ollama.py b/src/cogs/ollama.py index e088025..7e6de18 100644 --- a/src/cogs/ollama.py +++ b/src/cogs/ollama.py @@ -501,9 +501,10 @@ class Ollama(commands.Cog): params = {"seed": self.history.get_thread(context)["seed"]} if give_acid is True: - params["temperature"] = 500 - params["top_k"] = 500 - params["top_p"] = 500 + params["temperature"] = 2 + params["top_k"] = 0 + params["top_p"] = 2 + params["repeat_penalty"] = 2 payload = { "model": model, From 34a57af998149db7e9d0f9b00ad4c6ba96646861 Mon Sep 17 00:00:00 2001 From: nex Date: Tue, 6 Feb 2024 00:54:53 +0000 Subject: [PATCH 9/9] Properly avoid text overflow --- src/cogs/ollama.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cogs/ollama.py b/src/cogs/ollama.py index 7e6de18..7828bf9 100644 --- a/src/cogs/ollama.py +++ b/src/cogs/ollama.py @@ -534,8 +534,14 @@ class Ollama(commands.Cog): buffer.write(line["message"]["content"]) embed.description += line["message"]["content"] embed.timestamp = discord.utils.utcnow() - if len(embed.description) >= 4096: - embed.description = embed.description = "..." + line["message"]["content"] + if len(embed.description) >= 4000: + embed.description = "[...]" + line["message"]["content"] + if len(embed.description) >= 3250: + embed.colour = discord.Color.gold() + embed.set_footer(text="Warning: {:,}/4096 characters.".format(len(embed.description))) + else: + embed.colour = discord.Color.blurple() + embed.set_footer(text="Using server %r" % server, icon_url=server_config.get("icon_url")) if view.cancel.is_set(): break