From b9d18c53e7e2431b597d7e4aef0015cb568f5a49 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 1 Aug 2023 00:15:26 -0400 Subject: [PATCH] feat: improved how title detection works (if I could actually get it fundamentally working) --- musicdownloader/musicdownloader.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/musicdownloader/musicdownloader.py b/musicdownloader/musicdownloader.py index b968536..2218f53 100644 --- a/musicdownloader/musicdownloader.py +++ b/musicdownloader/musicdownloader.py @@ -57,7 +57,9 @@ class MusicDownloader(commands.Cog): with YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url=url, download=True) title = info['title'] - return title + id = info['id'] + filename = title + f' [{id}.m4a]' + return filename data_path = await self.config.save_directory() if subfolder: data_path = os.path.join(data_path, subfolder) @@ -88,9 +90,8 @@ class MusicDownloader(commands.Cog): else: msg = ctx.send message = await msg("YouTube Downloader started!") - title = youtube_download(self, url, data_path, message) - matching_files = [file for file in os.listdir(data_path) if file.startswith(title)] - if len(matching_files) == 1: - full_filename = os.path.join(data_path, matching_files[0]) - with open(full_filename, 'r') as file: - await ctx.send(content="Downloaded file:", file=discord.File(file, f'{title}.m4a')) + filename = youtube_download(self, url, data_path, message) + full_filename = os.path.join(data_path, filename) + if os.path.isfile(full_filename): + with open(full_filename, 'rb') as file: + await ctx.send(content="Downloaded file:", file=discord.File(file, {filename}))