instagram: use different endpoint for getting posts (#432)

This commit is contained in:
wukko 2024-04-17 11:03:42 +06:00 committed by GitHub
commit 6d17ff2e06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
} }
} }