Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- base : https://ytmp4.video/
- note : bisa download audio 64kbps, 128kbps, 192kbps, 256kbps, 320kbps
- bisa download video 360p, 480p, 720p, 1080p
- by : wolep
- node : v24.4.0
- update : 31 juli 2025
- */
- const yt = {
- get ytapiHeaders() {
- return {
- 'accept-encoding': 'gzip, deflate, br, zstd',
- "content-type": "application/json",
- "origin": "https://api.ytapi.cc",
- "referer": "https://api.ytapi.cc/",
- }
- },
- validateString(description, string) {
- if (typeof (string) !== "string" || string?.trim()?.length === 0) {
- throw Error(`${description} harus string dan gak boleh kosong!`)
- }
- },
- validateFormat(userFormat) {
- const validQuality = [
- "64kbps",
- "128kbps",
- "192kbps",
- "256kbps",
- "320kbps",
- "360p",
- "480p",
- "720p",
- "1080p"
- ]
- if (!validQuality.includes(userFormat)) throw Error(`your format "${userFormat}" is invalid format! pilih format yang tersedia: ${validQuality.join(`, `)}`)
- },
- async hit(hitDescription, url, options, returnType = "text") {
- try {
- const response = await fetch(url, options)
- if (!response.ok) throw Error(`${response.status} ${response.statusText} ${(await response.text() || `(respond body kosong)`).substring(0, 100)}...`)
- try {
- if (returnType === "text") {
- const data = await response.text()
- return { data, response }
- } else if (returnType === "json") {
- const data = await response.json()
- return { data, response }
- } else {
- throw Error(`invalid param retunt type. pilih text/json`)
- }
- } catch (error) {
- throw Error(`gagal mengubah response menjadi ${returnType}\n${error.message}`)
- }
- } catch (error) {
- throw Error(`gagal hit. ${hitDescription}.\n${error.message}`)
- }
- },
- async info(ytId, displayId) {
- const taskName = `${displayId}-cek info`
- console.time(taskName)
- const url = `https://dd-n01.yt2api.com/api/v4/info/${ytId}`
- const headers = {
- ...this.ytapiHeaders,
- }
- const { data, response } = await this.hit(`homepage`, url, { headers }, `json`)
- const authorization = response.headers.get('authorization')
- const cookie = response.headers.getSetCookie().map(v => v.split('; ')[0]).join('; ')
- // cek kalau ada error
- if (data.error) {
- throw Error(`${data.message}`)
- }
- const result = { ...data, authorization, cookie }
- console.timeEnd(taskName)
- return result
- },
- async convert(infoResult, yourFormat, displayId) {
- const taskName = `${displayId}-convert`
- console.time(taskName)
- const { authorization, cookie } = infoResult
- // handle format
- const handleFormat = (infoResult, userFormat) => {
- this.validateFormat(userFormat)
- if (/kbps/.test(userFormat)) {
- const availableAudioFormat = infoResult.formats.audio.mp3
- // sort dulu
- availableAudioFormat.sort((a, b) => parseInt(b.quality) - parseInt(a.quality))
- const find = availableAudioFormat.find(v => parseInt(v?.quality) == parseInt(userFormat))
- if (find) {
- return find
- } else {
- const falbackFormat = availableAudioFormat[0]
- console.log(`tidak menemukan format audio ${userFormat} auto falback ke ${falbackFormat.quality}kbps`)
- return falbackFormat
- }
- } else if (/p/.test(userFormat)) {
- const availableVideoFormat = infoResult.formats.video.mp4
- // sort dulu
- availableVideoFormat.sort((a, b) => parseInt(b.quality) - parseInt(a.quality))
- const find = availableVideoFormat.find(v => parseInt(v?.quality) == parseInt(userFormat))
- if (find) {
- return find
- } else {
- const falbackFormat = availableVideoFormat[0]
- console.log(`tidak menemukan format video ${userFormat} auto falback ke ${falbackFormat.quality}`)
- return falbackFormat
- }
- } else {
- throw Error(`lu input apaan cok`)
- }
- }
- const finalFormat = handleFormat(infoResult, yourFormat)
- const url = `https://dd-n01.yt2api.com/api/v4/convert`
- const headers = {
- authorization,
- cookie,
- ...this.ytapiHeaders
- }
- const body = JSON.stringify({
- token: finalFormat.token
- })
- const { data } = await this.hit(`convert`, url, { headers, body, 'method': 'post' }, `json`)
- console.timeEnd(taskName)
- return data
- },
- async progress(convertResult, infoResult, displayId) {
- const taskName = `${displayId}-cek progress`
- console.time(taskName)
- const { id } = convertResult
- const { cookie, authorization } = infoResult
- const delay = (ms) => new Promise(re => setTimeout(re, ms))
- const headers = {
- cookie,
- authorization,
- ...this.ytapiHeaders
- }
- const url = `https://dd-n01.yt2api.com/api/v4/status/${id}`
- let wolep
- do {
- wolep = await this.hit(`progress`, url, { headers }, `json`)
- console.log(`${wolep.data.progressStep} ${wolep.data.progress}%`)
- if (wolep.data.download) {
- console.timeEnd(taskName)
- return wolep.data
- }
- await delay(5000)
- } while (wolep.data.status == 'active')
- console.timeEnd(taskName)
- throw Error(`gagal cek progress. nih Jsonnya ${JSON.stringify(wolep.data, null, 2)}`)
- },
- // main function
- async download(yourubeId, userFormat) {
- // validate param before process
- this.validateString(`youtube id`, yourubeId)
- this.validateFormat(userFormat)
- // generate random
- const generateRandom = () => parseInt((Math.random() + "").substring(2).toString(36)).toString(36).substring(0,4)
- const displayId = generateRandom()
- console.log(`[NEW TASK] ${displayId}`)
- const infoResult = await this.info(yourubeId, displayId)
- const convertResult = await this.convert(infoResult, userFormat, displayId)
- const result = await this.progress(convertResult, infoResult, displayId)
- return result
- }
- }
- // cara pakai
- yt.download(`0fcRa5Z6LmU`, `128kbps`)
- .then(console.log)
- .catch(error => {
- console.log(error.message)
- })
- /* output
- {
- id: '31b3f127-1c74-45cf-a1e2-f6617aba51a0',
- status: 'completed',
- reason: '',
- progress: 100,
- progressStep: 'Done!',
- videoId: '0fcRa5Z6LmU',
- title: 'Red Hot Chili Peppers - The Zephyr Song [Official Music Video]',
- ext: 'mp3',
- quality: 128,
- download: 'https://dd-n01.yt2api.com/get/download/eyJhbGci...Q.W7BcAfgmTYJoeFw6VgbEUrtwL-fhh4iRcOOa-b0VI7k'
- }
- */
Advertisement
Comments
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=twwadlsmbj
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment