api: add an option to allow better audio from youtube

& an env variable to disable it if needed
This commit is contained in:
wukko 2025-04-20 20:45:07 +06:00
parent 0294bbd447
commit 335cd51eb5
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
3 changed files with 6 additions and 0 deletions

View File

@ -61,6 +61,7 @@ const env = {
ytSessionServer: process.env.YOUTUBE_SESSION_SERVER,
ytSessionReloadInterval: 300,
ytSessionInnertubeClient: process.env.YOUTUBE_SESSION_INNERTUBE_CLIENT,
ytAllowBetterAudio: process.env.YOUTUBE_ALLOW_BETTER_AUDIO !== "0",
}
const genericUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";

View File

@ -113,6 +113,10 @@ export default async function({ host, patternMatch, params }) {
fetchInfo.format = "vp9";
fetchInfo.isAudioOnly = true;
fetchInfo.isAudioMuted = false;
if (env.ytAllowBetterAudio && params.youtubeBetterAudio) {
fetchInfo.quality = "max";
}
}
r = await youtube(fetchInfo);

View File

@ -46,5 +46,6 @@ export const apiSchema = z.object({
localProcessing: z.boolean().default(false),
youtubeHLS: z.boolean().default(false),
youtubeBetterAudio: z.boolean().default(false),
})
.strict();