如何将Socks5代理嵌入youtube-dl的python代码中?

it_*_*ure 1 proxy socks python-3.x youtube-dl

youtube-dl --proxy socks5://127.0.0.1:1080 $link -o $dir 可以在bash shell中的youtube嵌入式socks5代理上下载视频。
使用以下代码,我们将youtube-dl嵌入到python代码中。

from __future__ import unicode_literals
import youtube_dl
ydl_opts = {}
link = "some_youtube_url"
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([link])
Run Code Online (Sandbox Code Playgroud)

如何在Python代码中嵌入socks5代理?
我已经在https://github.com/rg3/youtube-dl上阅读了该文档 ,但仍然不知道如何在youtube-dl的python代码中添加socks5代理。

phi*_*hag 6

只需设置proxy选项:

ydl_opts = {
    'proxy': 'socks5://127.0.0.1:1080',
}
Run Code Online (Sandbox Code Playgroud)

并保持其余代码不变。