Skip to content

Commit

Permalink
Get Challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxRefire committed Aug 5, 2024
1 parent 0f5f57c commit 2807074
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
40 changes: 40 additions & 0 deletions getChallenge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export default async function() {
let keySystemAccess;
try{
keySystemAccess = await navigator.requestMediaKeySystemAccess('com.widevine.alpha', config)
} catch {
config[0]['sessionTypes'] = ['temporary']
keySystemAccess = await navigator.requestMediaKeySystemAccess('com.widevine.alpha', config)
}
let challenge = await getChallenge(keySystemAccess);
return challenge
};

// Tears of Steel Init data Widevine
let initData = Uint8Array.from(atob('AAAARHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAACQIARIBMRoNd2lkZXZpbmVfdGVzdCIKMjAxNV90ZWFycyoCU0Q='), c => c.charCodeAt(0))

// Widevine CDM config MediaKeyAccess default
let config = [{
initDataTypes: ['cenc'],
sessionTypes: ['persistent-license'],
videoCapabilities: [{
contentType: 'video/mp4; codecs="avc1.640029"'
}],
audioCapabilities: [{
contentType: 'audio/mp4; codecs="mp4a.40.2"'
}]
}];

async function getChallenge(keySystemAccess) {
return new Promise((resolve, reject) => {
try{
keySystemAccess.createMediaKeys().then(mediaKeys => {
let keySession = mediaKeys.createSession(config[0]['sessionTypes'])
keySession.addEventListener("message", () => resolve(event.message));
keySession.generateRequest("cenc", initData)
})
} catch(err) {
reject("Unable to create MediaKeys : " + err)
}
})
}
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<script type="module">
import getChallenge from './getChallenge.js'
window.onload = async () => {
let b64encode = b => btoa(String.fromCharCode(...new Uint8Array(b)))
let challenge = await getChallenge()
console.log(b64encode(challenge))
}
</script>
</head>
<body>
</body>
</html>

0 comments on commit 2807074

Please sign in to comment.