wolfyflutter

pinterest downloader [downloader] [api ori] [image] [video]

Jan 30th, 2026
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.40 KB | Source Code | 0 0
  1. /*
  2. base: https://id.pinterest.com/
  3. note : gak tau token nya apakah bakalan bertahan lama / kagak. tapi kata orang" sih bertahan lama :v
  4. pint skrep by wolep
  5. param: string pint url (sup vid and image)
  6. throw error, jadi selalu pakai catch, handle error sesuka hati.. mungkin bs 500 atau friendly outout
  7. skrep api ori pint
  8. output konsisten sudah saya serialize :v
  9. liat penggunaan di bawah ya
  10. 24 januari 2026
  11. */
  12.  
  13. const pinterest = {
  14.   getData: async function (pinterestUrl) {
  15.     const pinterestId = await this.getPinterestIdFromUrl(pinterestUrl)
  16.     const res = await fetch("https://id.pinterest.com/_/graphql/", {
  17.       "headers": {
  18.         "accept-encoding": "gzip, deflate, br, zstd",
  19.         "content-type": "application/json",
  20.         "cookie": "csrftoken=f199c374cd68fda2595b9cc9bb9c7d5d;}",
  21.         "x-csrftoken": "f199c374cd68fda2595b9cc9bb9c7d5d",
  22.       },
  23.       "body": JSON.stringify({
  24.         "queryHash": "91dc7817f1acf1c2fb8d505d1c79dedebcb3baa1794065ba3602b843099f8ff7",
  25.         "variables": {
  26.           "pinId": pinterestId,
  27.           "isAuth": false,
  28.           "isDesktop": true,
  29.           "shouldPrefetchStoryPinFragment": false,
  30.           "isUnauth": true
  31.         }
  32.       }),
  33.       "method": "POST",
  34.     })
  35.     if (!res.ok) throw Error(`${res.status} ${res.statusText} on ${res.url}`)
  36.     const json = await res.json()
  37.     return this.serialize(json)
  38.   },
  39.   serialize: function (pinterestResponse) {
  40.     //return pinterestResponse
  41.     // path shorter
  42.     const data = pinterestResponse.data.v3GetPinQuery.data
  43.  
  44.     // post
  45.     const post = {
  46.       title: data?.unauthOnPageTitle?.trim() || '(no title)',
  47.       description: data?.description.trim(),
  48.       likesCount: data?.totalReactionCount || 0,
  49.       shareCount: data?.shareCount || 0,
  50.       commentCount: data?.aggregatedPinData.commentCount || 0,
  51.       createdAt: data?.createdAt || '(unknown)'
  52.     }
  53.  
  54.     // user
  55.     const user = {
  56.       fullName: data?.originPinner?.fullName || '(unknown)',
  57.       username: data?.originPinner?.username || '(unknown)'
  58.     }
  59.  
  60.  
  61.     const v = data?.storyPinData?.pages[0]?.blocks[0]?.videoDataV2?.videoList720P?.v720P ||
  62.       data?.videos?.videoList?.v720P
  63.     const content = {
  64.       images: Object.keys(data).filter(k => k.startsWith('images_')).map(k => ({ ...data[k], name: k.replace('images_', '') })),
  65.       videos: v ? [v] : []
  66.  
  67.  
  68.     }
  69.  
  70.     return {
  71.       user,
  72.       post,
  73.       content
  74.     }
  75.   },
  76.   getPinterestIdFromUrl: async function (pinterestUrl) {
  77.     const shortUrl = /pin\.it/i.test(pinterestUrl)
  78.     let utext
  79.     if (shortUrl) {
  80.       const r = await fetch(pinterestUrl, { method: 'head', redirect: 'follow', })
  81.       utext = r.url
  82.     } else {
  83.       const validHostname = /pinterest/i.test(pinterestUrl)
  84.       if (!validHostname) throw Error(`${pinterestUrl} invalid. hostname invalid`)
  85.       utext = pinterestUrl
  86.     }
  87.     const url = new URL(utext)
  88.     const pinId = url.pathname.match(/\/pin\/(\d+)/)?.[1]
  89.     if (!pinId) throw Error(`${pinterestUrl} invalid. cant parse pinterest id`)
  90.     return pinId
  91.   }
  92. }
  93.  
  94. // export esm, cjs ya anuin sendiri :v
  95. export { pinterest }
  96.  
  97. // cara pakai
  98. // pinterest.getData('https://id.pinterest.com/pin/10414642883372969/')
  99. //   .then(r => console.log(JSON.stringify(r, null, 2)))
  100. //   .catch(console.log)
  101.  
  102. /* output
  103. {
  104.   "user": {
  105.     "fullName": "HanVibey_",
  106.     "username": "animetim_e"
  107.   },
  108.   "post": {
  109.     "title": "Angry Anime Face",
  110.     "description": "",
  111.     "likesCount": 270,
  112.     "shareCount": 104,
  113.     "commentCount": 3,
  114.     "createdAt": "Wed, 31 Dec 2025 07:32:39 +0000"
  115.   },
  116.   "content": {
  117.     "images": [
  118.       {
  119.         "height": 419,
  120.         "width": 236,
  121.         "url": "https://i.pinimg.com/236x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  122.         "name": "236x"
  123.       },
  124.       {
  125.         "height": 136,
  126.         "width": 136,
  127.         "url": "https://i.pinimg.com/136x136/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  128.         "name": "136x136"
  129.       },
  130.       {
  131.         "url": "https://i.pinimg.com/60x60/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  132.         "name": "60x60"
  133.       },
  134.       {
  135.         "url": "https://i.pinimg.com/236x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  136.         "name": "170x"
  137.       },
  138.       {
  139.         "url": "https://i.pinimg.com/474x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  140.         "height": 842,
  141.         "width": 474,
  142.         "name": "474x"
  143.       },
  144.       {
  145.         "url": "https://i.pinimg.com/564x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  146.         "height": 1002,
  147.         "width": 564,
  148.         "name": "564x"
  149.       },
  150.       {
  151.         "url": "https://i.pinimg.com/736x/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  152.         "height": 1280,
  153.         "width": 720,
  154.         "name": "736x"
  155.       },
  156.       {
  157.         "url": "https://i.pinimg.com/600x315/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  158.         "name": "600x315"
  159.       },
  160.       {
  161.         "url": "https://i.pinimg.com/originals/29/f6/4c/29f64c75d6f77eaa44e2720a82b5b999.jpg",
  162.         "name": "orig"
  163.       }
  164.     ],
  165.     "videos": [
  166.       {
  167.         "thumbnail": "https://i.pinimg.com/videos/thumbnails/originals/f9/8f/a6/f98fa6d0ec8108ac9b87dce3563b89f3.0000000.jpg",
  168.         "url": "https://v1.pinimg.com/videos/iht/expMp4/f9/8f/a6/f98fa6d0ec8108ac9b87dce3563b89f3_720w.mp4",
  169.         "width": 720,
  170.         "height": 1280,
  171.         "duration": 9933
  172.       }
  173.     ]
  174.   }
  175. }
  176. */
Advertisement
Add Comment
Please, Sign In to add comment