const axios = require('axios'); const qs = require('querystring'); const client = axios.create({ baseURL: 'https://www.tubeninja.net', headers: { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36', 'Accept': '*/*', 'Accept-Language': 'en-US,en;q=0.9,id-ID;q=0.8,id;q=0.7', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest', 'Origin': 'https://www.tubeninja.net', 'sec-ch-ua': '"Chromium";v="137", "Not/A)Brand";v="24"', 'sec-ch-ua-mobile': '?1', 'sec-ch-ua-platform': '"Android"' }, withCredentials: true }); client.interceptors.response.use(res => { const cookies = res.headers['set-cookie']; if (cookies && cookies.length) { const cookieString = cookies.map(c => c.split(';')[0]).join('; '); client.defaults.headers.common['Cookie'] = cookieString; } return res; }); async function getCsrf() { await client.get('/welcome'); const cookie = client.defaults.headers.common['Cookie'] || ''; return { csrf: cookie.match(/csrftoken=([^;]+)/)?.[1] || '', ga: cookie.match(/_ga=([^;]+)/)?.[1] || '', ga2: cookie.match(/_ga_LJ99WGV91T=([^;]+)/)?.[1] || '' }; } function tubeninja(url) { getCsrf().then(({ csrf, ga, ga2 }) => { const data = { url: url, csrfmiddlewaretoken: csrf }; client.post('/get', qs.stringify(data), { headers: { 'Cookie': 'csrftoken=' + csrf + '; _ga=' + ga + '; _ga_LJ99WGV91T=' + ga2, 'Referer': 'https://www.tubeninja.net/welcome?url=' + encodeURIComponent(url) } }).then(res => { const html = res.data; const urls = html.match(/https?:\/\/[^\s"'<>]+\.(mp3|mp4|m4a|webm|jpg|jpeg|png|gif)[^\s"'<>]*/gi) || []; const unique = [...new Set(urls)]; unique.forEach(u => console.log(u)); }).catch(err => console.error(err.message)); }).catch(err => console.error(err.message)); } tubeninja('https://on.soundcloud.com/wB4uEh8FtTLvVscRqr');