如何在 Windows 10 上从 Python 中的 Youtube URL 流式传输音频(无需下载)?
How to stream audio from a Youtube URL in Python (without download) on Windows 10?
我正在尝试在 Windows 10 上使用 Python 流式传输 YouTube 音频。我发现了一个 Whosebug 问题,它询问 ;但在使用 Windows 时会进入死胡同。
如果我在 Windows 上使用 Python 2.7(32 位)使用下面的脚本,我会得到错误:"WindowsError: [Error 126] The specified module could not be found"。
我愿意接受任何不涉及启动庞大的 GUI 应用程序(例如 Web 浏览器)的解决方案。我正在寻找一个非常轻量级的音频播放器(以及相应的 Python 代码)来从 URL 播放 YouTube 音频。下面的脚本 "should" 有效,但在 Windows.
上无效
import pafy
import vlc
import time
url = "https://www.youtube.com/watch?v=PK5vAr5u6Xo"
video = pafy.new(url)
best = video.getbest()
playurl = best.url
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new(playurl)
Media.get_mrl()
player.set_media(Media)
duration = player.get_length() / 1000
player.play()
time.sleep(duration)
我必须安装正常的 Windows VLC 应用程序才能使用 VLC 模块。 Python VLC 模块没有安装播放所需的依赖项。
我正在尝试在 Windows 10 上使用 Python 流式传输 YouTube 音频。我发现了一个 Whosebug 问题,它询问
如果我在 Windows 上使用 Python 2.7(32 位)使用下面的脚本,我会得到错误:"WindowsError: [Error 126] The specified module could not be found"。
我愿意接受任何不涉及启动庞大的 GUI 应用程序(例如 Web 浏览器)的解决方案。我正在寻找一个非常轻量级的音频播放器(以及相应的 Python 代码)来从 URL 播放 YouTube 音频。下面的脚本 "should" 有效,但在 Windows.
上无效import pafy
import vlc
import time
url = "https://www.youtube.com/watch?v=PK5vAr5u6Xo"
video = pafy.new(url)
best = video.getbest()
playurl = best.url
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new(playurl)
Media.get_mrl()
player.set_media(Media)
duration = player.get_length() / 1000
player.play()
time.sleep(duration)
我必须安装正常的 Windows VLC 应用程序才能使用 VLC 模块。 Python VLC 模块没有安装播放所需的依赖项。