Skip to content

Commit

Permalink
fix: ignore fairplay content protection (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored May 19, 2021
1 parent 30d3b3d commit 9f62c85
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ export default class Parser extends Stream {
return;
}

if (entry.attributes.KEYFORMAT === 'com.apple.streamingkeydelivery') {
this.manifest.contentProtection = this.manifest.contentProtection || {};

// TODO: add full support for this.
this.manifest.contentProtection['com.apple.fps.1_0'] = {
attributes: entry.attributes
};

return;
}

// check if the content is encrypted for Widevine
// Widevine/HLS spec: https://storage.googleapis.com/wvdocs/Widevine_DRM_HLS.pdf
if (entry.attributes.KEYFORMAT === widevineUuid) {
Expand Down Expand Up @@ -286,16 +297,15 @@ export default class Parser extends Stream {

// if Widevine key attributes are valid, store them as `contentProtection`
// on the manifest to emulate Widevine tag structure in a DASH mpd
this.manifest.contentProtection = {
'com.widevine.alpha': {
attributes: {
schemeIdUri: entry.attributes.KEYFORMAT,
// remove '0x' from the key id string
keyId: entry.attributes.KEYID.substring(2)
},
// decode the base64-encoded PSSH box
pssh: decodeB64ToUint8Array(entry.attributes.URI.split(',')[1])
}
this.manifest.contentProtection = this.manifest.contentProtection || {};
this.manifest.contentProtection['com.widevine.alpha'] = {
attributes: {
schemeIdUri: entry.attributes.KEYFORMAT,
// remove '0x' from the key id string
keyId: entry.attributes.KEYID.substring(2)
},
// decode the base64-encoded PSSH box
pssh: decodeB64ToUint8Array(entry.attributes.URI.split(',')[1])
};
return;
}
Expand Down
23 changes: 23 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,29 @@ QUnit.module('m3u8s', function(hooks) {
);
});

QUnit.test('Can understand widevine/safari drm ext-x-key', function(assert) {
this.parser.push([
'#EXT-X-VERSION:3',
'#EXT-X-MEDIA-SEQUENCE:0',
'#EXT-X-DISCONTINUITY-SEQUENCE:0',
'#EXT-X-TARGETDURATION:10',
'#EXT-X-PART-INF:PART-TARGET=1',
'#EXT-X-SERVER-CONTROL:foo=bar',
'#EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,foo",KEYID=0x555777,IV=1234567890abcdef1234567890abcdef,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"',
'#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://foo",KEYFORMATVERSIONS="1",KEYFORMAT="com.apple.streamingkeydelivery"',
'#EXTINF:10,',
'media-00001.ts',
'#EXT-X-ENDLIST'
].join('\n'));
this.parser.end();

assert.deepEqual(
Object.keys(this.parser.manifest.contentProtection),
['com.widevine.alpha', 'com.apple.fps.1_0'],
'info as expected'
);
});

QUnit.module('integration');

for (const key in testDataExpected) {
Expand Down

0 comments on commit 9f62c85

Please sign in to comment.