ehmorris / High-Resolution-Downloader-For-Instagram

A Chrome extension for easily downloading high resolution copies of any Instagram photo, video, or story.
GNU General Public License v3.0
89 stars 8 forks source link

Return correct video url on standalone video pages #67

Closed ehmorris closed 3 years ago

ehmorris commented 3 years ago

Partially fixes https://github.com/ehmorris/High-Resolution-Downloader-For-Instagram/issues/64

Instagram has started serving videos as blobs, and the blob URL can't be used to fetch the video data. However, on standalone video pages, the canonical video url can be reliably found in the window object __additionalData (or via the unofficial GraphQL API.)

In an attempt to be as robust as possible, I chose not to rely on the GraphQL API since IG has been known to make frequent changes to it. Instead, this change adds an injected script which ingests __additionalData and _sharedData and finds all the keys named video_url, and then send the first one back to the extension content script.

This doesn't work reliably on the feed and in video modals because sometimes the canonical video url for those videos isn't present anywhere. Also, if a user navigates after having clicked a video, its canonical url remains in __additionalData and gets returned every time a new video is clicked, instead of the new video's url.

In an attempt to mitigate this behavior until a better fix can be released, the extension is reset if the url is a blob and the page is not a standalone page. Unfortunately opening a modal also changes the url path to match the standalone page path, so there's no way to detect when a video is in a modal vs. a standalone page, only when it's on the feed.

I would prefer a more permanent fix that doesn't rely on fetching named JSON data dumps, but I'm releasing this now since there have been lots of complaints in the CWS.