api: add /api/best_audio route

This commit is contained in:
SmilerRyan 2024-09-02 04:53:06 +01:00 committed by GitHub
parent afa33c4043
commit 57c628378d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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) => { app.get('/api/stream', (req, res) => {
const id = String(req.query.id); const id = String(req.query.id);
const exp = String(req.query.exp); const exp = String(req.query.exp);