Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const puppeteer = require('puppeteer');
- const iPhone = puppeteer.devices['iPhone 12']
- module.exports = async url => {
- const browser = await puppeteer.launch({
- headless: 'new',
- args: [
- "--fast-start",
- "--disable-extensions",
- "--no-sandbox",
- "--disable-setuid-sandbox",
- "--no-gpu",
- "--disable-background-timer-throttling",
- "--disable-renderer-backgrounding",
- "--override-plugin-power-saver-for-testing=never",
- "--disable-extensions-http-throttling",
- "--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"
- ]
- })
- try {
- const page = await browser.newPage()
- await page.emulate(iPhone)
- await page.goto('https://ytmp3s.nu', {
- waitUntil: 'networkidle2',
- timeout: 0
- })
- await page.type('input#url', url)
- await page.click('input[value="Convert"]')
- await page.waitForSelector('#progress', {
- hidden: true
- })
- const fileName = await page.evaluate(() => {
- const el = document.querySelector('form > div')
- return el ? el.innerText: ''
- })
- const fileUrl = await page.evaluate(() => {
- const el = document.querySelector('form > div > a[rel="nofollow"]')
- return el ? el.href: ''
- })
- await browser.close()
- if (!fileUrl) return ({
- status: false,
- msg: `Can't contvert file!`
- })
- return ({
- status: true,
- data: {
- filename: fileName + '.mp3',
- url: fileUrl
- }
- })
- } catch (e) {
- await browser.close()
- return ({
- status: false,
- msg: e.message
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement