forked from DevLARLEY/WidevineProxy2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_cdm.js
110 lines (99 loc) · 3.43 KB
/
remote_cdm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
export class RemoteCdm {
constructor(device_type, system_id, security_level, host, secret, device_name) {
this.device_type = device_type;
this.system_id = system_id;
this.security_level = security_level;
this.host = host;
this.secret = secret;
this.device_name = device_name;
}
static from_object(obj) {
return new RemoteCdm(
obj.device_type,
obj.system_id,
obj.security_level,
obj.host,
obj.secret,
obj.device_name ?? obj.name,
);
}
get_name() {
const type = this.device_type === "CHROME" ? "CHROME" : `L${this.security_level}`
return `[${type}] ${this.host}/${this.device_name} (${this.system_id})`;
}
async open() {
const open_request = await fetch(
`${this.host}/${this.device_name}/open`,
{
method: 'GET',
}
);
console.log("[WidevineProxy2]", "REMOTE_CDM", "OPEN", open_request.status);
const open_json = await open_request.json();
return open_json.data.session_id;
}
async close(session_id) {
const close_request = await fetch(
`${this.host}/${this.device_name}/close/${session_id}`,
{
method: 'GET',
}
);
console.log("[WidevineProxy2]", "REMOTE_CDM", "CLOSE", close_request.status);
}
// TODO:
// + get_service_certificate
// + set_service_certificate
async get_license_challenge(session_id, pssh, privacy_mode) {
const license_request = await fetch(
`${this.host}/${this.device_name}/get_license_challenge/STREAMING`,
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
session_id: session_id,
init_data: pssh,
privacy_mode: privacy_mode
})
}
)
console.log("[WidevineProxy2]", "REMOTE_CDM", "GET_LICENSE_CHALLENGE", license_request.status);
const license_request_json = await license_request.json();
return license_request_json.data.challenge_b64;
}
async parse_license(session_id, license_b64) {
const license = await fetch(
`${this.host}/${this.device_name}/parse_license`,
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
session_id: session_id,
license_message: license_b64
})
}
)
console.log("[WidevineProxy2]", "REMOTE_CDM", "PARSE_LICENSE", license.status);
}
async get_keys(session_id, type) {
const key_request = await fetch(
`${this.host}/${this.device_name}/get_keys/${type}`,
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
session_id: session_id
})
}
)
console.log("[WidevineProxy2]", "REMOTE_CDM", "GET_KEYS", key_request.status);
const key_request_json = await key_request.json();
return key_request_json.data.keys;
}
}