Advertisement
WILDAN_IZZUDIN

[JS] YOUTUBE MP3 DOWNLOADER

May 9th, 2024 (edited)
1,464
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const puppeteer = require('puppeteer');
  2. const iPhone = puppeteer.devices['iPhone 12']
  3.  
  4. module.exports = async url => {
  5.    const browser = await puppeteer.launch({
  6.       headless: 'new',
  7.       args: [
  8.          "--fast-start",
  9.          "--disable-extensions",
  10.          "--no-sandbox",
  11.          "--disable-setuid-sandbox",
  12.          "--no-gpu",
  13.          "--disable-background-timer-throttling",
  14.          "--disable-renderer-backgrounding",
  15.          "--override-plugin-power-saver-for-testing=never",
  16.          "--disable-extensions-http-throttling",
  17.          "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.3"
  18.       ]
  19.    })
  20.    try {
  21.       const page = await browser.newPage()
  22.       await page.emulate(iPhone)
  23.       await page.goto('https://ytmp3s.nu', {
  24.          waitUntil: 'networkidle2',
  25.          timeout: 0
  26.       })
  27.       await page.type('input#url', url)
  28.       await page.click('input[value="Convert"]')
  29.       await page.waitForSelector('#progress', {
  30.          hidden: true
  31.       })
  32.       const fileName = await page.evaluate(() => {
  33.          const el = document.querySelector('form > div')
  34.          return el ? el.innerText: ''
  35.       })
  36.       const fileUrl = await page.evaluate(() => {
  37.          const el = document.querySelector('form > div > a[rel="nofollow"]')
  38.          return el ? el.href: ''
  39.       })
  40.       await browser.close()
  41.       if (!fileUrl) return ({
  42.          status: false,
  43.          msg: `Can't contvert file!`
  44.      })
  45.      return ({
  46.         status: true,
  47.         data: {
  48.            filename: fileName + '.mp3',
  49.            url: fileUrl
  50.         }
  51.      })
  52.   } catch (e) {
  53.      await browser.close()
  54.      return ({
  55.         status: false,
  56.         msg: e.message
  57.      })
  58.   }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement