//import { youtubedl, youtubedlv2 } from '@bochilteam/scraper' import fetch from 'node-fetch' import yts from 'yt-search' import ytdl from 'ytdl-core' import axios from 'axios' import { createRequire } from 'module'; const require = createRequire(import.meta.url); const { ytmp3, ytmp4 } = require("@hiudyy/ytdl"); let handler = async (m, { conn, args, usedPrefix, command }) => { if (!args[0]) throw '*๐™Œ๐™ช๐™š ๐™š๐™จ๐™ฉ๐™– ๐™—๐™ช๐™จ๐™˜๐™–๐™™๐™ค๐Ÿค” ๐™„๐™ฃ๐™œ๐™ง๐™š๐™จ๐™š ๐™š๐™ก ๐™š๐™ฃ๐™ก๐™–๐™˜๐™š ๐™™๐™š ๐™”๐™ค๐™ช๐™๐™ช๐™—๐™š ๐™ฅ๐™–๐™ง๐™– ๐™™๐™š๐™จ๐™˜๐™–๐™ง๐™œ๐™–๐™ง ๐™š๐™ก ๐™–๐™ช๐™™๐™ž๐™ค*' if (command == 'ytmp3' || command == 'fgmp3') { let youtubeLink = ''; if (args[0].includes('you')) { youtubeLink = args[0]; } else { const index = parseInt(args[0]) - 1; if (index >= 0) { if (Array.isArray(global.videoList) && global.videoList.length > 0) { const matchingItem = global.videoList.find(item => item.from === m.sender); if (matchingItem) { if (index < matchingItem.urls.length) { youtubeLink = matchingItem.urls[index]; } else { throw `โš ๏ธ ๐™‰๐™ค ๐™จ๐™š ๐™š๐™ฃ๐™˜๐™ค๐™ฃ๐™ฉ๐™ง๐™ค ๐™ช๐™ฃ ๐™š๐™ฃ๐™ก๐™–๐™˜๐™š๐™จ ๐™ฅ๐™–๐™ง๐™– ๐™š๐™จ๐™š ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค, ๐™ฅ๐™ค๐™ง ๐™›๐™–๐™ซ๐™ค๐™ง ๐™ž๐™ฃ๐™œ๐™ง๐™š๐™จ๐™š ๐™š๐™ก ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค ๐™š๐™ฃ๐™ฉ๐™ง๐™š 1 ๐™ฎ ๐™š๐™ก ${matchingItem.urls.length}*` }} else { return }} else { return }}} conn.reply(m.chat, [`*โŒ› ๐™€๐™จ๐™ฅ๐™š๐™ง๐™š โœ‹ ๐™ช๐™ฃ ๐™ข๐™ค๐™ข๐™š๐™ฃ๐™ฉ๐™ค... ๐™”๐™– ๐™š๐™จ๐™ฉ๐™ค๐™ฎ ๐™™๐™š๐™จ๐™˜๐™–๐™ง๐™œ๐™–๐™™๐™ค ๐™ฉ๐™ช ๐™–๐™ช๐™™๐™ž๐™ค๐Ÿน*`, `โŒ› ๐™‹๐™๐™Š๐˜พ๐™€๐™Ž๐˜ผ๐™‰๐˜ฟ๐™Š...\n*๐˜Œ๐˜ด๐˜ต๐˜ฐ๐˜บ ๐˜ช๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต๐˜ข๐˜ฏ๐˜ฅ๐˜ฐ ๐˜ฅ๐˜ฆ๐˜ด๐˜ค๐˜ข๐˜ณ๐˜จ๐˜ข ๐˜ด๐˜ถ๐˜ด ๐˜ˆ๐˜ถ๐˜ฅ๐˜ช๐˜ฐ ๐˜ฆ๐˜ด๐˜ฑ๐˜ฆ๐˜ณ๐˜ฆ ๐Ÿƒโ€โ™‚๏ธ๐Ÿ’จ*`, `Calmao pa estoy bucando tu canciรณn ๐Ÿ˜Ž\n\n*Recuerda colocar bien el nombre de la cancion o el link del video de youtube*\n\n> *Si el comando *play no funciona utiliza el comando *ytmp3*`].getRandom(), m, {contextInfo: {externalAdReply :{ mediaUrl: null, mediaType: 1, description: null, title: wm, body: ' ๐Ÿ’ซ ๐’๐ฎ๐ฉ๐ž๐ซ ๐๐จ๐ญ ๐ƒ๐ž ๐–๐ก๐š๐ญ๐ฌ๐š๐ฉ๐ฉ ๐Ÿฅณ ', previewType: 0, thumbnail: img.getRandom(), sourceUrl: redes.getRandom()}}}) try { const audiodlp = await ytmp3(args); conn.sendMessage(m.chat, { audio: audiodlp, mimetype: "audio/mpeg" }, { quoted: m }); } catch { try { const res = await fetch(`https://api.siputzx.my.id/api/d/ytmp3?url=${args}`); let { data } = await res.json(); await conn.sendMessage(m.chat, { audio: { url: data.dl }, mimetype: 'audio/mpeg' }, { quoted: m ||null }); } catch { try { const res = await fetch(`https://api.zenkey.my.id/api/download/ytmp3?apikey=zenkey&url=${args}`) let { result } = await res.json() await conn.sendMessage(m.chat, { audio: { url: await result.download.url }, mimetype: 'audio/mpeg' }, { quoted: m }) } catch { try { const apiUrl = `${apis}/download/ytmp3?url=${args}`; const apiResponse = await fetch(apiUrl); const delius = await apiResponse.json(); if (!delius.status) { return m.react("โŒ")} const downloadUrl = delius.data.download.url; await conn.sendMessage(m.chat, { audio: { url: downloadUrl }, mimetype: 'audio/mpeg' }, { quoted: m }); } catch { try { let q = '128kbps' let v = youtubeLink const yt = await youtubedl(v).catch(async _ => await youtubedlv2(v)) const dl_url = await yt.audio[q].download() const ttl = await yt.title const size = await yt.audio[q].fileSizeH await conn.sendFile(m.chat, dl_url, ttl + '.mp3', null, m, false, { mimetype: 'audio/mp4' }) } catch { try { let searchh = await yts(youtubeLink) let __res = searchh.all.map(v => v).filter(v => v.type == "video") let infoo = await ytdl.getInfo('https://youtu.be/' + __res[0].videoId) let ress = await ytdl.chooseFormat(infoo.formats, { filter: 'audioonly' }) conn.sendMessage(m.chat, { audio: { url: ress.url }, fileName: __res[0].title + '.mp3', mimetype: 'audio/mp4' }, { quoted: m }) } catch { }}}}}}} if (command == 'ytmp4' || command == 'fgmp4') { let youtubeLink = ''; if (args[0].includes('you')) { youtubeLink = args[0]; } else { const index = parseInt(args[0]) - 1; if (index >= 0) { if (Array.isArray(global.videoList) && global.videoList.length > 0) { const matchingItem = global.videoList.find(item => item.from === m.sender); if (matchingItem) { if (index < matchingItem.urls.length) { youtubeLink = matchingItem.urls[index]; } else { throw `โš ๏ธ ๐™‰๐™ค ๐™จ๐™š ๐™š๐™ฃ๐™˜๐™ค๐™ฃ๐™ฉ๐™ง๐™ค ๐™ช๐™ฃ ๐™š๐™ฃ๐™ก๐™–๐™˜๐™š๐™จ ๐™ฅ๐™–๐™ง๐™– ๐™š๐™จ๐™š ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค, ๐™ฅ๐™ค๐™ง ๐™›๐™–๐™ซ๐™ค๐™ง ๐™ž๐™ฃ๐™œ๐™ง๐™š๐™จ๐™š ๐™š๐™ก ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค ๐™š๐™ฃ๐™ฉ๐™ง๐™š 1 ๐™ฎ ๐™š๐™ก ${matchingItem.urls.length}*` }} else { return }} else { return }}} conn.reply(m.chat, [`*โŒ› ๐™”๐™– ๐™š๐™จ๐™ฉ๐™ค๐™ฎ ๐™™๐™š๐™จ๐™˜๐™–๐™ง๐™œ๐™–๐™™๐™ค ๐™ฉ๐™ช ๐™‘๐™ž๐™™๐™š๐™ค ๐Ÿน*`, `โŒ› ๐™‹๐™๐™Š๐˜พ๐™€๐™Ž๐˜ผ๐™‰๐˜ฟ๐™Š...\n*๐˜Œ๐˜ด๐˜ต๐˜ฐ๐˜บ ๐˜ช๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต๐˜ข๐˜ฏ๐˜ฅ๐˜ฐ ๐˜ฅ๐˜ฆ๐˜ด๐˜ค๐˜ข๐˜ณ๐˜จ๐˜ขr ๐˜ด๐˜ถ๐˜ด ๐˜๐˜ช๐˜ฅ๐˜ฆ๐˜ฐ ๐˜ฆ๐˜ด๐˜ฑ๐˜ฆ๐˜ณ๐˜ฆ...*`, `*Estoy descargando tu video ๐Ÿ”„*\n\n> *Aguarde un momento, por favor*`].getRandom(), m, {contextInfo: {externalAdReply :{ mediaUrl: null, mediaType: 1, description: null, title: wm, body: ' ๐Ÿ’ซ ๐’๐ฎ๐ฉ๐ž๐ซ Kantu Bot ๐Ÿฃ ', previewType: 0, thumbnail: img.getRandom(), sourceUrl: redes.getRandom()}}}) try { const video = await ytmp4(args); await conn.sendMessage(m.chat, { video: { url: video }, fileName: `video.mp4`, mimetype: 'video/mp4', caption: `๐Ÿ”ฐ Aquรญ estรก tu video`}, { quoted: m }) } catch { try { const res = await fetch(`https://api.siputzx.my.id/api/d/ytmp4?url=${args}`); let { data } = await res.json(); await conn.sendMessage(m.chat, { video: { url: data.dl }, fileName: `video.mp4`, mimetype: 'video/mp4', caption: `๐Ÿ”ฐ Aquรญ estรก tu video`}, { quoted: m || null }) } catch { try { const res = await fetch(`https://api.zenkey.my.id/api/download/ytmp3?apikey=zenkey&url=${args}`) let { result } = await res.json() await conn.sendMessage(m.chat, { video: { url: result.download.url }, fileName: `video.mp4`, caption: `${wm}` }, { quoted: m }) } catch { try { const axeelApi = `https://axeel.my.id/api/download/video?url=${args}`; const axeelRes = await fetch(axeelApi); const axeelJson = await axeelRes.json(); if (axeelJson && axeelJson.downloads?.url) { const videoUrl = axeelJson.downloads.url; await conn.sendMessage(m.chat, { video: { url: videoUrl }, fileName: `${yt_play[0].title}.mp4`, caption: `๐Ÿ”ฐ Aquรญ estรก tu video \n๐Ÿ”ฅ Tรญtulo: ${yt_play[0].title}` }, { quoted: m }) }} catch { try { let qu = args[1] || '360' let q = qu + 'p' let v = youtubeLink const yt = await youtubedl(v).catch(async _ => await youtubedlv2(v)) const dl_url = await yt.video[q].download() const ttl = await yt.title const size = await yt.video[q].fileSizeH await await conn.sendMessage(m.chat, { video: { url: dl_url }, fileName: `${ttl}.mp4`, mimetype: 'video/mp4', caption: `๐Ÿ”ฐ ๐˜ผ๐™ฆ๐™ช๐™ž ๐™š๐™จ๐™ฉ๐™– ๐™ฉ๐™ช ๐™ซ๐™ž๐™™๐™š๐™ค \n๐Ÿ”ฅ ๐™๐™ž๐™ฉ๐™ช๐™ก๐™ค: ${ttl}`, thumbnail: await fetch(yt.thumbnail) }, { quoted: m }) } catch { try { let mediaa = await ytMp4(youtubeLink) await conn.sendMessage(m.chat, { video: { url: mediaa.result }, fileName: `error.mp4`, caption: `_${wm}_`, thumbnail: mediaa.thumb, mimetype: 'video/mp4' }, { quoted: m }) } catch (e) { console.log(e) }}}}}}}} handler.help = ['ytmp4', 'ytmp3']; handler.tags = ['downloader']; handler.command = /^ytmp3|ytmp4|fgmp4|audio|fgmp3|dlmp3?$/i export default handler function bytesToSize(bytes) { return new Promise((resolve, reject) => { const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes === 0) return 'n/a'; const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10); if (i === 0) resolve(`${bytes} ${sizes[i]}`); resolve(`${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`)})}; async function ytMp3(url) { return new Promise((resolve, reject) => { ytdl.getInfo(url).then(async(getUrl) => { let result = []; for(let i = 0; i < getUrl.formats.length; i++) { let item = getUrl.formats[i]; if (item.mimeType == 'audio/webm; codecs=\"opus\"') { let { contentLength } = item; let bytes = await bytesToSize(contentLength); result[i] = { audio: item.url, size: bytes }}}; let resultFix = result.filter(x => x.audio != undefined && x.size != undefined) let tiny = await axios.get(`https://tinyurl.com/api-create.php?url=${resultFix[0].audio}`); let tinyUrl = tiny.data; let title = getUrl.videoDetails.title; let thumb = getUrl.player_response.microformat.playerMicroformatRenderer.thumbnail.thumbnails[0].url; resolve({ title, result: tinyUrl, result2: resultFix, thumb })}).catch(reject)})} async function ytMp4(url) { return new Promise(async(resolve, reject) => { ytdl.getInfo(url).then(async(getUrl) => { let result = []; for(let i = 0; i < getUrl.formats.length; i++) { let item = getUrl.formats[i]; if (item.container == 'mp4' && item.hasVideo == true && item.hasAudio == true) { let { qualityLabel, contentLength } = item; let bytes = await bytesToSize(contentLength); result[i] = { video: item.url, quality: qualityLabel, size: bytes }}}; let resultFix = result.filter(x => x.video != undefined && x.size != undefined && x.quality != undefined) let tiny = await axios.get(`https://tinyurl.com/api-create.php?url=${resultFix[0].video}`); let tinyUrl = tiny.data; let title = getUrl.videoDetails.title; let thumb = getUrl.player_response.microformat.playerMicroformatRenderer.thumbnail.thumbnails[0].url; resolve({ title, result: tinyUrl, rersult2: resultFix[0].video, thumb })}).catch(reject)})}; async function ytPlay(query) { return new Promise((resolve, reject) => { yts(query).then(async(getData) => { let result = getData.videos.slice( 0, 5 ); let url = []; for (let i = 0; i < result.length; i++) { url.push(result[i].url) } let random = url[0]; let getAudio = await ytMp3(random); resolve(getAudio)}).catch(reject)})}; async function ytPlayVid(query) { return new Promise((resolve, reject) => { yts(query).then(async(getData) => { let result = getData.videos.slice( 0, 5 ); let url = []; for (let i = 0; i < result.length; i++) { url.push(result[i].url) } let random = url[0]; let getVideo = await ytMp4(random); resolve(getVideo)}).catch(reject)})};