flurrux / insta-loader

chrome extension for downloading media from instagram
14 stars 2 forks source link

many stories fail to download #28

Closed flurrux closed 2 years ago

flurrux commented 2 years ago

copy-pasted from README:

i've noticed today that many stories fail to download, while some other stories can be downloaded as usual. those stories that fail to download have a blob-url as a src, while the downloader expects an mp4-url.
i don't know the reason for this difference. maybe those stories that were published before the update still continue to work but time will tell.

i have dug into the network requests a little bit and found that there is one request for all stories and its url is https://i.instagram.com/api/v1/feed/reels_media/?reel_ids=[reel ID].
from the response, i was able to find the mp4-url of each story: response.reels_media[0].items[storyIndex].video_versions[0].url.
it looks as if the first item in video_versions is the highest quality one, but each item has a width and height property, so it should be no issue finding the best one.

anyway, i'm trying to fix this asap!

flurrux commented 2 years ago

on the main feed, stories are requested by https://i.instagram.com/api/v1/feed/reels_tray/ and its response has a list of stories at response.tray. here is one such tray-item for illustration:

(only showing the most relevant properties here)

{
  items: [
    {
      ...,
      image_versions: [...],
      video_versions: [...]
    }
  ],
  expiring_at: 1664526409,
  has_video: true,
  id: xxxxxxxxxx /*[10 digit number that i won't show for privacy reasons]*/,
  media_count: 1,
  ranked_position: 1, // the index in response.tray
  reel_type: "user_reel",
  seen: 0,
  seen_ranked_position: 1,
  story_duration_secs: 2
}
flurrux commented 2 years ago

i've managed to repair story-downloads. will push soon. first i need to adjust the downloads of stories from the highlights-tray, as it they are fetched by a slightly different url. main stories are fetched by https://i.instagram.com/api/v1/feed/reels_media/?reel_ids=${userID}, while stories from the highlights-tray are fetched by https://i.instagram.com/api/v1/feed/reels_media/?reel_ids=highlight%3A${reelID} where reelID can be obtained directly from the url which has the form https://www.instagram.com/stories/highlights/${reelID}/.
just wanted to leave this piece of information here.

flurrux commented 2 years ago

this issue should be fixed by 98329438d38a0d1810652c811ff65215bb219f7a.

this is now the main function for downloading stories. when the download-button is pressed in a story, it starts to fetch data about story which contains all of the urls of the other story-items as well. this process takes a good second or two. after that, the adjacent story-items should have no such delay, because all of the data is cached.

there are two types of stories, user_reel and highlight_reel (instagram internally calls them reel instead of story).
user_reel is what you see when you click on a users round profile-picture or on the stories-tray on your main-feed. highlight_reel is what you see when you click on a users highlighted stories beneath the bio.
both cases are handled slightly differently by the downloader as can be seen here and here.

specifically, in order to fetch a user_reel we need to know the users internal ID which is fetched here and causes a small delay. in contrast, a highlight_reel can be fetched immediately as the reel ID is already given in the url.
one other difference is in finding the correct story-item in the fetched data. after fetching story-data, we have a list of story-items and need to find the one we're currently watching. each story-item has an id and if it's a user-item, the id is given in the current url. you can check this for yourself by watching how the url changes as you navigate between story-items.
if we're watching a highlight_reel however, the url does not change from item to item. how to know which item in the array to download? by looking at the progress-bar!