Back to Library
Scrape SoundCloud
js • 1/26/2026
7
const axios = require("axios")
async function soundcloud(q) {
try {
const baseUrl = "https://api-mobi.soundcloud.com/search"
const params = {
q: q,
client_id: "KKzJxmw11tYpCs6T24P4uUYhqmjalG6M",
stage: "",
}
const headers = {
Accept: "application/json, text/javascript, */*; q=0.1",
"Content-Type": "application/json",
"User-Agent":
"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Mobile Safari/537.36",
Referer: `https://m.soundcloud.com/search?q=${encodeURIComponent(q)}`,
}
const response = await axios({
method: "get",
url: baseUrl,
params: params,
headers: headers,
timeout: 30000,
})
const data = response.data.collection || []
if (!data.length) throw new Error("No result found")
const result = data.map((item) => ({
title: item.title,
genre: item.genre,
created_at: item.created_at,
duration: item.duration,
permalink: cleanFilename(item.permalink),
comment_count: item.comment_count,
artwork_url: item.artwork_url,
permalink_url: item.permalink_url,
playback_count: item.playback_count,
user: item.user ? item.user.username : null,
}))
return result
} catch (error) {
console.error("SoundCloud API Error:", error.message)
throw new Error("Failed to fetch SoundCloud results")
}
}
function cleanFilename(filename) {
return filename
.replace(/[<>:"/\\|?*]/g, "_")
.replace(/-/g, " ")
.replace(/\s+/g, " ")
.trim()
}
module.exports = soundcloud