python subprocess.Popen:mpv无法播放视频网址,在shell中运行

时间:2014-08-13 04:23:39

标签: python python-2.7 video youtube-api

(主机操作系统是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无法播放视频:

  

无法打开https://r19---sn-npo7ene7.googlevideo.com/[...]

但是,如果我复制URL mpv尝试播放,然后在shell中执行以下操作(pbpaste输出剪贴板的内容,如果您不知道OS X特定的shell实用程序):

  

$ mpv“$(pbpaste)”

mpv播放视频没有任何问题。

0 个答案:

没有答案