instagram: use different endpoint for getting posts (#432)
This commit is contained in:
commit
6d17ff2e06
1 changed files with 25 additions and 14 deletions
|
@ -70,31 +70,41 @@ async function getPost(id) {
|
||||||
dtsgId = await findDtsgId(cookie);
|
dtsgId = await findDtsgId(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = new URL('https://www.instagram.com/graphql/query/');
|
const url = new URL('https://www.instagram.com/api/graphql/');
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
jazoest: '26297',
|
jazoest: '26406',
|
||||||
variables: JSON.stringify({
|
variables: JSON.stringify({
|
||||||
shortcode: id,
|
shortcode: id,
|
||||||
__relay_internal__pv__PolarisShareMenurelayprovider: false
|
__relay_internal__pv__PolarisShareMenurelayprovider: false
|
||||||
}),
|
}),
|
||||||
doc_id: '24852649951017035'
|
doc_id: '7153618348081770'
|
||||||
};
|
};
|
||||||
if (dtsgId) {
|
if (dtsgId) {
|
||||||
requestData.fb_dtsg = dtsgId;
|
requestData.fb_dtsg = dtsgId;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (await request(url, cookie, 'POST', requestData)).data;
|
data = (await request(url, cookie, 'POST', requestData))
|
||||||
|
.data
|
||||||
|
?.xdt_api__v1__media__shortcode__web_info
|
||||||
|
?.items
|
||||||
|
?.[0];
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
if (!data) return { error: 'ErrorCouldntFetch' };
|
if (!data) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
const sidecar = data?.xdt_shortcode_media?.edge_sidecar_to_children;
|
const carousel = data.carousel_media;
|
||||||
if (sidecar) {
|
if (carousel) {
|
||||||
const picker = sidecar.edges.filter(e => e.node?.display_url)
|
const picker = carousel.filter(e => e?.image_versions2)
|
||||||
.map(e => {
|
.map(e => {
|
||||||
const type = e.node?.is_video ? "video" : "photo";
|
const type = e.video_versions ? "video" : "photo";
|
||||||
const url = type === "video" ? e.node?.video_url : e.node?.display_url;
|
const imageUrl = e.image_versions2.candidates[0].url;
|
||||||
|
|
||||||
|
let url = imageUrl;
|
||||||
|
if (type === 'video') {
|
||||||
|
const video = e.video_versions.reduce((a, b) => a.width * a.height < b.width * b.height ? b : a);
|
||||||
|
url = video.url;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type, url,
|
type, url,
|
||||||
|
@ -103,22 +113,23 @@ async function getPost(id) {
|
||||||
thumb: createStream({
|
thumb: createStream({
|
||||||
service: "instagram",
|
service: "instagram",
|
||||||
type: "default",
|
type: "default",
|
||||||
u: e.node?.display_url,
|
u: imageUrl,
|
||||||
filename: "image.jpg"
|
filename: "image.jpg"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (picker.length) return { picker }
|
if (picker.length) return { picker }
|
||||||
} else if (data?.xdt_shortcode_media?.video_url) {
|
} else if (data.video_versions) {
|
||||||
|
const video = data.video_versions.reduce((a, b) => a.width * a.height < b.width * b.height ? b : a)
|
||||||
return {
|
return {
|
||||||
urls: data.xdt_shortcode_media.video_url,
|
urls: video.url,
|
||||||
filename: `instagram_${id}.mp4`,
|
filename: `instagram_${id}.mp4`,
|
||||||
audioFilename: `instagram_${id}_audio`
|
audioFilename: `instagram_${id}_audio`
|
||||||
}
|
}
|
||||||
} else if (data?.xdt_shortcode_media?.display_url) {
|
} else if (data.image_versions2?.candidates) {
|
||||||
return {
|
return {
|
||||||
urls: data.xdt_shortcode_media.display_url,
|
urls: data.image_versions2.candidates[0].url,
|
||||||
isPhoto: true
|
isPhoto: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue