File size: 2,935 Bytes
d966349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const axios = require('axios')


function tokenizer(uzido, ndbz) {
    if (eval(atob(uzido.t[0])) == uzido.t[1]) {
        for (var c = 0; c < atob(uzido[0]).split(uzido.f[5]).length; c++) ndbz += (0 < nyxz.f[4] ? nyxz[1].split("").reverse().join("") : nyxz[1])[atob(nyxz[0]).split(nyxz.f[5])[c] - nyxz.f[3]];
        return 1 == uzido.f[1] ? ndbz = ndbz.toLowerCase() : 2 == nyxz.f[1] && (ndbz = ndbz.toUpperCase()), 0 < nyxz.f[0].length ? nyxz.f[0] : 0 < nyxz.f[2] ? ndbz.substring(0, nyxz.f[2] + 1) : ndbz
    }
}
/* ndbotz */

const headers = {
    'Accept': '*/*',
    'Accept-Language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Origin': 'https://ytmp3.gs',
    'Pragma': 'no-cache',
    'Referer': 'https://ytmp3.gs/', 
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'cross-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.3',
    'sec-ch-ua': '"Not-A.Brand";v="99", "Chromium";v="124"',
    'sec-ch-ua-mobile': '?1',
    'sec-ch-ua-platform': '"Windows"'
};

const yt = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(?:embed\/)?(?:v\/)?(?:shorts\/)?([a-zA-Z0-9_-]{11})/;
/* ndbotz */

async function ytdl(url, type = 'mp3') {
  if (!yt.test(url)) { 
    throw new Error('Link ga valid kak');
  };
/* ndbotz */
  if (!['mp3', 'mp4'].includes(type)) {
    throw new Error('Type ga valid kak');
  };

  try {
    const vidId = url.match(yt)[3];
    const webb = await axios.get('https://ytmp3.cc/Vluk/', { headers });
/* ndbotz */
    const tokenJson = JSON.parse(atob(webb.data?.match(/atob\('(.*?)'\)/)?.[1]).match(/var gC = ({[\s\S]*?});/)?.[1]); 
    const token = btoa(tokenJson[2] + "-" + tokenizer(tokenJson, tokenJson.f[6]))

    const init = await axios.get(`https://d.ecoe.cc/api/v1/init?k=${token}&_=${Math.random()}`, { headers }).then(x => x.data);
    const convert = await axios.get(`${init.convertURL}&v=https://www.youtube.com/watch?v=${vidId}&f=${type}&_=${Math.random()}`, { headers }).then(x => x.data);

    if (convert.redirectURL) {
      const res = await axios.get(convert.redirectURL, { headers }).then(x => x.data);

      return {
        type,
        title: res.title,
        link: res.downloadURL
      };
    } else {/* uziproject */
      let res, retry = 0;
      do {
        if (retry > 50) throw 'Timeout';
        res = await axios.get(convert.progressURL, { headers }).then(x => x.data);
        await new Promise(rv => setTimeout(rv, 1000));
        retry++
      } while (res.progress < 3);
      return {
        type,
        title: res.title,
        link: convert.downloadURL
      };
    };
  } catch(e) {
    let err = new Error(`Eror bang, nanti aja download nya, nih log eror nya: ${e.message}`); err.error = e;
    throw err
  }
}

module.exports = ytdl