feat: improved how title detection works (if I could actually get it fundamentally working)
This commit is contained in:
parent
a646bf129e
commit
b9d18c53e7
1 changed files with 8 additions and 7 deletions
|
@ -57,7 +57,9 @@ class MusicDownloader(commands.Cog):
|
||||||
with YoutubeDL(ydl_opts) as ydl:
|
with YoutubeDL(ydl_opts) as ydl:
|
||||||
info = ydl.extract_info(url=url, download=True)
|
info = ydl.extract_info(url=url, download=True)
|
||||||
title = info['title']
|
title = info['title']
|
||||||
return title
|
id = info['id']
|
||||||
|
filename = title + f' [{id}.m4a]'
|
||||||
|
return filename
|
||||||
data_path = await self.config.save_directory()
|
data_path = await self.config.save_directory()
|
||||||
if subfolder:
|
if subfolder:
|
||||||
data_path = os.path.join(data_path, subfolder)
|
data_path = os.path.join(data_path, subfolder)
|
||||||
|
@ -88,9 +90,8 @@ class MusicDownloader(commands.Cog):
|
||||||
else:
|
else:
|
||||||
msg = ctx.send
|
msg = ctx.send
|
||||||
message = await msg("YouTube Downloader started!")
|
message = await msg("YouTube Downloader started!")
|
||||||
title = youtube_download(self, url, data_path, message)
|
filename = youtube_download(self, url, data_path, message)
|
||||||
matching_files = [file for file in os.listdir(data_path) if file.startswith(title)]
|
full_filename = os.path.join(data_path, filename)
|
||||||
if len(matching_files) == 1:
|
if os.path.isfile(full_filename):
|
||||||
full_filename = os.path.join(data_path, matching_files[0])
|
with open(full_filename, 'rb') as file:
|
||||||
with open(full_filename, 'r') as file:
|
await ctx.send(content="Downloaded file:", file=discord.File(file, {filename}))
|
||||||
await ctx.send(content="Downloaded file:", file=discord.File(file, f'{title}.m4a'))
|
|
||||||
|
|
Loading…
Reference in a new issue