import { maxVideoDuration } from "../../config.js"; let cachedID = {}; async function findClientID() { try { let sc = await fetch('https://soundcloud.com/').then((r) => { return r.text() }).catch(() => { return false }); let scVersion = String(sc.match(/')[0]) if (!json["media"]["transcodings"]) return { error: 'ErrorEmptyDownload' }; let clientId = await findClientID(); if (!clientId) return { error: 'ErrorSoundCloudNoClientId' }; let fileUrlBase = json.media.transcodings[0]["url"].replace("/hls", "/progressive") 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' }; if (json.duration > maxVideoDuration) return { error: ['ErrorLengthAudioConvert', maxVideoDuration / 60000] }; let file = await fetch(fileUrl).then(async (r) => { return (await r.json()).url }).catch(() => { return false }); if (!file) return { error: 'ErrorCouldntFetch' }; return { urls: file, audioFilename: `soundcloud_${json.id}`, fileMetadata: { title: json.title, artist: json.user.username, } } }