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' let handler = async (m, { conn, args, usedPrefix, command }) => { if (!args[0]) throw '*š™Œš™Ŗš™š š™šš™Øš™©š™– š™—š™Ŗš™Øš™˜š™–š™™š™¤šŸ¤” š™„š™£š™œš™§š™šš™Øš™š š™šš™” š™šš™£š™”š™–š™˜š™š š™™š™š š™”š™¤š™Ŗš™š™Ŗš™—š™š š™„š™–š™§š™– š™™š™šš™Øš™˜š™–š™§š™œš™–š™§ š™šš™” š™–š™Ŗš™™š™žš™¤*' if (command == 'ytmp3doc') { 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 { throw `āš ļø š™‹š™–š™§š™– š™„š™¤š™™š™šš™§ š™Ŗš™Øš™–š™§ š™šš™Øš™©š™š š™˜š™¤š™¢š™–š™£š™™š™¤ š™™š™š š™šš™Øš™©š™– š™›š™¤š™§š™¢š™– (${usedPrefix + command} ), š™‹š™¤š™§ š™›š™–š™«š™¤š™§ š™§š™šš™–š™”š™žš™Æš™–š™§ š™”š™– š™—š™Ŗš™Øš™¦š™Ŗš™šš™™š™– š™™š™š š™«š™žš™™š™šš™¤š™Ø š™˜š™¤š™£ š™šš™” š™˜š™¤š™¢š™–š™£š™™š™¤ ${usedPrefix}playlist *` }} else { throw `āš ļø š™‹š™–š™§š™– š™„š™¤š™™š™šš™§ š™Ŗš™Øš™–š™§ š™šš™Øš™©š™š š™˜š™¤š™¢š™–š™£š™™š™¤ š™™š™š š™šš™Øš™©š™– š™›š™¤š™§š™¢š™– (${usedPrefix + command} ), š™‹š™¤š™§ š™›š™–š™«š™¤š™§ š™§š™šš™–š™”š™žš™Æš™–š™§ š™”š™– š™—š™Ŗš™Øš™¦š™Ŗš™šš™™š™– š™™š™š š™«š™žš™™š™šš™¤š™Ø š™˜š™¤š™£ š™šš™” š™˜š™¤š™¢š™–š™£š™™š™¤ ${usedPrefix}playlist *` }}} conn.reply(m.chat, [`*āŒ› š™€š™Øš™„š™šš™§š™š āœ‹ š™Ŗš™£ š™¢š™¤š™¢š™šš™£š™©š™¤... š™”š™– š™šš™Øš™©š™¤š™® š™™š™šš™Øš™˜š™–š™§š™œš™–š™™š™¤ š™©š™Ŗ š™–š™Ŗš™™š™žš™¤šŸ¹*`, `āŒ› š™‹š™š™Šš˜¾š™€š™Žš˜¼š™‰š˜æš™Š...\n*š˜Œš˜“š˜µš˜°š˜ŗ š˜Ŗš˜Æš˜µš˜¦š˜Æš˜µš˜¢š˜Æš˜„š˜° š˜„š˜¦š˜“š˜¤š˜¢š˜³š˜Øš˜¢ š˜“š˜¶š˜“ š˜ˆš˜¶š˜„š˜Ŗš˜° š˜¦š˜“š˜±š˜¦š˜³š˜¦ šŸƒā€ā™‚ļøšŸ’Ø*`].getRandom(), m, {contextInfo: {externalAdReply :{ mediaUrl: null, mediaType: 1, description: null, title: wm, body: ' šŸ’« š’š®š©šžš« ššØš­ šƒšž š–š”ššš­š¬ššš©š© 🄳 ', previewType: 0, thumbnail: img.getRandom(), sourceUrl: redes.getRandom()}}}) 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.sendMessage(m.chat, { document: { url: dl_url }, fileName: `${ttl}.mp3`, mimetype: 'audio/mp4' }, { quoted: m }) //conn.sendFile(m.chat, dl_url, ttl + '.mp3', null, m, false, { mimetype: 'audio/mp4' }) } catch { try { let lolhuman = await fetch(`https://api.lolhuman.xyz/api/ytaudio2?apikey=${lolkeysapi}&url=${youtubeLink}`) let lolh = await lolhuman.json() let n = lolh.result.title || 'error' await conn.sendMessage(m.chat, { document: { url: lolh.result.link }, fileName: `${n}.mp3`, mimetype: 'audio/mp4' }, { quoted: m }) } 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, { document: { 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 { throw `āš ļø š™‹š™–š™§š™– š™„š™¤š™™š™šš™§ š™Ŗš™Øš™–š™§ š™šš™Øš™©š™š š™˜š™¤š™¢š™–š™£š™™š™¤ š™™š™š š™šš™Øš™©š™– š™›š™¤š™§š™¢š™– (${usedPrefix + command} ), š™‹š™¤š™§ š™›š™–š™«š™¤š™§ š™§š™šš™–š™”š™žš™Æš™–š™§ š™”š™– š™—š™Ŗš™Øš™¦š™Ŗš™šš™™š™– š™™š™š š™«š™žš™™š™šš™¤š™Ø š™˜š™¤š™£ š™šš™” š™˜š™¤š™¢š™–š™£š™™š™¤ ${usedPrefix}playlist *` }} else { throw `āš ļø š™‹š™–š™§š™– š™„š™¤š™™š™šš™§ š™Ŗš™Øš™–š™§ š™šš™Øš™©š™š š™˜š™¤š™¢š™–š™£š™™š™¤ š™™š™š š™šš™Øš™©š™– š™›š™¤š™§š™¢š™– (${usedPrefix + command} ), š™‹š™¤š™§ š™›š™–š™«š™¤š™§ š™§š™šš™–š™”š™žš™Æš™–š™§ š™”š™– š™—š™Ŗš™Øš™¦š™Ŗš™šš™™š™– š™™š™š š™«š™žš™™š™šš™¤š™Ø š™˜š™¤š™£ š™šš™” š™˜š™¤š™¢š™–š™£š™™š™¤ ${usedPrefix}playlist *` }}} conn.reply(m.chat, [`*āŒ› š™”š™– š™šš™Øš™©š™¤š™® š™™š™šš™Øš™˜š™–š™§š™œš™–š™™š™¤ š™©š™Ŗ š™‘š™žš™™š™šš™¤ šŸ¹*`, `āŒ› š™‹š™š™Šš˜¾š™€š™Žš˜¼š™‰š˜æš™Š...\n*š˜Œš˜“š˜µš˜°š˜ŗ š˜Ŗš˜Æš˜µš˜¦š˜Æš˜µš˜¢š˜Æš˜„š˜° š˜„š˜¦š˜“š˜¤š˜¢š˜³š˜Øš˜¢ š˜“š˜¶š˜“ š˜š˜Ŗš˜„š˜¦o...*`].getRandom(), m, {contextInfo: {externalAdReply :{ mediaUrl: null, mediaType: 1, description: null, title: wm, body: ' ⚔ š’š®š©šžš« Kantu Bot 🐣 ', previewType: 0, thumbnail: img.getRandom(), sourceUrl: redes.getRandom()}}}) 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, { document: { url: dl_url }, fileName: `${ttl}.mp4`, mimetype: 'video/mp4', caption: `šŸ”° š˜¼š™¦š™Ŗš™ž š™šš™Øš™©š™– š™©š™Ŗ š™«š™žš™™š™šš™¤ \nšŸ”„ š™š™žš™©š™Ŗš™”š™¤: ${ttl}`, thumbnail: await fetch(yt.thumbnail) }, { quoted: m }) } catch (E1) { //console.log('Error 1 ' + E1) try { let mediaa = await ytMp4(youtubeLink) await conn.sendMessage(m.chat, { document: { url: mediaa.result }, fileName: `error.mp4`, caption: `_${wm}_`, thumbnail: mediaa.thumb, mimetype: 'video/mp4' }, { quoted: m }) } catch (E2) { //console.log('Error 2 ' + E2) try { let lolhuman = await fetch(`https://api.lolhuman.xyz/api/ytvideo2?apikey=${lolkeysapi}&url=${youtubeLink}`) let lolh = await lolhuman.json() let n = lolh.result.title || 'error' let n2 = lolh.result.link let n3 = lolh.result.size let n4 = lolh.result.thumbnail await conn.sendMessage(m.chat, { document: { url: n2 }, fileName: `${n}.mp4`, mimetype: 'video/mp4', caption: `šŸ”° š˜¼š™¦š™Ŗš™ž š™šš™Øš™©š™– š™©š™Ŗ š™«š™žš™™š™šš™¤ \nšŸ”„ š™š™žš™©š™Ŗš™”š™¤: ${n}`, thumbnail: await fetch(n4) }, { quoted: m }) } catch (E3) { //console.log('Error 3 ' + E3) }}}}} handler.help = ['ytmp4doc', 'ytmp3doc']; handler.tags = ['downloader']; handler.command = /^ytmp3doc|ytmp4doc?$/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)})};