Streaming audio (YouTube)(流媒体音频 (YouTube))
问题描述
我正在为音乐媒体平台编写 CLI.其中一项功能是您可以直接从 CLI 播放 YouTube 视频.我真的不知道该怎么做,但这听起来最合理:
I'm writing a CLI for a music-media-platform. One of the features is going to be that you can directly play YouTube videos from the CLI. I don't really have an idea of how to do it, but this one sounded the most reasonable:
我将使用那些可以从 YouTube 下载音乐的网站,例如 http://keepvid.com/
然后我直接流式传输并播放它,但我有一个问题.有没有能够做到这一点的 Python 库,如果有,你有什么具体的例子吗?
I'm going to use of those sites where you can download music from YouTube, for example, http://keepvid.com/
and then I directly stream and play this, but I have one problem. Is there any Python library capable of doing this and if so, do you have any concrete examples?
我一直在寻找,但我什么也没找到,即使使用 GStreamer 也没有找到.
I've been looking, but I found nothing, even not with GStreamer.
推荐答案
你需要两个东西才能下载一个 YouTube 视频,视频 ID,由 v=
部分表示URL,以及存在于页面来源.我不知道这个 t
值是什么,但它是你需要的 :)
You need two things to be able to download a YouTube video, the video id, which is represented by the v=
section of the URL, and a hidden field t=
which is present in the page source. I have no idea what this t
value is, but it's what you need :)
然后您可以使用格式中的 URL 下载视频;
You can then download the video using a URL in the format;
http://www.youtube.com/get_video?video_id=*******&t=*******
星星代表获得的值.
我猜您可以从用户输入中询问视频 ID,因为它很容易获得.然后,您的程序将下载该视频的 HTML 源代码,解析 的源代码t
值,然后使用新构建的 URL 下载视频.
I'm guessing you can ask for the video id from user input, as it's straightforward to obtain. Your program would then download the HTML source for that video, parse the source for the t
value, then download the video using the newly constructed URL.
例如,如果您在浏览器中打开此链接,它应该会下载视频,或者您可以使用诸如 Wget;
For example, if you open this link in your browser, it should download the video, or you can use a downloading program such as Wget;
http://www.video?com/get_video_id=3HrSN7176XI&t=vjVQa1PpcFNM4c8MbEhsnGaNvYKoYERIJ-hK7ErLpUI=
这篇关于流媒体音频 (YouTube)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:流媒体音频 (YouTube)


基础教程推荐
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01