Skip to content

best way to save what you love

api: disable youtube HLS by default & add env to enable it

wukkoaf99e7218c0b
diff --git a/api/src/core/api.js b/api/src/core/api.js
index eb5cf4ff..c8ff6fbf 100644
--- a/api/src/core/api.js
+++ b/api/src/core/api.js
@@ -156,6 +156,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
return fail(res, `error.api.auth.key.${error}`);
}
+ req.isApiKey = true;
return next();
});
@@ -264,6 +265,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
patternMatch: parsed.patternMatch,
params: normalizedRequest,
isSession: req.isSession ?? false,
+ isApiKey: req.isApiKey ?? false,
});
res.status(result.status).json(result.body);
diff --git a/api/src/core/env.js b/api/src/core/env.js
index 37ab36c1..ec762b44 100644
--- a/api/src/core/env.js
+++ b/api/src/core/env.js
@@ -8,6 +8,7 @@ import * as cluster from "../misc/cluster.js";
import { Green, Yellow } from "../misc/console-text.js";
const forceLocalProcessingOptions = ["never", "session", "always"];
+const youtubeHlsOptions = ["never", "key", "always"];
export const loadEnvs = (env = process.env) => {
const disabledServices = env.DISABLED_SERVICES?.split(',') || [];
@@ -74,6 +75,9 @@ export const loadEnvs = (env = process.env) => {
// "never" | "session" | "always"
forceLocalProcessing: env.FORCE_LOCAL_PROCESSING ?? "never",
+ // "never" | "key" | "always"
+ enableDeprecatedYoutubeHls: env.ENABLE_DEPRECATED_YOUTUBE_HLS ?? "never",
+
envFile: env.API_ENV_FILE,
envRemoteReloadInterval: 300,
};
@@ -106,6 +110,12 @@ export const validateEnvs = async (env) => {
throw new Error("Invalid FORCE_LOCAL_PROCESSING");
}
+ if (env.enableDeprecatedYoutubeHls && !youtubeHlsOptions.includes(env.enableDeprecatedYoutubeHls)) {
+ console.error("ENABLE_DEPRECATED_YOUTUBE_HLS is invalid.");
+ console.error(`Supported options are are: ${youtubeHlsOptions.join(', ')}\n`);
+ throw new Error("Invalid ENABLE_DEPRECATED_YOUTUBE_HLS");
+ }
+
if (env.externalProxy && env.freebindCIDR) {
throw new Error('freebind is not available when external proxy is enabled')
}
diff --git a/api/src/processing/match.js b/api/src/processing/match.js
index 65a021b0..bf816b1c 100644
--- a/api/src/processing/match.js
+++ b/api/src/processing/match.js
@@ -32,7 +32,7 @@ import xiaohongshu from "./services/xiaohongshu.js";
let freebind;
-export default async function({ host, patternMatch, params, isSession }) {
+export default async function({ host, patternMatch, params, isSession, isApiKey }) {
const { url } = params;
assert(url instanceof URL);
let dispatcher, requestIP;
@@ -65,6 +65,14 @@ export default async function({ host, patternMatch, params, isSession }) {
});
}
+ // youtubeHLS will be fully removed in the future
+ let youtubeHLS = params.youtubeHLS;
+ const hlsEnv = env.enableDeprecatedYoutubeHls;
+
+ if (hlsEnv === "never" || (hlsEnv === "key" && !isApiKey)) {
+ youtubeHLS = false;
+ }
+
switch (host) {
case "twitter":
r = await twitter({
@@ -105,7 +113,7 @@ export default async function({ host, patternMatch, params, isSession }) {
isAudioOnly,
isAudioMuted,
dubLang: params.youtubeDubLang,
- youtubeHLS: params.youtubeHLS,
+ youtubeHLS,
}
if (url.hostname === "music.youtube.com" || isAudioOnly) {