(主机操作系统是OS X 10.10,Python版本是2.7.6)
我在Python程序中有一个函数,它使用youtube-dl获取YouTube视频的直接视频网址。
mpv_executable = find_executable("mpv")
if mpv_executable is None:
raise RuntimeError('mpv not found')
get_api_url = subprocess.Popen(['/usr/local/bin/youtube-dl', '-g', url], stdout = subprocess.PIPE)
ytapi_url,ec = get_api_url.communicate()
print(ytapi_url)
player = subprocess.Popen([mpv_executable, '--really-quiet', ytapi_url], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
player.wait()
如果我从倒数第二行删除stdout / stderr部分,我可以看到mpv无法播放视频:
但是,如果我复制URL mpv尝试播放,然后在shell中执行以下操作(pbpaste输出剪贴板的内容,如果您不知道OS X特定的shell实用程序):
$ mpv“$(pbpaste)”
mpv播放视频没有任何问题。