From 3389c595dfbfea4d0cf2a6d2f040894ef146f2ff Mon Sep 17 00:00:00 2001 From: wukko Date: Tue, 16 Apr 2024 23:51:35 +0600 Subject: [PATCH] instagram: update stories endpoint and parsing --- src/modules/processing/services/instagram.js | 30 +++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/modules/processing/services/instagram.js b/src/modules/processing/services/instagram.js index ddb1c2a..a5b20d7 100644 --- a/src/modules/processing/services/instagram.js +++ b/src/modules/processing/services/instagram.js @@ -3,9 +3,10 @@ import { genericUserAgent } from "../../config.js"; import { getCookie, updateCookie } from "../cookie/manager.js"; const commonInstagramHeaders = { - 'User-Agent': genericUserAgent, + 'user-agent': genericUserAgent, 'sec-gpc': '1', - 'Sec-Fetch-Site': 'same-origin', + 'sec-fetch-site': 'same-origin', + 'x-ig-app-id': '936619743392459' } const cachedDtsg = { @@ -137,22 +138,31 @@ async function usernameToId(username, cookie) { async function getStory(username, id) { const cookie = getCookie('instagram'); - if (!cookie) return { error: 'ErrorUnsupported' } + if (!cookie) return { error: 'ErrorUnsupported' }; const userId = await usernameToId(username, cookie); - if (!userId) return { error: 'ErrorEmptyDownload' } + if (!userId) return { error: 'ErrorEmptyDownload' }; + + const dtsgId = await findDtsgId(cookie); - const url = new URL('https://www.instagram.com/api/v1/feed/reels_media/'); - url.searchParams.set('reel_ids', userId); - url.searchParams.set('media_id', id); + const url = new URL('https://www.instagram.com/api/graphql/'); + const requestData = { + fb_dtsg: dtsgId, + jazoest: '26438', + variables: JSON.stringify({ + reel_ids_arr : [ userId ], + }), + server_timestamps: true, + doc_id: '25317500907894419' + }; let media; try { - const data = await request(url, cookie); - media = data?.reels_media?.find(m => m.id === userId); + const data = (await request(url, cookie, 'POST', requestData)); + media = data?.data?.xdt_api__v1__feed__reels_media?.reels_media?.find(m => m.id === userId); } catch {} - const item = media.items[media.media_ids.indexOf(id)]; + const item = media.items.filter(m => m.pk === id)[0]; if (!item) return { error: 'ErrorEmptyDownload' }; if (item.video_versions) {