diff --git a/plugins/download/ytv.js b/plugins/download/ytv.js index b68ff1c..6438c8c 100644 --- a/plugins/download/ytv.js +++ b/plugins/download/ytv.js @@ -1,3 +1,5 @@ +import ytdl from 'ytdl-core' +import { niceBytes } from '../../lib/func.js' import { youtubedl } from '@bochilteam/scraper-sosmed' let handler = async (m, { conn, args, usedPrefix, command }) => { @@ -9,21 +11,55 @@ let handler = async (m, { conn, args, usedPrefix, command }) => { let url = await data.download() if (data.fileSize > 400000) return m.reply(`Filesize: ${data.fileSizeH}\nTidak dapat mengirim, maksimal file 400 MB`) let txt = `*${anu.title}*\n\n` - txt += `⭔ Watch : ${args[0]}\n` - txt += `⭔ Resolution : ${data.quality}\n` - txt += `⭔ Size : ${data.fileSizeH}` + + `⭔ Watch : ${args[0]}\n` + + `⭔ Resolution : ${data.quality}\n` + + `⭔ Size : ${data.fileSizeH}` await conn.sendFile(m.chat, url, `${anu.title}.mp4`, txt, m) } catch (e) { console.log(e) - m.reply(`Invalid Youtube URL / terjadi kesalahan.`) + try { + let res = await ytdl.getURLVideoID(args[0]) + let anu = await ytdl.getInfo(res) + let data, det = anu.videoDetails + for (let x of ['360','480','240']) { + if (!data) data = anu.formats.find(v => v.mimeType.includes('video') && v.audioBitrate !== null && (v.qualityLabel || '').includes(x)) + } + 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) + try { + let anu = await (await fetch(`https://api.akuari.my.id/downloader/yt1?link=${args[0]}`)).json() + let size = anu.urldl_video.size + let vs = parseInt(size) + if (isNaN(vs)) vs = 1 + if (vs > 400 && /mb|gb/i.test(size)) return m.reply(`Filesize: ${size}\nTidak dapat mengirim, maksimal file 400 MB`) + let txt = `*${anu.info.title}*\n\n` + + `⭔ Watch : ${args[0]}\n` + + `⭔ Resolution : ${anu.urldl_video.quality}\n` + + `⭔ Size : ${size}` + await conn.sendFile(m.chat, anu.urldl_video.link, `${anu.info.title}.mp4`, txt, m) + } catch (e) { + console.log(e) + throw 'invalid url / internal server error.' + } + } } } -handler.help = ['ytvideo '] -handler.tags = ['download'] +handler.menudownload = ['ytvideo '] +handler.tagsdownload = ['search'] handler.command = /^(yt(v(ideo)?|mp4))$/i -handler.premium = true +handler.premium = false handler.limit = true -export default handler \ No newline at end of file +export default handler