获取Twitch VOD MPEG-2流信息
twitchvod的Python项目详细描述
Twitchvod(v0.1.1)
安装
pip install twitchvod
兼容性
此软件包与python3兼容。目前不支持python2。
>= python 3.5.2
请注意,使用此库的风险由您自己承担。使用未记录的api接口是违反twitch服务条款的。如果你的开发者令牌 但是,如果您想了解这个库是如何工作的,请随意阅读源代码。
好吧,现在来看看更有趣的东西。
此api客户端将使用您提供的twitch developer client_id发出多个请求,以twitch api端点获取与特定vod相关的信息。您甚至可以查询所有的mpeg-2传输流文件,您可以下载到任何您想要的。在这个例子中,假设您想下载vod 372739399。
>>> from twitchvod import Client
# Create client...
>>> client = Client("TWITCH-DEV-APP-CLIENT-ID")
>>> client
<Client>
# Generate access token for VOD 372739399...
>>> token = client.get_access_token(372739399)
>>> token
<AccessToken [372739399-vod_id]>
# Fetch the different vod qualities w/ token...
>>> vods = client.get_vods(token)
>>> vods
[
<Vod [chunked,1920x1080]>,
<Vod [720p60,1280x720]>,
<Vod [720p30,1280x720]>,
<Vod [480p30,852x480]>,
<Vod [audio_only]>,
<Vod [360p30,640x360]>,
<Vod [160p30,284x160]>
]
# Get VOD chunks... There are 364 of them...
>>> vod_chunk = client.get_chunks(vods[0])
>>> vod_chunk
<VodChunk [364-chunks]>
# Get the MPEG-2 transport stream files... Boom!
>>> mpeg2_ts_chunks = [c for c in vod_chunks.chunks()]
>>> mpeg2_ts_chunks[:3]
[
('1988.ts', 'https://vod-metro.twitch.tv/.../chunked/1988.ts'),
('1989.ts', 'https://vod-metro.twitch.tv/.../chunked/1989.ts'),
('1990.ts', 'https://vod-metro.twitch.tv/.../chunked/1990.ts')
]
开发环境/设置
这个包是早期开发的,因此如果有人有任何问题或疑虑,您可以提出公关或Github回购问题。
- git克隆了上面的repo。
git clone git@github.com:nomadmtb/twitchvod.git
- 进入项目。
cd twitchvod
- 创建virtualenv(假设您有3.7)
python3.7 -m venv .env
- 激活virtualenv。
source .env/bin/activate
- 安装开发要求。
pip install -r requirements.txt
通过上述设置,您可以执行以下操作开始。
- 运行unittests w/pytest。
make test
- 运行unittests w/coverage+pytest。
make coverage
- 安装包的本地副本。
python setup.py install
- 删除包的本地副本。
pip uninstall twitchvod