api/soundcloud: catch region locked and paid songs and show an error

This commit is contained in:
wukko 2024-11-24 18:35:07 +06:00
parent eb52ab2be8
commit 43c3294230
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -62,7 +62,17 @@ export default async function(obj) {
if (!json) return { error: "fetch.fail" };
if (!json.media.transcodings) return { error: "fetch.empty" };
if (json?.policy === "BLOCK") {
return { error: "content.region" };
}
if (json?.policy === "SNIP") {
return { error: "content.paid" };
}
if (!json?.media?.transcodings || !json?.media?.transcodings.length === 0) {
return { error: "fetch.empty" };
}
let bestAudio = "opus",
selectedStream = json.media.transcodings.find(v => v.preset === "opus_0_0"),
@ -74,6 +84,10 @@ export default async function(obj) {
bestAudio = "mp3"
}
if (!selectedStream) {
return { error: "fetch.empty" };
}
let fileUrlBase = selectedStream.url;
let fileUrl = `${fileUrlBase}${fileUrlBase.includes("?") ? "&" : "?"}client_id=${clientId}&track_authorization=${json.track_authorization}`;