import youtube_dl
def my_hook(d,`some parameter`):
...
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download("link" , 'some parameter')
如何将
some parameter
传递给 my_hook
函数?我想将套接字对象传递给 my_hook
函数,以向另一台机器报告最新的下载进度。怎么才能通过呢?
#! /usr/bin/env python3
import youtube_dl
def progress_hook( response ):
## send response['status'] to whatever subprocess you have going on.
print( response['status'] )
ydl_opts = {
'progress_hooks': [progress_hook],
## other options, resolution & whatnot
}
link = 'm.youtube.com/watch?v=dQw4w9WgXcQ'
with youtube_dl .YoutubeDL( ydl_opts ) as ydl:
## metadata = ydl .extract_info( link, download=False )
## print( metadata )
ydl .download( [link, ydl_opts] )
导入 youtube_dl defwrapper_hook(custom_param): def my_hook(d,
some parameter
):
...
将 youtube_dl.YoutubeDL(ydl_opts) 用作 ydl:
ydl.download("链接" , '某个参数')