From 7c826624a2e2e40e2827a6c087c12037503e9e57 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Sat, 10 Sep 2022 20:12:38 +0100 Subject: [PATCH] docs: Add a minimal example --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/README.md b/README.md index 2ffb383..7cdcfba 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,59 @@ See [Poetry's Docs] on various ways of making calls under the virtual-environmen [Poetry]: [Poetry's Docs]: +## 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