Skip to content

Commit

Permalink
v7.1.1
Browse files Browse the repository at this point in the history
Fix video download on some situations.
  • Loading branch information
saschaheim committed May 5, 2021
1 parent 5c8d571 commit 4ae06a4
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 118 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [instantgram] v7.1.0
# [instantgram] v7.1.1
![GitHub release](https://img.shields.io/badge/release-v7.0.0-blue)

![badge](https://img.shields.io/badge/for-instagram-yellow.svg?style=flat-square)
Expand Down Expand Up @@ -37,6 +37,7 @@ With this version we support all modern browsers that have ECMAScript 2015 (es6)
Read [CONTRIBUTING.md](CONTRIBUTING.md) for more information. :heart:

## Changelog
- v7.1.1 - [instangram] Fix video download on some situations.
- v7.1.0 - [instangram] Re-design update dialog.
- v7.0.1 - [instangram] Fix update handler.
- v7.0.0 - [instangram] Fix get highest image on every post or story.
Expand Down
2 changes: 1 addition & 1 deletion dist/main.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lang/de-de/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lang/en-us/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lang/pt-br/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "instantgram",
"version": "7.1.0",
"version": "7.1.1",
"description": "A bookmarklet for download photos in Instagram",
"main": "src/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/_langs/partials/button.html

Large diffs are not rendered by default.

96 changes: 5 additions & 91 deletions src/helpers/getBlobVideoUrl.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,11 @@
import forEach from '../helpers/forEach.js'
import getDataFromUrl from '../helpers/getDataFromUrl.js'

export default function getBlobVideoUrl(article, el, pos, callback) {
export default function getBlobVideoUrl(videoEl, callback) {

// Define some things
let isMultiVideo = (pos != null) ? true : false
let userId = null
let userName = article.querySelectorAll('header > div > div > div > span > a')[0].text
let userProfileUrl = article.querySelectorAll('header > div > div > div > span > a')[0].href
let videoUrl = null
const instanceKey = Object.keys(videoEl).find(key => key.includes('Instance'))
const reactVideoEl = videoEl[instanceKey]
const videoUrl = reactVideoEl.return.memoizedProps.fallbackSrc

// Will be used only for single video posts
if (!isMultiVideo) {
var posterRegex = /poster\=\"([\s\S]*)\" preload/gm
var posterRegexMatch = posterRegex.exec(el.outerHTML.replace(/(\r\n|\n|\r)/gm, ''))
var videoPosterUrl = null
if (posterRegexMatch) {
// HACK
let div = document.createElement('textarea')
div.innerHTML = posterRegexMatch[1]
let decoded = div.firstChild.nodeValue
//div.parentNode.removeChild(div)

videoPosterUrl = decoded
}
var videoPosterFilename = videoPosterUrl.split('/').pop().split('#')[0].split('?')[0]
}
//

// Stage 1
// Fetch user id from element
let userProfileUrlResponseData = null
getDataFromUrl(userProfileUrl, function(data) {
userProfileUrlResponseData = data
})

if (userProfileUrlResponseData) {
userProfileUrlResponseData = userProfileUrlResponseData.replace(/(\r\n|\n|\r)/gm, '')

let m
let entries
let regex = /profilePage_([0-9]+)/gm
while ((m = regex.exec(userProfileUrlResponseData)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++
}

// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
userId = match
})
}
}

// Stage 2
// Fetch the user data until the file name is found
if (userId) {
let userMediaFeedResponseData = null
getDataFromUrl('https://www.instagram.com/graphql/query/?query_hash=003056d32c2554def87228bc3fd9668a&variables={"id":' + userId + ',"first":100}', function(data) {
userMediaFeedResponseData = data
})

if (userMediaFeedResponseData) {
let json = JSON.parse(userMediaFeedResponseData)

for (let _fI = 0; _fI < json.data.user.edge_owner_to_timeline_media.edges.length; _fI++) {
// Handle different instagram post types
// Single Video
if (!isMultiVideo) {
if (json.data.user.edge_owner_to_timeline_media.edges[_fI].node.__typename == 'GraphVideo') {
let GraphVideoNode = json.data.user.edge_owner_to_timeline_media.edges[_fI].node
if (videoPosterFilename == GraphVideoNode.display_url.split('/').pop().split('#')[0].split('?')[0]) {
videoUrl = GraphVideoNode.video_url

// There exists only one node so break it no need to further analyze
break
}
}
// Multi Post which can have a video
} else {
if (json.data.user.edge_owner_to_timeline_media.edges[_fI].node.__typename == 'GraphSidecar') {
if (json.data.user.edge_owner_to_timeline_media.edges[_fI].node.hasOwnProperty('edge_sidecar_to_children')) {
let GraphSidecarNode = json.data.user.edge_owner_to_timeline_media.edges[_fI].node.edge_sidecar_to_children.edges[pos].node
videoUrl = GraphSidecarNode.video_url

break
}
}
}
}
}
}

callback(videoUrl ? videoUrl : false)
callback(videoUrl.length > 0 ? videoUrl : false)
}
7 changes: 3 additions & 4 deletions src/modules/searchVideoInFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export default function searchVideoInFeed(program, callback) {
getLoadingDots(modal.modalElem().querySelector('#loading_dot'))
}).afterShow(modal => {
setTimeout(function() {
getBlobVideoUrl($article[i], mediaEl, _currentSelectedControlIndex, function(scrapedBlobVideoUrl) {
if (scrapedBlobVideoUrl) {
modal.close()
getBlobVideoUrl(mediaEl, function(scrapedBlobVideoUrl) {
modal.close()

if (scrapedBlobVideoUrl) {
found = true
program.foundVideo = true
program.foundByModule = 'searchVideoInFeed'
Expand All @@ -132,7 +132,6 @@ export default function searchVideoInFeed(program, callback) {

callback(found, program)
} else {
modal.close()

found = false
program.foundVideo = false
Expand Down
10 changes: 4 additions & 6 deletions src/modules/searchVideoInModalPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function searchVideoInModalPost(program, callback) {

if (videoLink) {
if (videoLink.indexOf('blob:') !== -1) {
let blobLoaderModal = picoModal({
picoModal({
width: 400,
content: "<div style='padding:20px'><h4 style='font-weight:bold;margin-top:0'>[instantgram]<span style='float:right;'>v" + program.VERSION + "</span></h4><br/>" +
"<p style='margin:0;text-align:center'>" + getPreLoader() + "</p>" +
Expand All @@ -128,10 +128,10 @@ export default function searchVideoInModalPost(program, callback) {
getLoadingDots(modal.modalElem().querySelector('#loading_dot'))
}).afterShow(modal => {
setTimeout(function() {
getBlobVideoUrl($article, mediaEl, _currentSelectedControlIndex, function(scrapedBlobVideoUrl) {
if (scrapedBlobVideoUrl) {
blobLoaderModal.close()
getBlobVideoUrl(mediaEl, function(scrapedBlobVideoUrl) {
modal.close()

if (scrapedBlobVideoUrl) {
found = true
program.foundVideo = true
program.foundByModule = 'searchVideoInModalPost'
Expand All @@ -140,8 +140,6 @@ export default function searchVideoInModalPost(program, callback) {

callback(found, program)
} else {
blobLoaderModal.close()

found = false
program.foundVideo = false
program.foundByModule = 'searchVideoInModalPost'
Expand Down
8 changes: 3 additions & 5 deletions src/modules/searchVideoInPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export default function searchVideoInPost(program, callback) {
getLoadingDots(modal.modalElem().querySelector('#loading_dot'))
}).afterShow(modal => {
setTimeout(function() {
getBlobVideoUrl($article[i], mediaEl, _currentSelectedControlIndex, function(scrapedBlobVideoUrl) {
if (scrapedBlobVideoUrl) {
modal.close()
getBlobVideoUrl(mediaEl, function(scrapedBlobVideoUrl) {
modal.close()

if (scrapedBlobVideoUrl) {
found = true
program.foundVideo = true
program.foundByModule = 'searchVideoInPost'
Expand All @@ -132,8 +132,6 @@ export default function searchVideoInPost(program, callback) {

callback(found, program)
} else {
modal.close()

found = false
program.foundVideo = false
program.foundByModule = 'searchVideoInPost'
Expand Down

0 comments on commit 4ae06a4

Please sign in to comment.