wolfyflutter

65. www-y2mate.com [youtube] [downloader] [audio] [video]

Oct 26th, 2025 (edited)
503
1
Never
13
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.32 KB | Source Code | 1 0
  1. /*
  2.    nama  : yt downloader
  3.    base  : https://www-y2mate.com/
  4.    by    : wolep
  5.    update: 7 november 2025, 12:47 wita
  6.    note  : bisa download audio/video dan pilihan quality
  7.            skrep langsung download buffer, bisa sih
  8.            lu makek url download nya.. tapi perlu
  9.            custom headers buat download file nya
  10.            ribet wkwkw jadi gw langsung
  11.            aja kasih buffer. biar langsung lu olah sendiri
  12.    node  : v25.0.0
  13. */
  14.  
  15. import fs from 'node:fs'
  16.  
  17. const yt = {
  18.     static: Object.freeze({
  19.         baseUrl: 'https://cnv.cx',
  20.         headers: {
  21.             'accept-encoding': 'gzip, deflate, br, zstd',
  22.             'origin': 'https://frame.y2meta-uk.com',
  23.             'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0',
  24.         }
  25.     }),
  26.  
  27.     log: function (message) {
  28.         // return
  29.         const name = 'yt-skrep'
  30.         console.log(`[${name}] ${message}`)
  31.     },
  32.  
  33.     resolveConverterPayload: function (link, userFormat = '128k') {
  34.         const availableFormats = ['128k', '320k', '144p', '240p', '360p', '720p', '1080p']
  35.         if (!availableFormats.includes(userFormat)) throw Error(`invalid format. available format: ${availableFormats.join(', ')}`)
  36.         const format = userFormat.endsWith('k') ? 'mp3' : 'mp4'
  37.         const audioBitrate = format === "mp3" ? parseInt(userFormat) + '' : '128'
  38.         const videoQuality = format === "mp4" ? parseInt(userFormat) + '' : '720'
  39.         const filenameStyle = 'pretty'
  40.         const vCodec = 'h264'
  41.         return { link, format, audioBitrate, videoQuality, filenameStyle, vCodec }
  42.     },
  43.  
  44.     sanitizeFileName: function (fileName) {
  45.         const ext = fileName.match(/\.[^.]+$/)[0]
  46.         const fn = fileName.replace(new RegExp(`\\${ext}$`), '').replaceAll(/[^A-Za-z0-9]/g, '_').replace(/_+/g, '_').toLowerCase()
  47.         return fn + ext
  48.     },
  49.  
  50.     getBuffer: async function (urlDownload) {
  51.         this.log('downloading file...')
  52.         const headers = structuredClone(this.static.headers)
  53.         headers.referer = 'https://v6.www-y2mate.com/'
  54.         delete headers.origin
  55.         const r = await fetch(urlDownload, { headers })
  56.         if (!r.ok) throw Error(`${r.status} ${r.statusText} di fungsi getBuffer`)
  57.         const ab = await r.arrayBuffer()
  58.         const buff = Buffer.from(ab)
  59.         this.log('sukses download file')
  60.         return buff
  61.     },
  62.  
  63.  
  64.     getKey: async function () {
  65.         this.log('coba ambil key')
  66.         const endpoint = '/v2/sanity/key'
  67.         const r = await fetch(this.static.baseUrl + endpoint, {
  68.             headers: this.static.headers,
  69.         })
  70.         if (!r.ok) throw Error(`${r.status} ${r.statusText} di fungsi getKey`)
  71.         const j = await r.json()
  72.         return j
  73.     },
  74.  
  75.     convert: async function (yt_url, userFormat) {
  76.         const { key } = await this.getKey()
  77.        
  78.         this.log('coba ambil url')
  79.         const payload = this.resolveConverterPayload(yt_url, userFormat)
  80.         const headers = {
  81.             key,
  82.             ...this.static.headers
  83.         }
  84.  
  85.         const endpoint = '/v2/converter'
  86.         const r = await fetch(this.static.baseUrl + endpoint, {
  87.             headers,
  88.             method: 'post',
  89.             body: new URLSearchParams(payload)
  90.         })
  91.         if (!r.ok) throw Error(`${r.status} ${r.statusText} di fungsi convert`)
  92.         const j = await r.json()
  93.         this.log('dapat url ' + j.url)
  94.         return j
  95.     },
  96.  
  97.     download: async function (yt_url, userFormat) {
  98.         const { url, filename } = await this.convert(yt_url, userFormat)
  99.         const fileName = this.sanitizeFileName(filename)
  100.         const buffer = await this.getBuffer(url)
  101.         return { fileName, buffer }
  102.     }
  103. }
  104.  
  105. // cara pakai
  106. yt.download('https://www.youtube.com/watch?v=Ip6cw8gfHHI')
  107.     .then(data => {
  108.         // handle suka suka. param cuma file name dan buffer :v
  109.         const { buffer, fileName } = data
  110.         const filePath = './' + fileName
  111.         fs.writeFileSync(filePath, buffer)
  112.         console.log('sukses download! disimpan di ' + filePath)
  113.     })
  114.     .catch(error => {
  115.         console.log('ada kesalahan', error.message)
  116.     })
  117.  
  118. // atau yt.download('https://www.youtube.com/watch?v=Ip6cw8gfHHI', '360p')
  119.  
  120. export default yt
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment