Last active
December 8, 2020 19:33
-
-
Save warlock/56bf4f634ebfeb223e6f8079a9e53d90 to your computer and use it in GitHub Desktop.
Instagram Get ID from URL or Short
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const shortcodeToInstaID = Shortcode => { | |
var char | |
var id = 0 | |
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_' | |
for (var i = 0; i < Shortcode.length; i++) { | |
char = Shortcode[i] | |
var mul = id * 64 | |
id = mul + alphabet.indexOf(char) | |
} | |
return id | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getInstagramUrlFromMediaId(media_id) { | |
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | |
var shortenedId = ''; | |
media_id = media_id.substring(0, media_id.indexOf('_')); | |
while (media_id > 0) { | |
var remainder = bigInt(media_id).mod(64); | |
media_id = bigInt(media_id).minus(remainder).divide(64).toString(); | |
shortenedId = alphabet.charAt(remainder) + shortenedId; | |
} | |
return 'https://www.instagram.com/p/' + shortenedId + '/'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment