wolfyflutter

dlpanda.com [downloader] [video] [facebook] [x] [tiktok] [pinterest]

Jul 14th, 2025 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 7.56 KB | Source Code | 0 0
  1. /*
  2.     base   : https://dlpanda.com/id
  3.     update : 23 juli 2025
  4.     fungsi : buat download video dari facebook, x/twitter, pinterest, tiktok
  5.     node   : v24.4.0
  6.     note   : kalau error, hapus aja headers accept encoding yang zstd gw makek
  7.              fetch bawaan node versi tertera. jadi support :v
  8.              ada banyak service yang masih bisa di skrep. cuma gw skrep yang
  9.              common" ajah. bilang aja kalau mau di bikinin yang lainnya yah :v
  10.     by     : wolep
  11.     req by : orang, gatau lupa namanya :v
  12. */
  13.  
  14. class Dlpanda {
  15.     origin = "https://dlpanda.com/id"
  16.     webHeaders = {
  17.         "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
  18.         "accept-encoding": "gzip, deflate, br, zstd",
  19.         "accept-language": "en-GB,en;q=0.9,en-US;q=0.8",
  20.         "cache-control": "no-cache",
  21.         "pragma": "no-cache",
  22.         "priority": "u=0, i",
  23.         "sec-ch-ua": "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Microsoft Edge\";v=\"138\"",
  24.         "sec-ch-ua-mobile": "?0",
  25.         "sec-ch-ua-platform": "\"Windows\"",
  26.         "sec-fetch-dest": "document",
  27.         "sec-fetch-mode": "navigate",
  28.         "sec-fetch-site": "none",
  29.         "sec-fetch-user": "?1",
  30.         "upgrade-insecure-requests": "1",
  31.         "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0"
  32.     }
  33.  
  34.     getHtml = async (description, api, opts) => {
  35.         try {
  36.             const response = await fetch(api, opts);
  37.             if (!response.ok) throw Error(`${response.status} ${response.statusText}\n${await response.text()}`)
  38.             const html = await response.text()
  39.             return html
  40.         } catch (err) {
  41.             throw Error(`gagal getHtml ${description} karena ${err.message}`)
  42.         }
  43.     }
  44.  
  45.     getCookieAndToken = async (path, regex) => {
  46.         try {
  47.             const url = this.origin + path
  48.             const response = await fetch(url, {
  49.                 headers: this.webHeaders
  50.             })
  51.             const html = await response.text()
  52.             const cookie = response.headers.getSetCookie().map(v => v.split(";")[0]).join("; ")
  53.             const token = html.match(new RegExp(regex))?.[1] || null
  54.             const result = { cookie, token }
  55.             return result
  56.         } catch (err) {
  57.             throw Error(`gagal mendapatkan kuki dan tokenF\nkarena ${err.message}`)
  58.         }
  59.     }
  60.  
  61.     facebook = async (url) => {
  62.        if (typeof (url) !== "string" || url?.trim()?.length === 0) throw Error(`miaw.. masukin url yang bener yah`)
  63.         const { cookie, token } = await this.getCookieAndToken(`/facebook`, `_token" value="(.+?)"`)
  64.  
  65.        const headers = { cookie, ...this.headers }
  66.        const body = new URLSearchParams({ url, _token: token })
  67.  
  68.        const api = new URL(this.origin)
  69.        api.pathname = "/id/facebook"
  70.  
  71.  
  72.        const html = await this.getHtml(`facebook`, api, { headers, body, method: "post" })
  73.  
  74.        // pick link
  75.        const text = html.match(/" target="_blank"><h5>(.+?)<\/h5>/)?.[1] || `from facebook`
  76.         let images = Array.from(html.matchAll(/img alt="" src="(.+?)"/gm))
  77.         if (images.length) images = images.map(v => v[1])
  78.         const audio = html.match(/downVideo\('([^ ]+)', '(?:.+?)mp3/)?.[1] || null
  79.         let video =  html.match(/<source src="(.+?)"/)?.[1] || null
  80.         if (video) video = video.replaceAll(`&amp;`,`&`)
  81.         return {text, audio, video, images}            
  82.     }
  83.  
  84.     twitter = async (url) => {
  85.         if (typeof (url) !== "string" || url?.trim()?.length === 0) throw Error(`miaw.. masukin url yang bener yah`)
  86.         const { cookie, token } = await this.getCookieAndToken(`/t`, `_token" value="(.+?)"`)
  87.        const headers = { cookie, ...this.webHeaders }
  88.        const body = new URLSearchParams({ url, _token: token })
  89.  
  90.        const api = new URL(this.origin)
  91.        api.pathname = "/id/t"
  92.  
  93.        const html = await this.getHtml(`twitter`, api, {headers, body, "method":"post"})
  94.  
  95.        //pick link
  96.        const text = html.match(/" target="_blank"><h5>(.+?)<\/h5>/)?.[1] || `from Pinterest`
  97.         let images = Array.from(html.matchAll(/img alt="" src="(.+?)"/gm))
  98.         if (images.length) images = images.map(v => v[1])
  99.         const audio = html.match(/downVideo\('([^ ]+)', '(?:.+?)mp3/)?.[1] || null
  100.         const video =  html.match(/<source src="(.+?)"/)?.[1] || null
  101.         return {text, audio, video, images}
  102.     }
  103.  
  104.     tiktok = async (url) => {
  105.         if (typeof (url) !== "string" || url?.trim()?.length === 0) throw Error(`miaw.. masukin url yang bener yah`)
  106.         const { cookie, token } = await this.getCookieAndToken(``, `id="token" value="(.+?)"`)
  107.         const headers = { cookie, ...this.webHeaders }
  108.  
  109.         const api = new URL(this.origin)
  110.         api.search = new URLSearchParams({ url, token })
  111.  
  112.         const html = await this.getHtml(`tiktok`, api, {headers})
  113.  
  114.         // pick link
  115.         const text = html.match(/" target="_blank"><h5>(.+?)<\/h5>/)?.[1] || `from Tiktok`
  116.         let images = Array.from(html.matchAll(/img alt="" src="(.+?)"/gm))
  117.         if (images.length) images = images.map(v => v[1])
  118.         const audio = html.match(/downVideo\('([^ ]+)', '(?:.+?)mp3/)?.[1] || null
  119.         let video = html.match(/downVideo\('([^ ]+)', '(?:.+?)mp4/)?.[1] || null
  120.         if (video) video = "https:" + video
  121.  
  122.         return {text, audio, video, images}
  123.  
  124.     }
  125.  
  126.     pinterest = async (url) => {
  127.         if (typeof (url) !== "string" || url?.trim()?.length === 0) throw Error(`miaw.. masukin url yang bener yah`)    
  128.  
  129.         const headers = {...this.webHeaders}
  130.         const api = new URL(this.origin)
  131.         api.search = new URLSearchParams({ url })
  132.         api.pathname = "id/pinterest"
  133.  
  134.         const html = await this.getHtml(`pinterst`, api, {headers})
  135.  
  136.         // pick link
  137.         let text = html.match(/" target="_blank"><h5>(.+?)<\/h5>/)?.[1] || `from Pinterest`
  138.         let images = Array.from(html.matchAll(/img alt="" src="(.+?)"/gm))
  139.         if (images.length) images = images.map(v => v[1])
  140.         const audio = html.match(/downVideo\('([^ ]+)', '(?:.+?)mp3/)?.[1] || null
  141.         let video = html.match(/downloadFileHref\('(.+?)'\)/)?.[1] || null
  142.         return {text, audio, video, images}
  143.     }
  144.  
  145.     // tambah service lainnya, cuman males ku skrep, jarang di pakek jg wkw. patternnya kurang lebih sama, mungkin ku apdet lagi kode nya kalau perlu.
  146. }
  147.  
  148.  
  149.  
  150. // cara pakai
  151.  
  152. (async() => {
  153.  
  154.     const delay = (ms) => new Promise(resolve => setTimeout(resolve,ms))
  155.  
  156.     // create new instance of Dlpanda
  157.     const dlpanda = new Dlpanda()
  158.  
  159.     console.log("fb")
  160.     const fb = await dlpanda.facebook("https://www.facebook.com/KallenNyanKaiNiZ/videos/furina-final-wish-neko-ni/602868228770382/")
  161.     console.log(fb)
  162.  
  163.     await delay (2000)
  164.  
  165.     console.log("tiktok")
  166.     const tiktok = await dlpanda.tiktok("https://www.tiktok.com/@factual.id/photo/7524111285127056648?lang=en")
  167.     console.log(tiktok)
  168.  
  169.     await delay (2000)
  170.  
  171.     console.log("twitter")
  172.     const twitter = await dlpanda.twitter("https://x.com/SpacePancakes/status/1790081529953096125")
  173.     console.log(twitter)
  174.  
  175.     await delay (2000)
  176.  
  177.     console.log("pinterest")
  178.     const pinterest = await dlpanda.pinterest("https://www.pinterest.com/pin/3659243440224609/")
  179.     console.log(pinterest)
  180. })()
  181.  
  182. /* output
  183. {
  184.   text: 'from facebook',
  185.   audio: null,
  186.   video: 'https://video.........65576',
  187.   images: []
  188. }
  189. */
Add Comment
Please, Sign In to add comment