Advertisement
AnshorFalahi

youtube

May 18th, 2024
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.23 KB | Source Code | 0 0
  1. const { Converter } = new(require('@neoxr/wb'))
  2. exports.run = {
  3.    usage: ['ytmp3', 'ytmp4'],
  4.    hidden: ['yta', 'ytv'],
  5.    use: 'link',
  6.    category: 'downloader',
  7.    async: async (m, {
  8.       client,
  9.       args,
  10.       isPrefix,
  11.       command,
  12.       users,
  13.       env,
  14.       Func,
  15.       Scraper
  16.    }) => {
  17.       try {
  18.          if (/yt?(a|mp3)/i.test(command)) {
  19.             if (!args || !args[0]) return client.reply(m.chat, Func.example(isPrefix, command, 'https://youtu.be/zaRFmdtLhQ8'), m)
  20.             if (!/^(?:https?:\/\/)?(?:www\.|m\.|music\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)\&?/.test(args[0])) return client.reply(m.chat, global.status.invalid, m)
  21.             client.sendReact(m.chat, 'πŸ•’', m.key)
  22.             const json = await Scraper.youtube(args[0])
  23.             if (!json.status) return client.reply(m.chat, Func.jsonFormat(json), m)
  24.             let caption = `δΉ‚  *Y T - P L A Y*\n\n`
  25.             caption += `    β—¦  *Title* : ${json.title}\n`
  26.             caption += `    β—¦  *Size* : ${json.data.size}\n`
  27.             caption += `    β—¦  *Duration* : ${json.duration}\n`
  28.             caption += `    β—¦  *Bitrate* : ${json.data.quality}\n\n`
  29.             caption += global.footer
  30.             const chSize = Func.sizeLimit(json.data.size, users.premium ? env.max_upload : env.max_upload_free)
  31.             const isOver = users.premium ? `πŸ’€ File size (${json.data.size}) exceeds the maximum limit.` : `⚠️ File size (${json.data.size}), you can only download files with a maximum size of ${env.max_upload_free} MB and for premium users a maximum of ${env.max_upload} MB.`
  32.             if (chSize.oversize) return client.reply(m.chat, isOver, m)
  33.             client.sendMessageModify(m.chat, caption, m, {
  34.                largeThumb: true,
  35.                thumbnail: await Func.fetchBuffer(json.thumbnail)
  36.             }).then(async () => {
  37.                const buffer = await Converter.toAudio(json.data.buffer, 'mp3')
  38.                client.sendFile(m.chat, buffer, json.data.filename, '', m, {
  39.                   document: true,
  40.                   APIC: await Func.fetchBuffer(json.thumbnail)
  41.                })
  42.             })
  43.          } else if (/yt?(v|mp4)/i.test(command)) {
  44.             if (!args || !args[0]) return client.reply(m.chat, Func.example(isPrefix, command, 'https://youtu.be/zaRFmdtLhQ8'), m)
  45.             if (!/^(?:https?:\/\/)?(?:www\.|m\.|music\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)\&?/.test(args[0])) return client.reply(m.chat, global.status.invalid, m)
  46.             client.sendReact(m.chat, 'πŸ•’', m.key)
  47.             const json = await Scraper.youtube(args[0], 'video')
  48.             if (!json.status) return client.reply(m.chat, Func.jsonFormat(json), m)
  49.             let caption = `δΉ‚  *Y T - M P 4*\n\n`
  50.             caption += `    β—¦  *Title* : ${json.title}\n`
  51.             caption += `    β—¦  *Size* : ${json.data.size}\n`
  52.             caption += `    β—¦  *Duration* : ${json.duration}\n`
  53.             caption += `    β—¦  *Quality* : ${json.data.quality}\n\n`
  54.             caption += global.footer
  55.             const chSize = Func.sizeLimit(json.data.size, users.premium ? env.max_upload : env.max_upload_free)
  56.             const isOver = users.premium ? `πŸ’€ File size (${json.data.size}) exceeds the maximum limit.` : `⚠️ File size (${json.data.size}), you can only download files with a maximum size of ${env.max_upload_free} MB and for premium users a maximum of ${env.max_upload} MB.`
  57.             if (chSize.oversize) return client.reply(m.chat, isOver, m)
  58.             let isSize = (json.data.size).replace(/MB/g, '').trim()
  59.             if (isSize > 99) return client.sendMessageModify(m.chat, caption, m, {
  60.                largeThumb: true,
  61.                thumbnail: await Func.fetchBuffer(json.thumbnail)
  62.             }).then(async () => {
  63.                await client.sendFile(m.chat, json.data.buffer, json.data.filename, caption, m, {
  64.                   document: true
  65.                })
  66.             })
  67.             client.sendFile(m.chat, json.data.buffer, json.data.filename, caption, m)
  68.          }
  69.       } catch (e) {
  70.          return client.reply(m.chat, Func.jsonFormat(e), m)
  71.       }
  72.    },
  73.    error: false,
  74.    limit: true,
  75.    cache: true,
  76.    location: __filename
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement