pywinrt / python-winsdk

Python package with bindings for Windows SDK
https://python-winsdk.readthedocs.io
MIT License
77 stars 8 forks source link

PlayReady sample C# to Python #19

Open hyugogirubato opened 1 year ago

hyugogirubato commented 1 year ago

Hey dev, I wanted to reproduce the example of the use of the playready library provided by Microsoft in C# in python based on your library in order to be able to use the uwp api specific to windows. The C# application works fine but I get errors with python.

I have below the python code used in order to use the video tests but does not work.

import uuid
from winsdk.windows.media.protection.playready import *
from winsdk.windows.foundation import Uri
# from winsdk.windows.foundation import IAsyncAction

# https://github.com/pywinrt/python-winsdk
# https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/winrt/Windows.Media.Protection.PlayReadyErrors.h

keyId = '{6F651AE1-DBE4-4434-BCB4-690D1564C41C}'
moviePath = 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)'
licenseUrl = 'http://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&SecurityLevel=2000&MaxResDecode=1920x1080'

# @PlayReadyHelpers.ReactiveLicenseAcquisition
def ReactiveLicenseAcquisition(laRequest):
    # args = IAsyncAction
    laRequest.begin_service_request()  # ERROR: object needs an argument
    print('ReactiveLicenseAcquisition::Complete')

# @PlayReadyHelpers.ProactiveLicenseAcquisition
def ProactiveLicenseAcquisition(contentHeader):
    laRequest = PlayReadyLicenseAcquisitionServiceRequest
    laRequest.content_header = contentHeader
    ReactiveLicenseAcquisition(laRequest)

# @ProactiveViewModel.GetLicense
def GetLicense(kid):
    laURL = licenseUrl
    customData = 'token:12345'
    contentHeader = PlayReadyContentHeader(
        uuid.UUID(kid),
        '',
        PlayReadyEncryptionAlgorithm.AES128_CTR,
        Uri(laURL),
        Uri(laURL),
        customData,
        uuid.UUID(int=0)
    )  # ERROR: 0x8004b8ce --> HWDRM is present on the system but is not supported.
    ProactiveLicenseAcquisition(contentHeader)

if __name__ == '__main__':
    # Proactive License Request
    GetLicense(keyId)

Do you have an idea for a fix?

Microsoft Sample Application: https://learn.microsoft.com/en-us/samples/microsoft/windows-universal-samples/playready/