fix soundcloud bug

This commit is contained in:
aria blue
2024-04-11 13:30:06 -04:00
parent 9bcb96a062
commit 52893fd615
2 changed files with 15 additions and 4 deletions

11
run.js Normal file
View File

@@ -0,0 +1,11 @@
import Lucida from './build/index.js';
import Soundcloud from './build/streamers/soundcloud/main.js'
const lucida = new Lucida({
modules: {
soundcloud: new Soundcloud({"oauthToken": "2-294707-1346470389-4thCm1p3QnA05"})
},
logins: {}
});
console.log(await lucida.search("ram ranch"))

View File

@@ -55,11 +55,10 @@ export default class Soundcloud implements Streamer {
if (!response.ok) { if (!response.ok) {
const errMsg = await response.text() const errMsg = await response.text()
try { try {
console.error('Soundcloud error response:', JSON.parse(errMsg)) throw new Error(JSON.parse(errMsg))
} catch (error) { } catch (error) {
console.error('Soundcloud error response:', errMsg) throw new Error(errMsg);
} }
throw new Error(`Searching Soundcloud failed with status code ${response.status}.`)
} }
const resultResponse = <RawSearchResults>await response.json() const resultResponse = <RawSearchResults>await response.json()
@@ -233,7 +232,8 @@ async function fetchKey(response: string) {
if (typeof streamKey == 'string') continue if (typeof streamKey == 'string') continue
const key = keys[i].split(`"`)[0] const key = keys[i].split(`"`)[0]
if (!key.startsWith('https://a-v2.sndcdn.com/assets/50-')) continue const keyregex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/
if (!keyregex.test(key)) continue
const script = await (await fetch(key)).text() const script = await (await fetch(key)).text()
if (script.split(`,client_id:"`).length > 1 && !streamKey) { if (script.split(`,client_id:"`).length > 1 && !streamKey) {