protocol-buffersdrmwidevineshakaeme

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?


Solution

  • You can either use the build-script with the shaka-packager, or you can simply generate the python protobuf files from the widevine header proto file directly.

    The Protocol Buffers tutorial for python describes nicely how to use protoc to compile the necessary python code.

    If you don't want or need any of the other shaka-packager stuff, but just want to use the pssh.py, then you can just modify this part:

    # 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
    

    Just keep import widevine_pssh_data_pb2 and make sure that the code you generated with protoc is in the path of the pssh.py file. Then it should work nicely.

    What are you planning to use the pssh.py for?