make릭ع a few f梦nctions have return types + etc
This commit is contained in:
parent
b10801bf29
commit
237ec061d2
11 changed files with 98 additions and 68 deletions
|
@ -2,11 +2,10 @@ import { LicenseType, Session } from "node-widevine";
|
|||
import { env } from "../config.js";
|
||||
import { appleMusicApi } from "../api/index.js";
|
||||
import { dataUriToBuffer } from "data-uri-to-buffer";
|
||||
import psshTools from "pssh-tools";
|
||||
import * as log from "../log.js";
|
||||
import fs from "node:fs";
|
||||
import * as psshTools from "pssh-tools";
|
||||
|
||||
export async function getWidevineDecryptionKey(psshDataUri: string, trackId: string): Promise<void> {
|
||||
export async function getWidevineDecryptionKey(psshDataUri: string, trackId: string): Promise<string> {
|
||||
let pssh = Buffer.from(dataUriToBuffer(psshDataUri).buffer);
|
||||
|
||||
const privateKey = Buffer.from(env.WIDEVINE_PRIVATE_KEY, "base64");
|
||||
|
@ -18,7 +17,7 @@ export async function getWidevineDecryptionKey(psshDataUri: string, trackId: str
|
|||
challenge = session.createLicenseRequest(LicenseType.STREAMING);
|
||||
} catch (err) {
|
||||
// for some reason, if gotten from a webplayback manifest, the pssh is in a completely different format
|
||||
// well, somewhat. we have to rebuild the pssh
|
||||
// well, somewhat. it's just the raw data, we have to rebuild the pssh
|
||||
const rebuiltPssh = psshTools.widevine.encodePssh({
|
||||
contentId: "Hiiii", // lol?? i don't know what this is, random slop go!!!!
|
||||
dataOnly: false,
|
||||
|
@ -26,7 +25,7 @@ export async function getWidevineDecryptionKey(psshDataUri: string, trackId: str
|
|||
});
|
||||
|
||||
log.warn("pssh was invalid, treating it as raw data");
|
||||
log.warn("this should not error, unless the pssh data is invalid, too");
|
||||
log.warn("this should not throw an error, unless the pssh data is invalid, too");
|
||||
|
||||
pssh = Buffer.from(rebuiltPssh, "base64");
|
||||
session = new Session({ privateKey, identifierBlob }, pssh);
|
||||
|
@ -39,10 +38,11 @@ export async function getWidevineDecryptionKey(psshDataUri: string, trackId: str
|
|||
challenge.toString("base64")
|
||||
);
|
||||
|
||||
if (typeof response?.license !== "string") { throw "license is missing or not a string! sign that authentication failed (unsupported codec?)"; }
|
||||
if (typeof response?.license !== "string") { throw "license is gone/not a string! sign that auth failed (unsupported codec?)"; }
|
||||
const license = session.parseLicense(Buffer.from(response.license, "base64"));
|
||||
if (license.length === 0) { throw "license(s) failed to be parsed. this could be an error for invalid data! (e.x. pssh/challenge)"; }
|
||||
if (license.length === 0) { throw "license(s) failed to be parsed. this could be an error showing invalid data! (e.x. pssh/challenge)"; }
|
||||
|
||||
log.info(license);
|
||||
fs.writeFileSync("license", response.license, { encoding: "utf-8" });
|
||||
const validKey = license.find((keyPair) => { return keyPair?.key?.length === 32; })?.key;
|
||||
if (validKey === undefined) { throw "no valid key found in license"; }
|
||||
return validKey;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue