descargas-play2.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //import { youtubedl, youtubedlv2 } from '@bochilteam/scraper'
  2. import fetch from 'node-fetch'
  3. import yts from 'yt-search'
  4. import ytdl from 'ytdl-core'
  5. import axios from 'axios'
  6. import { createRequire } from 'module';
  7. const require = createRequire(import.meta.url);
  8. const { ytmp3, ytmp4 } = require("@hiudyy/ytdl");
  9. let handler = async (m, { conn, args, usedPrefix, command }) => {
  10. if (!args[0]) throw '*๐™Œ๐™ช๐™š ๐™š๐™จ๐™ฉ๐™– ๐™—๐™ช๐™จ๐™˜๐™–๐™™๐™ค๐Ÿค” ๐™„๐™ฃ๐™œ๐™ง๐™š๐™จ๐™š ๐™š๐™ก ๐™š๐™ฃ๐™ก๐™–๐™˜๐™š ๐™™๐™š ๐™”๐™ค๐™ช๐™๐™ช๐™—๐™š ๐™ฅ๐™–๐™ง๐™– ๐™™๐™š๐™จ๐™˜๐™–๐™ง๐™œ๐™–๐™ง ๐™š๐™ก ๐™–๐™ช๐™™๐™ž๐™ค*'
  11. if (command == 'ytmp3' || command == 'fgmp3') {
  12. let youtubeLink = '';
  13. if (args[0].includes('you')) {
  14. youtubeLink = args[0];
  15. } else {
  16. const index = parseInt(args[0]) - 1;
  17. if (index >= 0) {
  18. if (Array.isArray(global.videoList) && global.videoList.length > 0) {
  19. const matchingItem = global.videoList.find(item => item.from === m.sender);
  20. if (matchingItem) {
  21. if (index < matchingItem.urls.length) {
  22. youtubeLink = matchingItem.urls[index];
  23. } else {
  24. throw `โš ๏ธ ๐™‰๐™ค ๐™จ๐™š ๐™š๐™ฃ๐™˜๐™ค๐™ฃ๐™ฉ๐™ง๐™ค ๐™ช๐™ฃ ๐™š๐™ฃ๐™ก๐™–๐™˜๐™š๐™จ ๐™ฅ๐™–๐™ง๐™– ๐™š๐™จ๐™š ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค, ๐™ฅ๐™ค๐™ง ๐™›๐™–๐™ซ๐™ค๐™ง ๐™ž๐™ฃ๐™œ๐™ง๐™š๐™จ๐™š ๐™š๐™ก ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค ๐™š๐™ฃ๐™ฉ๐™ง๐™š 1 ๐™ฎ ๐™š๐™ก ${matchingItem.urls.length}*`
  25. }} else {
  26. return
  27. }} else {
  28. return
  29. }}}
  30. 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()}}})
  31. try {
  32. const audiodlp = await ytmp3(args);
  33. conn.sendMessage(m.chat, { audio: audiodlp, mimetype: "audio/mpeg" }, { quoted: m });
  34. } catch {
  35. try {
  36. const res = await fetch(`https://api.siputzx.my.id/api/d/ytmp3?url=${args}`);
  37. let { data } = await res.json();
  38. await conn.sendMessage(m.chat, { audio: { url: data.dl }, mimetype: 'audio/mpeg' }, { quoted: m ||null });
  39. } catch {
  40. try {
  41. const res = await fetch(`https://api.zenkey.my.id/api/download/ytmp3?apikey=zenkey&url=${args}`)
  42. let { result } = await res.json()
  43. await conn.sendMessage(m.chat, { audio: { url: await result.download.url }, mimetype: 'audio/mpeg' }, { quoted: m })
  44. } catch {
  45. try {
  46. const apiUrl = `${apis}/download/ytmp3?url=${args}`;
  47. const apiResponse = await fetch(apiUrl);
  48. const delius = await apiResponse.json();
  49. if (!delius.status) {
  50. return m.react("โŒ")}
  51. const downloadUrl = delius.data.download.url;
  52. await conn.sendMessage(m.chat, { audio: { url: downloadUrl }, mimetype: 'audio/mpeg' }, { quoted: m });
  53. } catch {
  54. try {
  55. let q = '128kbps'
  56. let v = youtubeLink
  57. const yt = await youtubedl(v).catch(async _ => await youtubedlv2(v))
  58. const dl_url = await yt.audio[q].download()
  59. const ttl = await yt.title
  60. const size = await yt.audio[q].fileSizeH
  61. await conn.sendFile(m.chat, dl_url, ttl + '.mp3', null, m, false, { mimetype: 'audio/mp4' })
  62. } catch {
  63. try {
  64. let searchh = await yts(youtubeLink)
  65. let __res = searchh.all.map(v => v).filter(v => v.type == "video")
  66. let infoo = await ytdl.getInfo('https://youtu.be/' + __res[0].videoId)
  67. let ress = await ytdl.chooseFormat(infoo.formats, { filter: 'audioonly' })
  68. conn.sendMessage(m.chat, { audio: { url: ress.url }, fileName: __res[0].title + '.mp3', mimetype: 'audio/mp4' }, { quoted: m })
  69. } catch {
  70. }}}}}}}
  71. if (command == 'ytmp4' || command == 'fgmp4') {
  72. let youtubeLink = '';
  73. if (args[0].includes('you')) {
  74. youtubeLink = args[0];
  75. } else {
  76. const index = parseInt(args[0]) - 1;
  77. if (index >= 0) {
  78. if (Array.isArray(global.videoList) && global.videoList.length > 0) {
  79. const matchingItem = global.videoList.find(item => item.from === m.sender);
  80. if (matchingItem) {
  81. if (index < matchingItem.urls.length) {
  82. youtubeLink = matchingItem.urls[index];
  83. } else {
  84. throw `โš ๏ธ ๐™‰๐™ค ๐™จ๐™š ๐™š๐™ฃ๐™˜๐™ค๐™ฃ๐™ฉ๐™ง๐™ค ๐™ช๐™ฃ ๐™š๐™ฃ๐™ก๐™–๐™˜๐™š๐™จ ๐™ฅ๐™–๐™ง๐™– ๐™š๐™จ๐™š ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค, ๐™ฅ๐™ค๐™ง ๐™›๐™–๐™ซ๐™ค๐™ง ๐™ž๐™ฃ๐™œ๐™ง๐™š๐™จ๐™š ๐™š๐™ก ๐™ฃ๐™ช๐™ข๐™š๐™ง๐™ค ๐™š๐™ฃ๐™ฉ๐™ง๐™š 1 ๐™ฎ ๐™š๐™ก ${matchingItem.urls.length}*`
  85. }} else {
  86. return
  87. }} else {
  88. return
  89. }}}
  90. 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()}}})
  91. try {
  92. const video = await ytmp4(args);
  93. await conn.sendMessage(m.chat, { video: { url: video }, fileName: `video.mp4`, mimetype: 'video/mp4', caption: `๐Ÿ”ฐ Aquรญ estรก tu video`}, { quoted: m })
  94. } catch {
  95. try {
  96. const res = await fetch(`https://api.siputzx.my.id/api/d/ytmp4?url=${args}`);
  97. let { data } = await res.json();
  98. await conn.sendMessage(m.chat, { video: { url: data.dl }, fileName: `video.mp4`, mimetype: 'video/mp4', caption: `๐Ÿ”ฐ Aquรญ estรก tu video`}, { quoted: m || null })
  99. } catch {
  100. try {
  101. const res = await fetch(`https://api.zenkey.my.id/api/download/ytmp3?apikey=zenkey&url=${args}`)
  102. let { result } = await res.json()
  103. await conn.sendMessage(m.chat, { video: { url: result.download.url }, fileName: `video.mp4`, caption: `${wm}` }, { quoted: m })
  104. } catch {
  105. try {
  106. const axeelApi = `https://axeel.my.id/api/download/video?url=${args}`;
  107. const axeelRes = await fetch(axeelApi);
  108. const axeelJson = await axeelRes.json();
  109. if (axeelJson && axeelJson.downloads?.url) {
  110. const videoUrl = axeelJson.downloads.url;
  111. 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 })
  112. }} catch {
  113. try {
  114. let qu = args[1] || '360'
  115. let q = qu + 'p'
  116. let v = youtubeLink
  117. const yt = await youtubedl(v).catch(async _ => await youtubedlv2(v))
  118. const dl_url = await yt.video[q].download()
  119. const ttl = await yt.title
  120. const size = await yt.video[q].fileSizeH
  121. 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 })
  122. } catch {
  123. try {
  124. let mediaa = await ytMp4(youtubeLink)
  125. await conn.sendMessage(m.chat, { video: { url: mediaa.result }, fileName: `error.mp4`, caption: `_${wm}_`, thumbnail: mediaa.thumb, mimetype: 'video/mp4' }, { quoted: m })
  126. } catch (e) {
  127. console.log(e)
  128. }}}}}}}}
  129. handler.help = ['ytmp4', 'ytmp3'];
  130. handler.tags = ['downloader'];
  131. handler.command = /^ytmp3|ytmp4|fgmp4|audio|fgmp3|dlmp3?$/i
  132. export default handler
  133. function bytesToSize(bytes) {
  134. return new Promise((resolve, reject) => {
  135. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  136. if (bytes === 0) return 'n/a';
  137. const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
  138. if (i === 0) resolve(`${bytes} ${sizes[i]}`);
  139. resolve(`${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`)})};
  140. async function ytMp3(url) {
  141. return new Promise((resolve, reject) => {
  142. ytdl.getInfo(url).then(async(getUrl) => {
  143. let result = [];
  144. for(let i = 0; i < getUrl.formats.length; i++) {
  145. let item = getUrl.formats[i];
  146. if (item.mimeType == 'audio/webm; codecs=\"opus\"') {
  147. let { contentLength } = item;
  148. let bytes = await bytesToSize(contentLength);
  149. result[i] = { audio: item.url, size: bytes }}};
  150. let resultFix = result.filter(x => x.audio != undefined && x.size != undefined)
  151. let tiny = await axios.get(`https://tinyurl.com/api-create.php?url=${resultFix[0].audio}`);
  152. let tinyUrl = tiny.data;
  153. let title = getUrl.videoDetails.title;
  154. let thumb = getUrl.player_response.microformat.playerMicroformatRenderer.thumbnail.thumbnails[0].url;
  155. resolve({ title, result: tinyUrl, result2: resultFix, thumb })}).catch(reject)})}
  156. async function ytMp4(url) {
  157. return new Promise(async(resolve, reject) => {
  158. ytdl.getInfo(url).then(async(getUrl) => {
  159. let result = [];
  160. for(let i = 0; i < getUrl.formats.length; i++) {
  161. let item = getUrl.formats[i];
  162. if (item.container == 'mp4' && item.hasVideo == true && item.hasAudio == true) {
  163. let { qualityLabel, contentLength } = item;
  164. let bytes = await bytesToSize(contentLength);
  165. result[i] = { video: item.url, quality: qualityLabel, size: bytes }}};
  166. let resultFix = result.filter(x => x.video != undefined && x.size != undefined && x.quality != undefined)
  167. let tiny = await axios.get(`https://tinyurl.com/api-create.php?url=${resultFix[0].video}`);
  168. let tinyUrl = tiny.data;
  169. let title = getUrl.videoDetails.title;
  170. let thumb = getUrl.player_response.microformat.playerMicroformatRenderer.thumbnail.thumbnails[0].url;
  171. resolve({ title, result: tinyUrl, rersult2: resultFix[0].video, thumb })}).catch(reject)})};
  172. async function ytPlay(query) {
  173. return new Promise((resolve, reject) => {
  174. yts(query).then(async(getData) => {
  175. let result = getData.videos.slice( 0, 5 );
  176. let url = [];
  177. for (let i = 0; i < result.length; i++) { url.push(result[i].url) }
  178. let random = url[0];
  179. let getAudio = await ytMp3(random);
  180. resolve(getAudio)}).catch(reject)})};
  181. async function ytPlayVid(query) {
  182. return new Promise((resolve, reject) => {
  183. yts(query).then(async(getData) => {
  184. let result = getData.videos.slice( 0, 5 );
  185. let url = [];
  186. for (let i = 0; i < result.length; i++) { url.push(result[i].url) }
  187. let random = url[0];
  188. let getVideo = await ytMp4(random);
  189. resolve(getVideo)}).catch(reject)})};