擅长:python、mysql、java
<p>你应该把它放在<code>ydl_opts</code>里面:</p>
<pre class="lang-py prettyprint-override"><code>ydl_opts = {
'outtmpl': os.path.join(download_path, '%(title)s-%(id)s.%(ext)s'),
}
</code></pre>
<p>在你的例子中,<code>download_path</code>应该是<code>'C:/Users/Desktop'</code>。如果您喜欢不带视频ID的文件名,请使用<code>%(title)s.%(ext)s</code>,而不是<code>%(title)s-%(id)s.%(ext)s</code></p>
<p>或者在开始下载之前,只需<code>os.chdir(path)</code>将目录更改为您希望下载的位置。</p>
<pre class="lang-py prettyprint-override"><code>from __future__ import unicode_literals
import youtube_dl
import os
ydl_opts = {}
os.chdir('C:/Users/Desktop')
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=n06H7OcPd-g'])
</code></pre>