-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use standard python xml.etree.ElementTree #35
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Have you tested PlayReady header parsing with your changes on each support PlayReady header version? I understand that I have no Python tests made yet (something I will do eventually). |
Yes, I tested this: # -*- coding: utf-8 -*-
from xml.etree.ElementTree import XML
def run():
wrm_list = [
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.3.0.0">
<DATA>
<PROTECTINFO>
<KIDS>
<KID ALGID="AESCBC" VALUE="PV1LM/VEVk+kEOB8qqcWDg=="></KID>
<KID ALGID="AESCBC" VALUE="tuhDoKUN7EyxDPtMRNmhyA=="></KID>
</KIDS>
</PROTECTINFO>
<LA_URL>http://rm.contoso.com/rightsmanager.asmx</LA_URL>
<DS_ID>AH+03juKbUGbHl1V/QIwRA==</DS_ID>
</DATA>
</WRMHEADER>
""",
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.3.0.0">
<DATA>
<PROTECTINFO>
<KIDS>
<KID VALUE="PV1LM/VEVk+kEOB8qqcWDg=="></KID>
</KIDS>
</PROTECTINFO>
<LA_URL>http://rm.contoso.com/rightsmanager.asmx</LA_URL>
<DS_ID>AH+03juKbUGbHl1V/QIwRA==</DS_ID>
<DECRYPTORSETUP>ONDEMAND</DECRYPTORSETUP>
</DATA>
</WRMHEADER>
""",
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.3.0.0">
<DATA>
<PROTECTINFO LICENSEREQUESTED="true">
<KIDS>
<KID ALGID="value" CHECKSUM="base64-encoded value" VALUE="base64-encoded guid"></KID>
<KID ALGID="value" CHECKSUM="base64-encoded value" VALUE="base64-encoded guid"></KID>
<KID ALGID="value" CHECKSUM="base64-encoded value" VALUE="base64-encoded guid"></KID>
</KIDS>
</PROTECTINFO>
<LA_URL> URL for license acquisition </LA_URL>
<LUI_URL>
URL for Non-silent license acquisition web page
</LUI_URL>
<DS_ID> base64-encoded guid </DS_ID>
<CUSTOMATTRIBUTES xmlns="">
<mm:Publisher xmlns:mm="urn:schema-musicmogul-com">
<mm:Author>
Elvis Presley
</mm:Author>
<mm:CreationDate>
2007/08/21:12:00:00
</mm:CreationDate>
</mm:Publisher>
</CUSTOMATTRIBUTES>
<DECRYPTORSETUP>ONDEMAND</DECRYPTORSETUP>
</DATA>
</WRMHEADER>
""",
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.2.0.0">
<DATA>
<PROTECTINFO>
<KIDS>
<KID ALGID="AESCTR" CHECKSUM="xNvWVxoWk04=" VALUE="0IbHou/5s0yzM80yOkKEpQ=="></KID>
<KID ALGID="AESCTR" CHECKSUM="GnKaQIRacPU=" VALUE="/qgG2xbs4k2SKCxx6bhWqw=="></KID>
</KIDS>
</PROTECTINFO>
<LA_URL>http://rm.contoso.com/rightsmanager.asmx</LA_URL>
<DS_ID>AH+03juKbUGbHl1V/QIwRA==</DS_ID>
</DATA>
</WRMHEADER>
""",
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.2.0.0">
<DATA>
<PROTECTINFO>
<KIDS>
<KID ALGID="AESCTR" CHECKSUM="base64-encoded value" VALUE="base64-encoded guid"></KID>
<KID ALGID="AESCTR" CHECKSUM="base64-encoded value" VALUE="base64-encoded guid"></KID>
<KID ALGID="AESCTR" CHECKSUM="base64-encoded value" VALUE="base64-encoded guid"></KID>
</KIDS>
</PROTECTINFO>
<LA_URL> URL for license acquisition </LA_URL>
<LUI_URL>
URL for Non-silent license acquisition web page
</LUI_URL>
<DS_ID> base64-encoded guid </DS_ID>
<CUSTOMATTRIBUTES xmlns="">
<mm:Publisher xmlns:mm="urn:schema-musicmogul-com">
<mm:Author>
Elvis Presley
</mm:Author>
<mm:CreationDate>
2007/08/21:12:00:00
</mm:CreationDate>
</mm:Publisher>
</CUSTOMATTRIBUTES>
<DECRYPTORSETUP>ONDEMAND</DECRYPTORSETUP>
</DATA>
</WRMHEADER>
""",
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.1.0.0">
<DATA>
<PROTECTINFO>
<KID ALGID="AESCTR" CHECKSUM="base64-encoded value" VALUE="base64-encoded guid"></KID>
</PROTECTINFO>
<LA_URL> URL for license acquisition </LA_URL>
<LUI_URL>
URL for Non-silent license acquisition web page
</LUI_URL>
<DS_ID> base64-encoded guid </DS_ID>
<CUSTOMATTRIBUTES xmlns="">
<mm:Publisher xmlns:mm="urn:schema-musicmogul-com">
<mm:Author>
Elvis Presley
</mm:Author>
<mm:CreationDate>
2007/08/21:12:00:00
</mm:CreationDate>
</mm:Publisher>
</CUSTOMATTRIBUTES>
<DECRYPTORSETUP>ONDEMAND</DECRYPTORSETUP>
</DATA>
</WRMHEADER>
""",
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0">
<DATA>
<PROTECTINFO>
<ALGID>AESCTR</ALGID>
<KEYLEN>16</KEYLEN>
</PROTECTINFO>
<KID>q5HgCTj40kGeNVhTH9Gexw==</KID>
<CHECKSUM>w+OZVr8vzrQ=</CHECKSUM>
<LA_URL>http://rm.contoso.com/rightsmanager.asmx</LA_URL>
<CUSTOMATTRIBUTES>
<IIS_DRM_VERSION>8.0.1705.19</IIS_DRM_VERSION>
</CUSTOMATTRIBUTES>
</DATA>
</WRMHEADER>
""",
"""
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0">
<DATA>
<PROTECTINFO>
<ALGID>AESCTR</ALGID>
<KEYLEN>16</KEYLEN>
</PROTECTINFO>
<LA_URL> URL for license acquisition </LA_URL>
<LUI_URL>
URL for Non-silent license acquisition web page
</LUI_URL>
<DS_ID>base64-encoded guid</DS_ID>
<KID>base64-encoded kid</KID>
<CUSTOMATTRIBUTES xmlns="">
<mm:Publisher xmlns:mm="urn:schema-musicmogul-com">
<mm:Author>
Elvis Presley
</mm:Author>
<mm:CreationDate>
2007/08/21:12:00:00
</mm:CreationDate>
</mm:Publisher>
</CUSTOMATTRIBUTES>
<CHECKSUM>
checksum of the content key for verification
</CHECKSUM>
</DATA>
</WRMHEADER>
"""
]
for wrm in wrm_list:
wrm_ns = {"wrm": "http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader"}
prr_header = XML(wrm)
prr_header_version = prr_header.get("version")
if prr_header_version == "4.0.0.0":
key_ids = [
x.text
for x in prr_header.findall("./wrm:DATA/wrm:KID", wrm_ns)
]
elif prr_header_version == "4.1.0.0":
key_ids = [
x.get("VALUE")
for x in prr_header.findall("./wrm:DATA/wrm:PROTECTINFO/wrm:KID", wrm_ns)
]
elif prr_header_version in ("4.2.0.0", "4.3.0.0"):
# TODO: Retain the Encryption Scheme information in v4.3.0.0
# This is because some Key IDs can be AES-CTR while some are AES-CBC.
# Conversion to WidevineCencHeader could use this information.
key_ids = [
x.get("VALUE")
for x in prr_header.findall("./wrm:DATA/wrm:PROTECTINFO/wrm:KIDS/wrm:KID", wrm_ns)
]
print(prr_header_version)
print(key_ids)
if __name__ == '__main__':
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
lxml needs a compiled binary and therefore it is more difficult to install pywidevine on ARM devices like Raspberry Pi.
It's better to use standard xml.etree.ElementTree for xml parsing. This code even works on Python 2.7.