music: fix /tracks for soundcloud

This commit is contained in:
Cynthia Foxwell 2024-04-12 11:30:04 -06:00
parent 0ce0dfa67e
commit 77c73e814a

View file

@ -119,6 +119,31 @@ async function processPlaylist(
).then((res) => res.json()); ).then((res) => res.json());
playlist = [...playlist, ...currentLikes.collection]; playlist = [...playlist, ...currentLikes.collection];
} }
} else if (url.indexOf("/tracks")) {
let userInfo = await fetch(
`https://api-v2.soundcloud.com/resolve?url=${url}&client_id=${clientId}&limit=500`
).then((res) => res.json());
while (!userInfo.uri) {
userInfo = await fetch(
`https://api-v2.soundcloud.com/resolve?url=${url}&client_id=${clientId}&limit=500`
).then((res) => res.json());
}
const tracksUrl =
userInfo.uri.replace("api.", "api-v2.") +
"/tracks?limit=500&client_id=" +
clientId;
let currentTracks = await fetch(tracksUrl).then((res) => res.json());
playlist = currentTracks.collection;
while (currentTracks.next_href != null) {
currentTracks = await fetch(
currentTracks.next_href + "&client_id=" + clientId
).then((res) => res.json());
playlist = [...playlist, ...currentTracks.collection];
}
} else { } else {
playlist = await fetch( playlist = await fetch(
`https://api-v2.soundcloud.com/resolve?url=${url}&client_id=${clientId}&limit=500` `https://api-v2.soundcloud.com/resolve?url=${url}&client_id=${clientId}&limit=500`