mostly finish custom music
This commit is contained in:
@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user