wolfyflutter

gabut [4kdownload.to] ytmp3 dl

Jan 1st, 2026 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // source https://4kdownload.to/enXd/
  2.  
  3. const yt = {
  4.     MAX_TRIES: 24, //times
  5.     CHECK_PROGRESS_DELAY: 5000, // ms
  6.     fetchJson: async function (url, requestInit) {
  7.         try {
  8.             const res = await fetch(url, requestInit)
  9.             if (!res.ok) throw Error(`${res.status}`)
  10.             const data = await res.json()
  11.             return { ok: true, data }
  12.         } catch (e) {
  13.             return { ok: false, data: e.message }
  14.         }
  15.     },
  16.  
  17.     headers: {
  18.         "accept-encoding": "gzip, deflate, br, zstd",
  19.         // "Referer": "https://4kdownload.to/"
  20.     },
  21.  
  22.     downloadMp3: async function (youtubeUrl) {
  23.         // init
  24.         const i = await this.init(youtubeUrl)
  25.         if (!i.ok) throw Error(`init function fail ${i.data}`)
  26.  
  27.         // progress check
  28.         const pc = await this.processCheck(i)
  29.         if (!pc.ok) throw Error(`init function fail ${i.data}`)
  30.         return pc.data
  31.     },
  32.  
  33.     init: async function (youtubeUrl) {
  34.         console.log('init')
  35.         const url = new URL('https://p.savenow.to/ajax/download.php')
  36.         url.search = new URLSearchParams({
  37.             'copyright': '0',
  38.             'format': 'mp3', // modifi this value if u want other format, read web api docs
  39.             'url': youtubeUrl
  40.         })
  41.         return await this.fetchJson(url, { headers: this.headers })
  42.     },
  43.  
  44.     processCheck: async function (initObj) {
  45.         console.log('progress check')
  46.         if (!initObj.data.success) throw Error(`return value from init is not success`)
  47.         const url = initObj.data.progress_url
  48.  
  49.         let res = await this.fetchJson(url, { headers: this.headers })
  50.         if (!res.ok) throw Error(`${res.status}`)
  51.         if (res.data.success) return res
  52.  
  53.         for (let i = 0; i <= this.MAX_TRIES; i++) {
  54.             console.log(`try ${i + 1}/${this.MAX_TRIES}`)
  55.             res = await this.fetchJson(url, { headers: this.headers })
  56.             if (!res.ok) throw Error(`${res.status}`)
  57.             if (res.data.success) return res
  58.             console.log(`${parseInt(res.data.progress) / 10}% (${res.data.text || '(unknown)'})`)
  59.             await new Promise(r => setTimeout(r, this.CHECK_PROGRESS_DELAY))
  60.         }
  61.     }
  62. }
  63.  
  64. await yt.downloadMp3("https://www.youtube.com/watch?v=7iNbnineUCI&list=RDBy7ctqcWxyM&index=22")
  65.     .then(console.log)
  66.     .catch(console.log)
  67.  
  68. /* output
  69. {
  70.   success: 1,
  71.   progress: 1000,
  72.   download_url: 'https://leo3.savenow.to/pacific/?F5OkmTGnaDtxS6yq0KzmF9z',
  73.   text: 'Finished',
  74.   message: 'If you want your application to use our API contact us: [email protected] or visit https://video-download-api.com/',
  75.   alternative_download_urls: [
  76.     {
  77.       type: 'nip.io',
  78.       url: 'https://81-17-16-210.nip.io/pacific/?F5OkmTGnaDtxS6yq0KzmF9z',
  79.       has_ssl: true
  80.     },
  81.     {
  82.       type: 'sslip.io',
  83.       url: 'https://81-17-16-210.sslip.io/pacific/?F5OkmTGnaDtxS6yq0KzmF9z',
  84.       has_ssl: true
  85.     },
  86.     {
  87.       type: 'traefik.me',
  88.       url: 'http://81-17-16-210.traefik.me/pacific/?F5OkmTGnaDtxS6yq0KzmF9z',
  89.       has_ssl: false
  90.     }
  91.   ]
  92. }
  93.   */
Advertisement
Add Comment
Please, Sign In to add comment