protocol-buffers - how to use pssh python script using Python ProtoBuf library?
问题描述
I am not able to figure out how Python ProtoBuf library is related to use pssh python script in this documentation https://github.com/google/shaka-packager/tree/master/packager/tools/pssh
How can I build the pssh.py script without the proto file?
解决方案
您可以将构建脚本与 shaka-packager 一起使用,也可以直接从widevine 头 proto 文件生成 python protobuf 文件。
Python的 Protocol Buffers教程很好地描述了如何使用 protoc 编译必要的 Python 代码。
如果您不想要或不需要任何其他 shaka-packager 的东西,而只想使用 pssh.py,那么您可以修改这部分:
# Append the local protobuf location. Use a path relative to the tools/pssh
# folder where this file should be found. This allows the file to be executed
# from any directory.
_pssh_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(_pssh_dir, '../../third_party/protobuf/python'))
# Import the widevine protobuf. Use either Release or Debug.
_proto_path_format = os.path.join(
_pssh_dir, '../../../out/%s/pyproto/packager/media/base')
if os.path.isdir(_proto_path_format % 'Release'):
sys.path.insert(0, _proto_path_format % 'Release')
else:
sys.path.insert(0, _proto_path_format % 'Debug')
try:
import widevine_pssh_data_pb2 # pylint: disable=g-import-not-at-top
except ImportError:
print >> sys.stderr, 'Cannot find proto file, make sure to build first'
raise
只需保留import widevine_pssh_data_pb2
并确保您使用 protoc 生成的代码位于 pssh.py 文件的路径中。然后它应该工作得很好。
你打算用 pssh.py 做什么?
推荐阅读
- c# - 为什么 HttpClient.GetAsync() 缺少部分内容?
- audio - 通过代码创建简单的声音,例如 8 位
- css - 降低 Woocommerce Storefront 主题页脚高度
- jenkins - 带有詹金斯作业参数的 Slack Slash 命令
- javascript - 使用 Javascript 将日期验证为必填字段
- reactjs - 在 React 中,是否可以只覆盖 HTML 模板,而不是整个类?
- forms - VueJS v-model 动态输入表单
- php - 如何在 React Native 中通过上传图像获取数据到 php 服务器
- python-3.x - Python 控制台要求在 PyCharm (Python 3.x) 中导入 sys
- symlink - 删除和重新创建文件时的 Linux 符号链接