Skip to content

Instantly share code, notes, and snippets.

@ayashiiiyo
Last active April 19, 2026 13:27
Show Gist options
  • Select an option

  • Save ayashiiiyo/a2ebbfb91349f0db4d4a4058e79b95e6 to your computer and use it in GitHub Desktop.

Select an option

Save ayashiiiyo/a2ebbfb91349f0db4d4a4058e79b95e6 to your computer and use it in GitHub Desktop.
import { load } from 'cheerio'
async function scSearch(q) {
const url = 'https://m.soundcloud.com/search?q=' + encodeURIComponent(q)
const res = await fetch(url, {
headers: {
'user-agent': 'Mozilla/5.0'
}
})
const html = await res.text()
const $ = load(html)
const json = JSON.parse($('#__NEXT_DATA__').text())
const tracks = json.props.pageProps.initialStoreState.entities.tracks
const result = Object.values(tracks)
.filter(v => v && v.data && v.data.title)
.map(v => {
const d = v.data
return {
id: d.id || '-',
title: d.title || '-',
url: d.permalink_url || '-',
user_id: d.user_id || '-',
artwork: d.artwork_url || null,
duration: d.duration || '-',
plays: d.playback_count || '-',
likes: d.likes_count || '-',
comments: d.comment_count || '-',
reposts: d.reposts_count || '-',
created_at: d.created_at || '-'
}
})
return result
}
let handler = async (m, { conn, args, command }) => {
try {
if (!args[0]) return m.reply(`*Example :* .${command} Only We Know`)
m.reply(global.wait)
const data = await scSearch(args.join(' '))
if (!data.length) return m.reply('No result')
let thumb = data.find(v => v.artwork)?.artwork || null
let txt = ''
for (let i = 0; i < data.length; i++) {
txt += `*Title :* ${data[i].title || '-'}\n`
txt += `*Url :* ${data[i].url || '-'}\n`
txt += `*Views :* ${data[i].plays || '-'}\n`
txt += `*Likes :* ${data[i].likes || '-'}\n`
txt += `*Comments :* ${data[i].comments || '-'}\n`
txt += `*Reposts :* ${data[i].reposts || '-'}\n\n`
}
if (thumb) {
await conn.sendMessage(m.chat, {
image: { url: thumb },
caption: txt.trim()
}, { quoted: m })
} else {
await conn.sendMessage(m.chat, {
text: txt.trim()
}, { quoted: m })
}
} catch (e) {
m.reply(e.message)
}
}
handler.help = ['scs <query>', 'soundcloud-s <query>']
handler.command = ['scs', 'soundcloud-s']
handler.tags = ['search']
export default handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment