fixed more errors with instagram

This commit is contained in:
Denis Utkin 2025-04-27 15:45:53 +02:00
parent 55aab2aff2
commit f3a57b33d5

View File

@ -136,21 +136,26 @@ export default function instagram(obj) {
} }
async function requestHTML(id, cookie) { async function requestHTML(id, cookie) {
const data = await fetch(`https://www.instagram.com/p/${id}/embed/captioned/`, { try {
headers: { const data = await fetch(`https://www.instagram.com/p/${id}/embed/captioned/`, {
...embedHeaders, headers: {
cookie ...embedHeaders,
}, cookie
dispatcher },
}).then(r => r.text()).catch(() => {}); dispatcher
}).then(r => r.text()).catch(() => {
});
let embedData = JSON.parse(data?.match(/"init",\[\],\[(.*?)\]\],/)[1]); let embedData = JSON.parse(data?.match(/"init",\[\],\[(.*?)\]\],/)[1]);
if (!embedData || !embedData?.contextJSON) return false; if (!embedData || !embedData?.contextJSON) return false;
embedData = JSON.parse(embedData.contextJSON); embedData = JSON.parse(embedData.contextJSON);
return embedData;
}catch {
return null;
}
return embedData;
} }
async function getGQLParams(id, cookie) { async function getGQLParams(id, cookie) {
@ -213,6 +218,7 @@ export default function instagram(obj) {
} }
async function requestGQL(id, cookie) { async function requestGQL(id, cookie) {
try{
const { headers, body } = await getGQLParams(id, cookie); const { headers, body } = await getGQLParams(id, cookie);
const req = await fetch('https://www.instagram.com/graphql/query', { const req = await fetch('https://www.instagram.com/graphql/query', {
@ -245,6 +251,10 @@ export default function instagram(obj) {
.then(r => r.data) .then(r => r.data)
.catch(() => null) .catch(() => null)
}; };
}
catch {
return null;
}
} }
async function getErrorContext(id) { async function getErrorContext(id) {