soundcloud: fall back to mp3 when no opus found
also made match action decider readable
This commit is contained in:
@@ -60,8 +60,16 @@ export default async function(obj) {
|
||||
|
||||
if (!json["media"]["transcodings"]) return { error: 'ErrorEmptyDownload' };
|
||||
|
||||
let fileUrlBase = json.media.transcodings.filter(v => v.preset === "opus_0_0")[0]["url"],
|
||||
fileUrl = `${fileUrlBase}${fileUrlBase.includes("?") ? "&" : "?"}client_id=${clientId}&track_authorization=${json.track_authorization}`;
|
||||
let isMp3,
|
||||
selectedStream = json.media.transcodings.filter(v => v.preset === "opus_0_0")
|
||||
|
||||
// fall back to mp3 if no opus is available
|
||||
if (selectedStream.length === 0) {
|
||||
selectedStream = json.media.transcodings.filter(v => v.preset === "mp3_0_0")
|
||||
isMp3 = true
|
||||
}
|
||||
let fileUrlBase = selectedStream[0]["url"];
|
||||
let 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' };
|
||||
|
||||
@@ -83,6 +91,7 @@ export default async function(obj) {
|
||||
title: fileMetadata.title,
|
||||
author: fileMetadata.artist
|
||||
},
|
||||
fileMetadata: fileMetadata
|
||||
isMp3,
|
||||
fileMetadata
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user