(sock: any, message: any, args: any, context: BotContext)
| 9 | usage: '.scloud <song name>', |
| 10 | |
| 11 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 12 | const chatId = context.chatId || message.key.remoteJid; |
| 13 | const searchQuery = args.join(' ').trim(); |
| 14 | |
| 15 | try { |
| 16 | if (!searchQuery) { |
| 17 | return await sock.sendMessage(chatId, { |
| 18 | text: "*What do you want to search on SoundCloud?*\nUsage: .soundcloud <song name>\n\nExample: .soundcloud never gonna give you up" |
| 19 | }, { quoted: message }); |
| 20 | } |
| 21 | |
| 22 | await new Promise(resolve => setTimeout(resolve, 10000)); |
| 23 | |
| 24 | const searchUrl = `https://discardapi.dpdns.org/api/search/soundcloud?apikey=guru&query=${encodeURIComponent(searchQuery)}`; |
| 25 | const response = await axios.get(searchUrl, { timeout: 30000 }); |
| 26 | |
| 27 | if (!response.data?.result?.result || response.data.result.result.length === 0) { |
| 28 | return await sock.sendMessage(chatId, { |
| 29 | text: "❌ *No results found!*\nTry a different search term." |
| 30 | }, { quoted: message }); |
| 31 | } |
| 32 | |
| 33 | const results = response.data.result.result; |
| 34 | const totalFound = results.length; |
| 35 | |
| 36 | const tracks = results.filter((item: any) => item.kind === 'track'); |
| 37 | |
| 38 | if (tracks.length === 0) { |
| 39 | return await sock.sendMessage(chatId, { |
| 40 | text: "❌ *No tracks found!*\nOnly found user profiles. Try searching for specific songs." |
| 41 | }, { quoted: message }); |
| 42 | } |
| 43 | |
| 44 | const limit = Math.min(5, tracks.length); |
| 45 | |
| 46 | let resultText = `🎵 *SoundCloud Results*\n`; |
| 47 | resultText += `📊 Found ${totalFound} results (${tracks.length} tracks)\n\n`; |
| 48 | |
| 49 | for (let i = 0; i < limit; i++) { |
| 50 | const track = tracks[i]; |
| 51 | const duration = Math.floor(track.duration / 1000); |
| 52 | const minutes = Math.floor(duration / 60); |
| 53 | const seconds = duration % 60; |
| 54 | |
| 55 | resultText += `*${i + 1}. ${track.title}*\n`; |
| 56 | resultText += `👤 Artist: ${track.user_id ? 'Available' : 'Unknown'}\n`; |
| 57 | resultText += `⏱️ Duration: ${minutes}:${seconds.toString().padStart(2, '0')}\n`; |
| 58 | resultText += `👂 Plays: ${track.playback_count?.toLocaleString() || 'N/A'}\n`; |
| 59 | resultText += `❤️ Likes: ${track.likes_count?.toLocaleString() || 'N/A'}\n`; |
| 60 | resultText += `💬 Comments: ${track.comment_count?.toLocaleString() || 'N/A'}\n`; |
| 61 | resultText += `🎼 Genre: ${track.genre || 'Unknown'}\n`; |
| 62 | resultText += `🔗 Link: ${track.permalink_url}\n\n`; |
| 63 | } |
| 64 | |
| 65 | if (tracks.length > limit) { |
| 66 | resultText += `_+${tracks.length - limit} more tracks available_`; |
| 67 | } |
| 68 |
nothing calls this directly
no outgoing calls
no test coverage detected