| 2 | import cheerio from 'cheerio' |
| 3 | |
| 4 | const ytv = async yutub => { |
| 5 | function post(url, formdata) { |
| 6 | return fetch(url, { |
| 7 | method: 'POST', |
| 8 | headers: { |
| 9 | accept: '*/*', |
| 10 | 'accept-language': 'en-US,en;q=0.9', |
| 11 | 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', |
| 12 | }, |
| 13 | body: new URLSearchParams(Object.entries(formdata)), |
| 14 | }) |
| 15 | } |
| 16 | const ytIdRegex = |
| 17 | /(?:http(?:s|):\/\/|)(?:(?:www\.|)youtube(?:\-nocookie|)\.com\/(?:watch\?.*(?:|\&)v=|embed\/|v\/)|youtu\.be\/)([-_0-9A-Za-z]{11})/ |
| 18 | let ytId = ytIdRegex.exec(yutub) |
| 19 | let url = 'https://youtu.be/' + ytId[1] |
| 20 | let res = await post(`https://www.y2mate.com/mates/en68/analyze/ajax`, { |
| 21 | url, |
| 22 | q_auto: 0, |
| 23 | ajax: 1, |
| 24 | }) |
| 25 | const mela = await res.json() |
| 26 | const $ = cheerio.load(mela.result) |
| 27 | const hasil = [] |
| 28 | let thumb = $('div').find('.thumbnail.cover > a > img').attr('src') |
| 29 | let title = $('div').find('.thumbnail.cover > div > b').text() |
| 30 | let quality = $('div') |
| 31 | .find('#mp4 > table > tbody > tr:nth-child(4) > td:nth-child(3) > a') |
| 32 | .attr('data-fquality') |
| 33 | let tipe = $('div') |
| 34 | .find('#mp4 > table > tbody > tr:nth-child(3) > td:nth-child(3) > a') |
| 35 | .attr('data-ftype') |
| 36 | let output = `${title}.` + tipe |
| 37 | let size = $('div').find('#mp4 > table > tbody > tr:nth-child(2) > td:nth-child(2)').text() |
| 38 | let id = /var k__id = "(.*?)"/.exec(mela.result)[1] |
| 39 | let res2 = await post(`https://www.y2mate.com/mates/en68/convert`, { |
| 40 | type: 'youtube', |
| 41 | _id: id, |
| 42 | v_id: ytId[1], |
| 43 | ajax: '1', |
| 44 | token: '', |
| 45 | ftype: tipe, |
| 46 | fquality: quality, |
| 47 | }) |
| 48 | const meme = await res2.json() |
| 49 | const supp = cheerio.load(meme.result) |
| 50 | let link = supp('div').find('a').attr('href') |
| 51 | hasil.push({ thumb, title, quality, tipe, size, output, link }) |
| 52 | return hasil[0] |
| 53 | } |
| 54 | |
| 55 | const yta = async yutub => { |
| 56 | function post(url, formdata) { |