为 youtube-dl 选择下载位置 python

Choosing download location for youtube-dl python

我在 python 中将 youtube-dl 用于 discord 机器人,它工作正常,但它会将文件下载到项目的根目录。因为它会下载很多视频,所以我更愿意将它下载到根目录中。我该怎么做?

这些是我当前的选择:

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、许可证、格式 name/bitrates、专辑名称等等,具体取决于您的视频网站重新使用支撑)。有关详细信息,请参阅 youtube-dl documentation of output templates。所有字段都可以用作目录或文件名。