我在 python 中使用 youtube-dl 作为 discord bot,它工作正常,但是它将文件下载到项目的根目录。由于它将下载大量视频,我希望它下载到根目录内。我该怎么做呢?
这些是我目前的选择:
ytdl_format_options = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'reactrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
'source_addreacs': '0.0.0.0', # bind to ipv4 since ipv6 addreacses cause issues sometimes
'output': r'youtube-dl'
}
ffmpeg_options = {
'before_options': '-nostdin',
'options': '-vn'
}
最佳答案
在 outtmpl
option 中设置包含斜杠的输出模板:
ytdl_format_options = {
'outtmpl': 'somewhere/%(extractor_key)s/%(extractor)s-%(id)s-%(title)s.%(ext)s',
...
}
输出模板可以有很多字段(包括播放列表 ID、许可证、格式名称/比特率、专辑名称等等,具体取决于您使用的视频网站支持的内容)。如需更多信息,请参阅 youtube-dl documentation of output templates .所有字段都可以用作目录或文件名。
关于python-3.x - 为 youtube-dl python 选择下载位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51663637/