From ba7137ef629833f89929b4ab5b15eeb6c5b54b64 Mon Sep 17 00:00:00 2001 From: dumbmoron <136796770+dumbmoron@users.noreply.github.com> Date: Sun, 20 Aug 2023 22:18:32 +0000 Subject: [PATCH 1/4] send cookies as-is --- src/modules/processing/cookie/cookie.js | 4 ++-- src/modules/processing/cookie/manager.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/processing/cookie/cookie.js b/src/modules/processing/cookie/cookie.js index 996ab7c7..6dd95fc3 100644 --- a/src/modules/processing/cookie/cookie.js +++ b/src/modules/processing/cookie/cookie.js @@ -20,13 +20,13 @@ export default class Cookie { str.split('; ').forEach(cookie => { const key = cookie.split('=')[0]; const value = cookie.split('=').splice(1).join('='); - obj[key] = decodeURIComponent(value) + obj[key] = value }) return new Cookie(obj) } toString() { - return Object.entries(this._values).map(([ name, value ]) => `${name}=${encodeURIComponent(value)}`).join('; ') + return Object.entries(this._values).map(([ name, value ]) => `${name}=${value}`).join('; ') } toJSON() { return this.toString() diff --git a/src/modules/processing/cookie/manager.js b/src/modules/processing/cookie/manager.js index 4efb0b45..b9feedc1 100644 --- a/src/modules/processing/cookie/manager.js +++ b/src/modules/processing/cookie/manager.js @@ -49,8 +49,10 @@ export function getCookie(service) { export function updateCookie(cookie, headers) { if (!cookie) return; - const parsed = parseSetCookie(splitCookiesString(headers.get('set-cookie'))), - values = {} + const parsed = parseSetCookie( + splitCookiesString(headers.get('set-cookie')), + { decodeValues: false } + ), values = {} cookie.unset(parsed.filter(c => c.expires < new Date()).map(c => c.name)); parsed.filter(c => c.expires > new Date()).forEach(c => values[c.name] = c.value); From 9eb6700399da0c4880c0ad40878930338b005ce4 Mon Sep 17 00:00:00 2001 From: dumbmoron <136796770+dumbmoron@users.noreply.github.com> Date: Sun, 20 Aug 2023 22:18:49 +0000 Subject: [PATCH 2/4] set instagram specific headers --- src/modules/processing/services/instagram.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/processing/services/instagram.js b/src/modules/processing/services/instagram.js index 459ac3e0..355608b7 100644 --- a/src/modules/processing/services/instagram.js +++ b/src/modules/processing/services/instagram.js @@ -23,6 +23,9 @@ export default async function(obj) { 'User-Agent': genericUserAgent, 'X-Ig-App-Id': '936619743392459', 'X-Asbd-Id': '129477', + 'x-ig-www-claim': cookie?._wwwClaim || '0', + 'x-csrftoken': cookie?.values()?.csrftoken, + 'x-requested-with': 'XMLHttpRequest', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-origin', @@ -32,6 +35,11 @@ export default async function(obj) { cookie } }) + + if (data.headers.get('X-Ig-Set-Www-Claim') && cookie) { + cookie._wwwClaim = data.headers.get('X-Ig-Set-Www-Claim'); + } + updateCookie(cookie, data.headers); data = (await data.json()).data; } catch (e) { @@ -92,3 +100,4 @@ export default async function(obj) { return { error: 'ErrorEmptyDownload' } } } + From 40f8b3ee0c29e050ce9985898e6b2e23d0869af9 Mon Sep 17 00:00:00 2001 From: dumbmoron <136796770+dumbmoron@users.noreply.github.com> Date: Sun, 20 Aug 2023 22:31:16 +0000 Subject: [PATCH 3/4] update cookies that have no expiration --- src/modules/processing/cookie/manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/processing/cookie/manager.js b/src/modules/processing/cookie/manager.js index b9feedc1..6ea05561 100644 --- a/src/modules/processing/cookie/manager.js +++ b/src/modules/processing/cookie/manager.js @@ -55,7 +55,7 @@ export function updateCookie(cookie, headers) { ), values = {} cookie.unset(parsed.filter(c => c.expires < new Date()).map(c => c.name)); - parsed.filter(c => c.expires > new Date()).forEach(c => values[c.name] = c.value); + parsed.filter(c => !c.expires || c.expires > new Date()).forEach(c => values[c.name] = c.value); cookie.set(values); if (Object.keys(values).length) dirty = true From a1e08c069230f32990864bc181921ac51da78a61 Mon Sep 17 00:00:00 2001 From: wukko Date: Mon, 21 Aug 2023 22:03:18 +0600 Subject: [PATCH 4/4] Update instagram.js --- src/modules/processing/services/instagram.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/processing/services/instagram.js b/src/modules/processing/services/instagram.js index 355608b7..9614bd94 100644 --- a/src/modules/processing/services/instagram.js +++ b/src/modules/processing/services/instagram.js @@ -100,4 +100,3 @@ export default async function(obj) { return { error: 'ErrorEmptyDownload' } } } -