it mostly works!

This commit is contained in:
Reid 2025-05-12 23:33:52 -07:00
parent 76543fd220
commit 44cd13f10c
Signed by: reidlab
GPG key ID: DAF5EAF6665839FD
52 changed files with 879 additions and 396 deletions

View file

@ -1,6 +1,6 @@
import { LicenseType, Session } from "node-widevine";
import { env } from "../config.js";
import { appleMusicApi } from "../api/index.js";
import { appleMusicApi } from "../appleMusicApi/index.js";
import { dataUriToBuffer } from "data-uri-to-buffer";
import psshTools from "pssh-tools";
import * as log from "../log.js";
@ -19,7 +19,7 @@ export async function getWidevineDecryptionKey(psshDataUri: string, trackId: str
// for some reason, if gotten from a webplayback manifest, the pssh is in a completely different format
// well, somewhat. it's just the raw data, we have to rebuild the pssh
const rebuiltPssh = psshTools.widevine.encodePssh({
contentId: "meow", // this actually isn't even needed, but this library is stubborn
contentId: "meow", // this actually isn't even needed, but this library is somewhat-stubborn
dataOnly: false,
keyIds: [Buffer.from(dataUriToBuffer(psshDataUri).buffer).toString("hex")]
});
@ -38,11 +38,11 @@ export async function getWidevineDecryptionKey(psshDataUri: string, trackId: str
challenge.toString("base64")
);
if (typeof response?.license !== "string") { throw "license is gone/not a string! sign that auth failed (unsupported codec?)"; }
if (typeof response?.license !== "string") { throw new Error("license is gone/not a string! maybe 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 showing invalid data! (e.x. pssh/challenge)"; }
if (license.length === 0) { throw new Error("license(s) can't parse. this may be an error showing invalid data! (ex. pssh/challenge)"); }
const validKey = license.find((keyPair) => { return keyPair?.key?.length === 32; })?.key;
if (validKey === undefined) { throw "no valid key found in license"; }
if (validKey === undefined) { throw new Error("no valid key found in license!"); }
return validKey;
}