mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-16 10:18:28 +00:00
soundcloud: download original audio file whenever possible
This commit is contained in:
parent
b4eddd06fe
commit
fdd7137865
@ -54,6 +54,24 @@ export default async function(obj) {
|
|||||||
let clientId = await findClientID();
|
let clientId = await findClientID();
|
||||||
if (!clientId) return { error: 'ErrorSoundCloudNoClientId' };
|
if (!clientId) return { error: 'ErrorSoundCloudNoClientId' };
|
||||||
|
|
||||||
|
const audioFilename = `soundcloud_${json.id}`;
|
||||||
|
const fileMetadata = {
|
||||||
|
title: json.title,
|
||||||
|
artist: json.user.username,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (json.downloadable) {
|
||||||
|
const downloadUrl = 'https://api-v2.soundcloud.com/tracks/' + json.id + '/download?client_id=' + clientId;
|
||||||
|
const redirectUri = await fetch(downloadUrl).then(async (r) => { return (await r.json()).redirectUri })
|
||||||
|
.catch(() => { return false });
|
||||||
|
if (redirectUri)
|
||||||
|
return {
|
||||||
|
urls: redirectUri,
|
||||||
|
audioFilename,
|
||||||
|
fileMetadata
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let fileUrlBase = json.media.transcodings[0]["url"].replace("/hls", "/progressive"),
|
let fileUrlBase = json.media.transcodings[0]["url"].replace("/hls", "/progressive"),
|
||||||
fileUrl = `${fileUrlBase}${fileUrlBase.includes("?") ? "&" : "?"}client_id=${clientId}&track_authorization=${json.track_authorization}`;
|
fileUrl = `${fileUrlBase}${fileUrlBase.includes("?") ? "&" : "?"}client_id=${clientId}&track_authorization=${json.track_authorization}`;
|
||||||
if (fileUrl.substring(0, 54) !== "https://api-v2.soundcloud.com/media/soundcloud:tracks:") return { error: 'ErrorEmptyDownload' };
|
if (fileUrl.substring(0, 54) !== "https://api-v2.soundcloud.com/media/soundcloud:tracks:") return { error: 'ErrorEmptyDownload' };
|
||||||
@ -65,10 +83,7 @@ export default async function(obj) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
urls: file,
|
urls: file,
|
||||||
audioFilename: `soundcloud_${json.id}`,
|
audioFilename,
|
||||||
fileMetadata: {
|
fileMetadata
|
||||||
title: json.title,
|
|
||||||
artist: json.user.username,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user