If you’re working with PlayReady DRM-protected content, the PyPlayReady library makes it easy to fetch and manage keys securely. Below is an example to guide you through the process, along with details on how to set up and run the script.
Installing PyPlayReady
First, ensure you have the library installed. You can do this with pip:
pip install pyplayready
Using the Script
Here’s a complete example of using PyPlayReady to retrieve PlayReady keys:
from pyplayready.cdm import Cdm
from pyplayready.device import Device
from pyplayready.system.pssh import PSSH
import requests
# Load your PRD device file
device = Device.load("C:/Path/To/A/Device.prd") # Replace with your device file path
cdm = Cdm.from_device(device)
session_id = cdm.open()
# Provide the PSSH string
pssh = PSSH(
"AAADfHBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAA1xcAwAAAQABAFIDPABXAFIATQBIAEUA..."
)
# Extract WRM headers from the PSSH
wrm_headers = pssh.get_wrm_headers()
request = cdm.get_license_challenge(session_id, wrm_headers[0])
# Make the license request
response = requests.post(
url="https://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:2000)",
headers={
'Content-Type': 'text/xml; charset=UTF-8',
},
data=request,
)
# Parse the license and retrieve keys
cdm.parse_license(session_id, response.text)
for key in cdm.get_keys(session_id):
print(f"{key.key_id.hex}:{key.key.hex()}")
# Close the session
cdm.close(session_id)
Notes on Device Files (PRD)
The .prd device file is required for this script to work.
If you don’t have a .prd file or need assistance setting one up, contact the admin for guidance.
How It Works
Device Setup: Load a .prd device file, which acts as a virtual PlayReady device.
Session Creation: Open a PlayReady session using the Cdm class.
License Challenge: Extract WRM headers and create a license request.
License Retrieval: Submit the request to the license server to fetch keys.
Key Management: Parse the license and print the content keys.