From 57c628378d0c9f5f92c568f9913770897d8d7ae8 Mon Sep 17 00:00:00 2001 From: SmilerRyan Date: Mon, 2 Sep 2024 04:53:06 +0100 Subject: [PATCH] api: add /api/best_audio route --- src/core/api.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/core/api.js b/src/core/api.js index 5f4ee804..2f873cd0 100644 --- a/src/core/api.js +++ b/src/core/api.js @@ -143,6 +143,32 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { } }) + app.get('/api/best_audio', async (req, res) => { + + if (!req.query.url) { return res.status(400).send('Missing required "url" query parameter'); } + + const request = req.query; + request.aFormat = "best"; + request.isAudioOnly = true; + + const normalizedRequest = normalizeRequest(request); + if (!normalizedRequest) { + return fail('ErrorCantProcess'); + } + + const parsed = extract(normalizedRequest.url); + if (parsed === null) { + return fail('ErrorUnsupported'); + } + + try { + const result = await match(parsed.host, parsed.patternMatch, false, normalizedRequest); + res.status(302).set('Location', result.body.url).end(); + } catch { + fail('ErrorSomethingWentWrong'); + } + }) + app.get('/api/stream', (req, res) => { const id = String(req.query.id); const exp = String(req.query.exp);