docs: Add a minimal example

This commit is contained in:
rlaphoenix 2022-09-10 20:12:38 +01:00
parent 3ef69deb29
commit 7c826624a2

View File

@ -55,6 +55,59 @@ See [Poetry's Docs] on various ways of making calls under the virtual-environmen
[Poetry]: <https://python-poetry.org>
[Poetry's Docs]: <https://python-poetry.org/docs/basic-usage/#using-your-virtual-environment>
## Usage
The following is a minimal example of using pywidevine in a script. It gets a License for Bitmovin's
Art of Motion Demo. There's various stuff not shown in this specific example like:
- Privacy Mode
- Setting Service Certificates
- Remote CDMs and Serving
- Choosing a License Type to request
- Creating WVD files
- and much more!
Just take a look around the Cdm code to see what stuff does. Everything is documented quite well.
There's also various functions in `main.py` that showcases a lot of features.
```py
from pywidevine.cdm import Cdm
from pywidevine.device import Device
from pywidevine.pssh import PSSH
import requests
# prepare pssh
pssh = PSSH("AAAAW3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAADsIARIQ62dqu8s0Xpa"
"7z2FmMPGj2hoNd2lkZXZpbmVfdGVzdCIQZmtqM2xqYVNkZmFsa3IzaioCSEQyAA==")
# load device
device = Device.load("C:/Path/To/A/Provision.wvd")
# load cdm
cdm = Cdm.from_device(device)
# open cdm session
session_id = cdm.open()
# get license challenge
challenge = cdm.get_license_challenge(session_id, pssh)
# send license challenge (assuming a generic license server SDK with no API front)
licence = requests.post("https://...", data=challenge)
licence.raise_for_status()
# parse license challenge
cdm.parse_license(session_id, licence.content)
# print keys
for key in cdm.get_keys(session_id):
print(f"[{key.type}] {key.kid.hex}:{key.key.hex()}")
# close session, disposes of session data
cdm.close(session_id)
```
## Troubleshooting
### Executable `pywidevine` was not found