websӘFacebook ite
This commit is contained in:
parent
f233d9e64f
commit
76543fd220
20 changed files with 1051 additions and 96 deletions
34
src/web/endpoints/back/dlWebplayback.ts
Normal file
34
src/web/endpoints/back/dlWebplayback.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { getWidevineDecryptionKey } from "../../../downloader/keygen.js";
|
||||
import { downloadSong, WebplaybackCodec } from "../../../downloader/index.js";
|
||||
import express from "express";
|
||||
import StreamInfo from "../../../downloader/streamInfo.js";
|
||||
import { appleMusicApi } from "../../../api/index.js";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/dlWebplayback", async (req, res, next) => {
|
||||
try {
|
||||
const { trackId, codec } = req.query;
|
||||
if (typeof trackId !== "string") { res.status(400).send("trackId is required and must be a string!"); return; }
|
||||
if (typeof codec !== "string") { res.status(400).send("codec is required and must be a string!"); return; }
|
||||
|
||||
const c = Object.values(WebplaybackCodec).find((c) => { return c === codec; });
|
||||
if (c === undefined) { res.status(400).send("codec is invalid!"); return; }
|
||||
|
||||
// TODO: check if this returns an error
|
||||
const webplaybackResponse = await appleMusicApi.getWebplayback(trackId);
|
||||
console.log(webplaybackResponse);
|
||||
const streamInfo = await StreamInfo.fromWebplayback(webplaybackResponse, c);
|
||||
if (streamInfo.widevinePssh !== undefined) {
|
||||
const decryptionKey = await getWidevineDecryptionKey(streamInfo.widevinePssh, streamInfo.trackId);
|
||||
const filePath = await downloadSong(streamInfo.streamUrl, decryptionKey, c);
|
||||
res.download(filePath);
|
||||
} else {
|
||||
res.status(400).send("no decryption key found!");
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
Loading…
Add table
Add a link
Reference in a new issue