non-hardcoded companion ip
This commit is contained in:
parent
f9fcfe01af
commit
aaa9676fbb
12
bun.lock
12
bun.lock
|
|
@ -15,7 +15,7 @@
|
|||
"fluent-ffmpeg": "^2.1.3",
|
||||
"googlevideo": "^4.0.4",
|
||||
"jsdom": "^26.1.0",
|
||||
"youtubei.js": "^15.1.1",
|
||||
"youtubei.js": "^16.0.1",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
|
|
@ -76,8 +76,6 @@
|
|||
|
||||
"accepts": ["accepts@2.0.0", "", { "dependencies": { "mime-types": "^3.0.0", "negotiator": "^1.0.0" } }, "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng=="],
|
||||
|
||||
"acorn": ["acorn@8.15.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg=="],
|
||||
|
||||
"agent-base": ["agent-base@6.0.2", "", { "dependencies": { "debug": "4" } }, "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ=="],
|
||||
|
||||
"async": ["async@0.2.10", "", {}, "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ=="],
|
||||
|
|
@ -212,8 +210,6 @@
|
|||
|
||||
"isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="],
|
||||
|
||||
"jintr": ["jintr@3.3.1", "", { "dependencies": { "acorn": "^8.8.0" } }, "sha512-nnOzyhf0SLpbWuZ270Omwbj5LcXUkTcZkVnK8/veJXtSZOiATM5gMZMdmzN75FmTyj+NVgrGaPdH12zIJ24oIA=="],
|
||||
|
||||
"jsdom": ["jsdom@26.1.0", "", { "dependencies": { "cssstyle": "^4.2.1", "data-urls": "^5.0.0", "decimal.js": "^10.5.0", "html-encoding-sniffer": "^4.0.0", "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.6", "is-potential-custom-element-name": "^1.0.1", "nwsapi": "^2.2.16", "parse5": "^7.2.1", "rrweb-cssom": "^0.8.0", "saxes": "^6.0.0", "symbol-tree": "^3.2.4", "tough-cookie": "^5.1.1", "w3c-xmlserializer": "^5.0.0", "webidl-conversions": "^7.0.0", "whatwg-encoding": "^3.1.1", "whatwg-mimetype": "^4.0.0", "whatwg-url": "^14.1.1", "ws": "^8.18.0", "xml-name-validator": "^5.0.0" }, "peerDependencies": { "canvas": "^3.0.0" }, "optionalPeers": ["canvas"] }, "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg=="],
|
||||
|
||||
"lru-cache": ["lru-cache@10.4.3", "", {}, "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ=="],
|
||||
|
|
@ -224,6 +220,8 @@
|
|||
|
||||
"merge-descriptors": ["merge-descriptors@2.0.0", "", {}, "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g=="],
|
||||
|
||||
"meriyah": ["meriyah@6.1.4", "", {}, "sha512-Sz8FzjzI0kN13GK/6MVEsVzMZEPvOhnmmI1lU5+/1cGOiK3QUahntrNNtdVeihrO7t9JpoH75iMNXg6R6uWflQ=="],
|
||||
|
||||
"mime-db": ["mime-db@1.54.0", "", {}, "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ=="],
|
||||
|
||||
"mime-types": ["mime-types@3.0.1", "", { "dependencies": { "mime-db": "^1.54.0" } }, "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA=="],
|
||||
|
|
@ -344,7 +342,7 @@
|
|||
|
||||
"xmlchars": ["xmlchars@2.2.0", "", {}, "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="],
|
||||
|
||||
"youtubei.js": ["youtubei.js@15.1.1", "", { "dependencies": { "@bufbuild/protobuf": "^2.0.0", "jintr": "^3.3.1", "undici": "^6.21.3" } }, "sha512-fuEDj9Ky6cAQg93BrRVCbr+GTYNZQAIFZrx/a3oDRuGc3Mf5bS0dQfoYwwgjtSV7sgAKQEEdGtzRdBzOc8g72Q=="],
|
||||
"youtubei.js": ["youtubei.js@16.0.1", "", { "dependencies": { "@bufbuild/protobuf": "^2.0.0", "meriyah": "^6.1.4" } }, "sha512-3802bCAGkBc2/G5WUTc0l/bO5mPYJbQAHL04d9hE9PnrDHoBUT8MN721Yqt4RCNncAXdHcfee9VdJy3Fhq1r5g=="],
|
||||
|
||||
"dom-serializer/entities": ["entities@4.5.0", "", {}, "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw=="],
|
||||
|
||||
|
|
@ -358,8 +356,6 @@
|
|||
|
||||
"jsdom/ws": ["ws@8.18.3", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg=="],
|
||||
|
||||
"youtubei.js/undici": ["undici@6.21.3", "", {}, "sha512-gBLkYIlEnSp8pFbT64yFgGE6UIB9tAkhukC23PmMDCe5Nd+cRqKxSjw5y54MK2AZMgZfJWMaNE4nYUHgi1XEOw=="],
|
||||
|
||||
"jsdom/https-proxy-agent/agent-base": ["agent-base@7.1.4", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="],
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"whitelist": [],
|
||||
"player_id": "0004de42",
|
||||
"useCompanion": true
|
||||
"useCompanion": true,
|
||||
"maxVideoSize": 100,
|
||||
"companionIp": ""
|
||||
}
|
||||
14
index.ts
14
index.ts
|
|
@ -132,9 +132,15 @@ app.get('/videos/:id', async (req, res) => {
|
|||
}
|
||||
})
|
||||
|
||||
interface Config {
|
||||
whitelist: string[]
|
||||
useCompanion: boolean
|
||||
maxVideoSize: number // in MB
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
app.ws('/download/:id', async (ws, req) => {
|
||||
const config = await Bun.file('config.json').json()
|
||||
const config: Config = await Bun.file('config.json').json()
|
||||
const yt = await Innertube.create();
|
||||
let quality = '480p'
|
||||
|
||||
|
|
@ -179,7 +185,7 @@ app.ws('/download/:id', async (ws, req) => {
|
|||
const videoSizeTotal = (selectedFormats.audioFormat.content_length || 0)
|
||||
+ (selectedFormats.videoFormat.content_length || 0)
|
||||
|
||||
if (videoSizeTotal > (1_048_576 * 150) && !config.whitelist.includes(req.params.id)) {
|
||||
if (videoSizeTotal > (1_048_576 * config.maxVideoSize) && !config.whitelist.includes(req.params.id)) {
|
||||
ws.send('Is this content considered high risk? If so, please email me at admin@preservetube.com.');
|
||||
ws.send('This video is too large, and unfortunately, Preservetube does not have unlimited storage.');
|
||||
return ws.close()
|
||||
|
|
@ -205,12 +211,10 @@ app.ws('/download/:id', async (ws, req) => {
|
|||
const { streamResults } = await createSabrStream(req.params.id, streamOptions);
|
||||
const { videoStream, audioStream, selectedFormats } = streamResults;
|
||||
|
||||
const config = await Bun.file('config.json').json()
|
||||
const videoSizeTotal = (selectedFormats.audioFormat.contentLength || 0)
|
||||
+ (selectedFormats.videoFormat.contentLength || 0)
|
||||
|
||||
// 100MB
|
||||
if (videoSizeTotal > (1_048_576 * 100) && !config.whitelist.includes(req.params.id)) {
|
||||
if (videoSizeTotal > (1_048_576 * config.maxVideoSize) && !config.whitelist.includes(req.params.id)) {
|
||||
ws.send('Is this content considered high risk? If so, please email me at admin@preservetube.com.');
|
||||
ws.send('This video is too large, and unfortunately, Preservetube does not have unlimited storage.');
|
||||
return ws.close()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@
|
|||
"fluent-ffmpeg": "^2.1.3",
|
||||
"googlevideo": "^4.0.4",
|
||||
"jsdom": "^26.1.0",
|
||||
"youtubei.js": "^15.1.1"
|
||||
"youtubei.js": "^16.0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,8 @@ export async function downloadStream(streamUrl: string, format: any, stream: Wri
|
|||
}
|
||||
|
||||
async function getStreamUrl(videoId: string, itag: number): Promise<string|false> {
|
||||
const req = await fetch(`http://127.0.0.1:8282/companion/latest_version?id=${videoId}&itag=${itag}`, {
|
||||
const config = await Bun.file('config.json').json()
|
||||
const req = await fetch(`http://${config.companionIp || '127.0.0.1'}:8282/companion/latest_version?id=${videoId}&itag=${itag}`, {
|
||||
redirect: 'manual'
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue