Skip to content

Commit

Permalink
Update ytv2.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SkulZOnTheYT authored Nov 12, 2023
1 parent b509907 commit 6af613a
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions plugins/download/ytv2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ytdl from 'ytdl-core'
import { niceBytes } from '../../lib/func.js'
import { youtubedl } from '@bochilteam/scraper-sosmed'

let handler = async (m, { conn, text, args, usedPrefix, command }) => {
if (!text.match(new RegExp(/(?:https?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed|shorts)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]+)/, 'gi'))) return m.reply(`Invalid Youtube URL.`)
let za = command.includes('480') ? '480' : command.includes('720') ? '720' : '1080'
let za = /360/.test(command) ? '360' : /480/.test(command) ? '480' : command.includes('720') ? '720' : '1080'
try {
let anu = await youtubedl(args[0])
let anu = await outubedl(args[0])
let list = Object.keys(anu.video).toString()
let data = anu.video[`${za}p`]
let url = await data.download()
Expand All @@ -16,15 +18,33 @@ let handler = async (m, { conn, text, args, usedPrefix, command }) => {
await conn.sendFile(m.chat, url, `${anu.title}.mp4`, txt, m)
} catch (e) {
console.log(e)
m.reply(`[!] ${za}p tidak tersedia / terjadi kesalahan.`)
try {
let res = await ytdl.getURLVideoID(args[0])
let anu = await ytdl.getInfo(res)
let det = anu.videoDetails
let data = anu.formats.find(v => v.mimeType.includes('video') && v.audioBitrate !== null && (v.qualityLabel || '').includes(za))
if (!data) throw Error()
let size = parseInt(data.bitrate)
let buffer = Buffer.from(await (await fetch(data.url)).arrayBuffer())
let buffl = Buffer.byteLength(buffer)
if (size > 400000000) return m.reply(`Filesize: ${niceBytes(buffl)}\nTidak dapat mengirim, maksimal file 400 MB`)
let txt = `*${det.title}*\n\n`
+ `⭔ Watch : ${args[0]}\n`
+ `⭔ Resolution : ${data.width} x ${data.height}\n`
+ `⭔ Size : ${niceBytes(buffl)}`
await conn.sendFile(m.chat, buffer, `${det.title}.mp4`, txt, m)
} catch (e) {
console.log(e)
m.reply(`[!] ${za}p tidak tersedia / terjadi kesalahan.`)
}
}
}

handler.help = ['480','720','1080'].map(v => 'ytvideo'+v+' <url>')
handler.tags = ['download']
handler.command = /^(yt(v(ideo)?|mp4)(480|720|1080)p?)$/i
handler.menudownload = ['360','480','720','1080'].map(v => 'ytvideo'+v+' <url>')
handler.tagsdownload = ['search']
handler.command = /^(yt(v(ideo)?|mp4)(360|480|720|1080)p?)$/i

handler.premium = true
handler.premium = false
handler.limit = true

export default handler
export default handler

0 comments on commit 6af613a

Please sign in to comment.