mostly finish custom music

This commit is contained in:
sky
2025-07-09 02:35:38 -04:00
parent acd6d2e9e2
commit daf54267b4
6 changed files with 88 additions and 187 deletions

View File

@ -9,30 +9,16 @@ async function search(query) {
let data = sc.search(query);
return data;
}
async function download(url, res) {
if (!url) {
return res.status(400).send('Please provide a SoundCloud track URL as ?url=')
}
async function download(url) {
try {
const info = await sc.getByUrl(url)
const info = await sc.getByUrl(url);
if (info.type !== 'track') {
return res.status(400).send('URL is not a SoundCloud track')
}
const { stream } = await info.getStream();
const { stream, mimeType, sizeBytes } = await info.getStream()
res.setHeader('Content-Type', mimeType)
if (sizeBytes) {
res.setHeader('Content-Length', sizeBytes.toString())
}
res.setHeader('Cache-Control', 'no-cache')
stream.pipe(res)
return stream.path;
} catch (err) {
console.error('Stream error:', err)
res.status(500).send(err.message || 'Failed to stream track')
return(err.message || 'Failed to stream track')
}
}