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
question from:
https://stackoverflow.com/questions/65829739/python-youtube-dl-change-output-name 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…