Skip to content

api/instagram: prefer graphql over embed for posts#1554

Open
ponei wants to merge 1 commit into
imputnet:developfrom
ponei:fix/instagram-first-video
Open

api/instagram: prefer graphql over embed for posts#1554
ponei wants to merge 1 commit into
imputnet:developfrom
ponei:fix/instagram-first-video

Conversation

@ponei

@ponei ponei commented May 8, 2026

Copy link
Copy Markdown

what happened

When scraping the embed HTML for an Instagram post, carousel ("multipost") posts can expose media through a contextJSON payload. This property is empty for single-video posts, but appears for posts with multiple media items.

The problem is that, if a "multipost" has multiple videos, Instagram marks the first video node with is_video, but does not include a usable video_url.

The extractor then checks for both is_video and video_url before treating a node as downloadable video media:

const type = e.node?.is_video && e.node?.video_url ? "video" : "photo";

Because the affected node is missing video_url, the extractor cannot expose it as a video and falls back to treating it as a photo.

This also appears to affect Instagram's official embed for the same "multipost" post. Example from the original issue:

embed2.mp4

what changed

This pull request changes the Instagram post fallback order so that the GraphQL API is tried before the embed HTML scrape.

GraphQL still returns data for single-video posts, and it also returns the correct video_url for the affected "multipost" posts. Keeping embed HTML as a later fallback preserves the existing recovery path without letting incomplete embed data win too early.


This fixes #1550

zImPatrick pushed a commit to zImPatrick/cobalt that referenced this pull request Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant