devine-dl / pywidevine

Python implementation of Google's Widevine DRM CDM (Content Decryption Module)
GNU General Public License v3.0
537 stars 118 forks source link

How to convert `mspr:pro` to `cenc:pssh` #22

Closed Ukenn2112 closed 1 year ago

Ukenn2112 commented 1 year ago

I only found PlayReady's mspr:pro in the pmd file, how can I convert it to cenc:pssh?

<?xml version='1.0' ?>
<MPD mediaPresentationDuration='PT12M9.033S' minBufferTime='PT2.0S' profiles='urn:mpeg:dash:profile:isoff-on-demand:2011' type='static' xmlns='urn:mpeg:dash:schema:mpd:2011' xmlns:cenc='urn:mpeg:cenc:2013' xmlns:mspr='urn:microsoft:playready'>
<Period>
<AdaptationSet maxHeight='1080' maxWidth='1920' minHeight='1080' minWidth='1920' mimeType='video/mp4' segmentAlignment='true' startWithSAP='1'>
<Representation bandwidth='4848906' codecs='avc1.640028' frameRate='30' height='1080' id='video-avc1' scanType='progressive' width='1920'>
        <ContentProtection cenc:default_KID='c2bc9cc9-1376-400f-8bde-732b9cf519ba' schemeIdUri='urn:mpeg:dash:mp4protection:2011' value='cenc'/>
<ContentProtection schemeIdUri='urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95'><mspr:pro>pAIAAAEAAQCaAjwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4AeQBaAHkAOAB3AG4AWQBUAEQAMABDAEwAMwBuAE0AcgBuAFAAVQBaAHUAZwA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBKAHMAWgBBAEEARgBRAFkANgBsAGMAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APABMAEEAXwBVAFIATAA+AGgAdAB0AHAAOgAvAC8AcwB0AHIAZQBhAG0AaQBuAGcAMQAuAHgAYwByAGUAYQBtAC4AbgBlAHQAOgA4ADAAOAAwAC8AcABsAGEAeQByAGUAYQBkAHkALwBSAGkAZwBoAHQAcwBNAGEAbgBhAGcAZQByAC4AYQBzAG0AeAA8AC8ATABBAF8AVQBSAEwAPgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==</mspr:pro></ContentProtection>
<ContentProtection schemeIdUri='urn:uuid:EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED'/>
<BaseURL>https://xxxx/xxxxxx/xxxxxx.rb?r=1DyFJbi5cVYEynbTt9w7gzc5TGPmiCjyYcfgym9B5cGIg33LfBpuMrsK0A3p7L7_xWhui4ruzYGMtWvip7T29uOIJUrBEItq09sWjkZXalbYrI4UTLNocnr6Ji1Lw_KPAUfhy-tMmSG4HFcNdRD8FwK3e0PJGDiODg6F8kha8Aj_TXRVaiyh_KKBC2u5kHC0</BaseURL>
        <SegmentBase indexRange='1623-6034'>
          <Initialization range='0-1622'/>
        </SegmentBase>
      </Representation></AdaptationSet>
</Period></MPD>
rlaphoenix commented 1 year ago

The current code is bugged in regard to loading PlayReady Headers. I'll have this fixed in the next stable release, and it's already fixed in master as of now with https://github.com/rlaphoenix/pywidevine/commit/3a910bd03aa3b5376245d25be15b796f5b1aa679

I'm also making further improvements to add further support for PlayReadyObjects and their records.

In regards to actually loading that mspr:pro value, load it the same way you would a Widevine PSSH, i.e., pssh = PSSH("<the base64 here>"). Once loaded, you can then convert it with pssh.playready_to_widevine(). The reason why you probably struggled is because of the bugged loading of PlayReadyHeaders in all stable versions as of right now. As I said it will be fixed in a stable release soon.

rlaphoenix commented 1 year ago

As of https://github.com/rlaphoenix/pywidevine/commit/ddc66f0a2bf08d04ef75e1b917d18be328d14d48 I consider this issue Fixed. The final code to load a PlayReadyHeader, then convert it to a WidevineCencHeader, all while autoloading back in the PSSH class is:

from pywidevine import PSSH

pssh = PSSH("pAIAAAEAAQCaAjwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4AeQBaAHkAOAB3AG4AWQBUAEQAMABDAEwAMwBuAE0AcgBuAFAAVQBaAHUAZwA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBKAHMAWgBBAEEARgBRAFkANgBsAGMAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APABMAEEAXwBVAFIATAA+AGgAdAB0AHAAOgAvAC8AcwB0AHIAZQBhAG0AaQBuAGcAMQAuAHgAYwByAGUAYQBtAC4AbgBlAHQAOgA4ADAAOAAwAC8AcABsAGEAeQByAGUAYQBkAHkALwBSAGkAZwBoAHQAcwBNAGEAbgBhAGcAZQByAC4AYQBzAG0AeAA8AC8ATABBAF8AVQBSAEwAPgA8AC8ARABBAFQAQQA+ADwALwBXAFIATQBIAEUAQQBEAEUAUgA+AA==")
pssh.to_widevine()
assert(pssh.system_id == PSSH.SystemId.Widevine)  # True

(stable patch release soon)