twitter spaces and a ton of improvements
This commit is contained in:
@@ -7,30 +7,28 @@ export default async function(obj) {
|
||||
let html;
|
||||
if (!obj.author && !obj.song && obj.shortLink) {
|
||||
html = await got.get(`https://soundcloud.app.goo.gl/${obj.shortLink}/`, { headers: { "user-agent": genericUserAgent } });
|
||||
html.on('error', (err) => {
|
||||
return { error: loc(obj.lang, 'ErrorCouldntFetch', 'soundcloud') };
|
||||
});
|
||||
html = html.body
|
||||
}
|
||||
if (obj.author && obj.song) {
|
||||
html = await got.get(`https://soundcloud.com/${obj.author}/${obj.song}`, { headers: { "user-agent": genericUserAgent } });
|
||||
html.on('error', (err) => {
|
||||
return { error: loc(obj.lang, 'ErrorCouldntFetch', 'soundcloud') };
|
||||
});
|
||||
html = html.body
|
||||
}
|
||||
if (html.includes('<script>window.__sc_hydration = ') && html.includes('"format":{"protocol":"progressive","mime_type":"audio/mpeg"},') && html.includes('{"hydratable":"sound","data":')) {
|
||||
let json = JSON.parse(html.split('{"hydratable":"sound","data":')[1].split('}];</script>')[0])
|
||||
if (json["media"]["transcodings"]) {
|
||||
let fileUrl = `${json.media.transcodings[0]["url"].replace("/hls", "/progressive")}?client_id=${services["soundcloud"]["clientid"]}&track_authorization=${json.track_authorization}`;
|
||||
if (fileUrl.substring(0, 54) == "https://api-v2.soundcloud.com/media/soundcloud:tracks:") {
|
||||
if ((json.duration < maxAudioDuration) || obj.format == "best" || obj.format == "mp3") {
|
||||
if (fileUrl.substring(0, 54) === "https://api-v2.soundcloud.com/media/soundcloud:tracks:") {
|
||||
if (json.duration < maxAudioDuration) {
|
||||
let file = await got.get(fileUrl, { headers: { "user-agent": genericUserAgent } });
|
||||
file.on('error', (err) => {
|
||||
return { error: loc(obj.lang, 'ErrorCouldntFetch', 'soundcloud') };
|
||||
});
|
||||
file = JSON.parse(file.body).url
|
||||
return { urls: file, audioFilename: `soundcloud_${json.id}` }
|
||||
return {
|
||||
urls: file,
|
||||
audioFilename: `soundcloud_${json.id}`,
|
||||
fileMetadata: {
|
||||
title: json.title,
|
||||
artist: json.user.username,
|
||||
}
|
||||
}
|
||||
} else return { error: loc(obj.lang, 'ErrorLengthAudioConvert', maxAudioDuration / 60000) }
|
||||
}
|
||||
} else return { error: loc(obj.lang, 'ErrorEmptyDownload') }
|
||||
|
||||
Reference in New Issue
Block a user