-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathytv.js
94 lines (88 loc) · 3.44 KB
/
ytv.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
let fetch = require('node-fetch')
let { JSDOM } = require('jsdom')
let limit = 30
let handler = async (m, { conn, args, isPrems, isOwner }) => {
if (!args || !args[0]) return conn.reply(m.chat, 'Uhm... urlnya mana?', m)
let { dl_link, thumb, title, filesize, filesizeF} = await ytv(args[0])
let isLimit = (isPrems || isOwner ? 99 : limit) * 1024 < filesize
conn.sendFile(m.chat, thumb, 'thumbnail.jpg', `
*Title:* ${title}
*Filesize:* ${filesizeF}
*LAGI DIKIRIM SABAR COY!*
*${isLimit ? 'Pakai ': ''}Link:* ${dl_link}
`.trim(), m)
if (!isLimit) conn.sendFile(m.chat, dl_link, 'video.mp4', `
*Title:* ${title}
*Filesize:* ${filesizeF}
`.trim(), m)
}
handler.help = ['mp4','v',''].map(v => 'yt' + v + ' <url>')
handler.tags = ['downloader']
handler.command = /^yt(v|mp4)?$/i
handler.owner = false
handler.mods = false
handler.premium = false
handler.group = false
handler.private = false
handler.admin = false
handler.botAdmin = false
handler.fail = null
handler.exp = 0
handler.limit = true
module.exports = handler
function post(url, formdata) {
console.log(Object.keys(formdata).map(key => `${key}=${encodeURIComponent(formdata[key])}`).join('&'))
return fetch(url, {
method: 'POST',
headers: {
accept: "*/*",
'accept-language': "en-US,en;q=0.9",
'content-type': "application/x-www-form-urlencoded; charset=UTF-8"
},
body: Object.keys(formdata).map(key => `${key}=${encodeURIComponent(formdata[key])}`).join('&')
})
}
const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)youtube(?:\-nocookie|)\.com\/(?:watch\?.*(?:|\&)v=|embed\/|v\/)|youtu\.be\/)([-_0-9A-Za-z]{11})/
function ytv(url) {
return new Promise((resolve, reject) => {
if (ytIdRegex.test(url)) {
let ytId = ytIdRegex.exec(url)
url = 'https://youtu.be/' + ytId[1]
post('https://www.y2mate.com/mates/id4/analyze/ajax', {
url,
q_auto: 0,
ajax: 1
})
.then(res => res.json())
.then(res => {
console.log('Scraping...')
document = (new JSDOM(res.result)).window.document
yaha = document.querySelectorAll('td')
filesize = yaha[yaha.length - 23].innerHTML
id = /var k__id = "(.*?)"/.exec(document.body.innerHTML) || ['', '']
thumb = document.querySelector('img').src
title = document.querySelector('b').innerHTML
post('https://www.y2mate.com/mates/id4/convert', {
type: 'youtube',
_id: id[1],
v_id: ytId[1],
ajax: '1',
token: '',
ftype: 'mp4',
fquality: 360
})
.then(res => res.json())
.then(res => {
let KB = parseFloat(filesize) * (1000 * /MB$/.test(filesize))
resolve({
dl_link: /<a.+?href="(.+?)"/.exec(res.result)[1],
thumb,
title,
filesizeF: filesize,
filesize: KB
})
}).catch(reject)
}).catch(reject)
} else reject('URL INVALID')
})
}