I'm trying to build a discord music bot and am using youtube_dl for downloading the songs. I want to save them in a directory so I won't have to download them again every time. But I want to change the songs name in the directory.
I know that I'll have to change something in the outtmpl but this is just giving me the youtube name of the song:
ydl_opts = {
'outtmpl': f'./project/audio/%(title)s.%(ext)s', #Output directory
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
When I replaced the outtmpl with: 'outtmpl': f'./project/audio/{songname}',
it gave me the error message:
DownloadError: ERROR: audio conversion failed: file:mp3: Invalid argument