Update lib/yt.js
Browse files
lib/yt.js
CHANGED
|
@@ -1,35 +1,42 @@
|
|
| 1 |
const axios = require('axios');
|
| 2 |
const cheerio = require('cheerio');
|
| 3 |
|
| 4 |
-
async function
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
'Sec-Fetch-Mode': 'cors',
|
| 18 |
-
'Sec-Fetch-Site': 'same-site',
|
| 19 |
-
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36',
|
| 20 |
-
'sec-ch-ua': '"Not A(Brand";v="8", "Chromium";v="132"',
|
| 21 |
-
'sec-ch-ua-mobile': '?1',
|
| 22 |
-
'sec-ch-ua-platform': '"Android"'
|
| 23 |
-
},
|
| 24 |
-
data: `url=${encodeURIComponent(url)}&format=${encodeURIComponent(format)}&lang=${encodeURIComponent(lang)}&subscribed=${encodeURIComponent(subscribed)}`,
|
| 25 |
-
responseType: 'json'
|
| 26 |
-
});
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
};
|
| 34 |
|
| 35 |
async function tiktok(url) {
|
|
|
|
| 1 |
const axios = require('axios');
|
| 2 |
const cheerio = require('cheerio');
|
| 3 |
|
| 4 |
+
async function yt(url, format) {
|
| 5 |
+
const headers = {
|
| 6 |
+
"accept": "*/*",
|
| 7 |
+
"accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
|
| 8 |
+
"sec-ch-ua": "\"Not A(Brand\";v=\"8\", \"Chromium\";v=\"132\"",
|
| 9 |
+
"sec-ch-ua-mobile": "?1",
|
| 10 |
+
"sec-ch-ua-platform": "\"Android\"",
|
| 11 |
+
"sec-fetch-dest": "empty",
|
| 12 |
+
"sec-fetch-mode": "cors",
|
| 13 |
+
"sec-fetch-site": "cross-site",
|
| 14 |
+
"Referer": "https://id.ytmp3.mobi/",
|
| 15 |
+
"Referrer-Policy": "strict-origin-when-cross-origin"
|
| 16 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
const initial = await fetch(`https://d.ymcdn.org/api/v1/init?p=y&23=1llum1n471&_=${Math.random()}`, {headers});
|
| 19 |
+
let format = format || 'mp3'; //mp3
|
| 20 |
+
const init = await initial.json();
|
| 21 |
+
console.log(init)
|
| 22 |
+
|
| 23 |
+
const id = url.match(/(?:youtu\.be\/|youtube\.com\/(?:.*v=|.*\/|.*embed\/))([^&?/]+)/)?.[1];
|
| 24 |
+
let convertURL = init.convertURL + `&v=${id}&f=${format}&_=${Math.random()}`;
|
| 25 |
+
//console.log(convertURL)
|
| 26 |
+
|
| 27 |
+
const converts = await fetch(convertURL, {headers});
|
| 28 |
+
const convert = await converts.json();
|
| 29 |
+
//console.log(convert)
|
| 30 |
+
|
| 31 |
+
let info = {};
|
| 32 |
+
for (let i = 0; i < 3; i++ ){
|
| 33 |
+
let j = await fetch(convert.progressURL, {headers});
|
| 34 |
+
info = await j.json();
|
| 35 |
+
console.log(info);
|
| 36 |
+
if (info.progress == 3) break;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
return { url: convert.downloadURL };
|
| 40 |
};
|
| 41 |
|
| 42 |
async function tiktok(url) {
|