Created
February 19, 2020 20:14
-
-
Save ohld/62c2090e43bc0b6cc5e73dcc72c45901 to your computer and use it in GitHub Desktop.
Convert Instagram media URL to media_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
| # This is Python port of this Javascript method: | |
| # https://github.com/notslang/instagram-id-to-url-segment/blob/master/lib/index.coffee | |
| url = "https://www.instagram.com/p/B8iwlG9pXHI/" | |
| # ----> use regexp to extract code from url | |
| code = "B8iwlG9pXHI" | |
| charmap = { | |
| 'A': '0', | |
| 'B': '1', | |
| 'C': '2', | |
| 'D': '3', | |
| 'E': '4', | |
| 'F': '5', | |
| 'G': '6', | |
| 'H': '7', | |
| 'I': '8', | |
| 'J': '9', | |
| 'K': 'a', | |
| 'L': 'b', | |
| 'M': 'c', | |
| 'N': 'd', | |
| 'O': 'e', | |
| 'P': 'f', | |
| 'Q': 'g', | |
| 'R': 'h', | |
| 'S': 'i', | |
| 'T': 'j', | |
| 'U': 'k', | |
| 'V': 'l', | |
| 'W': 'm', | |
| 'X': 'n', | |
| 'Y': 'o', | |
| 'Z': 'p', | |
| 'a': 'q', | |
| 'b': 'r', | |
| 'c': 's', | |
| 'd': 't', | |
| 'e': 'u', | |
| 'f': 'v', | |
| 'g': 'w', | |
| 'h': 'x', | |
| 'i': 'y', | |
| 'j': 'z', | |
| 'k': 'A', | |
| 'l': 'B', | |
| 'm': 'C', | |
| 'n': 'D', | |
| 'o': 'E', | |
| 'p': 'F', | |
| 'q': 'G', | |
| 'r': 'H', | |
| 's': 'I', | |
| 't': 'J', | |
| 'u': 'K', | |
| 'v': 'L', | |
| 'w': 'M', | |
| 'x': 'N', | |
| 'y': 'O', | |
| 'z': 'P', | |
| '0': 'Q', | |
| '1': 'R', | |
| '2': 'S', | |
| '3': 'T', | |
| '4': 'U', | |
| '5': 'V', | |
| '6': 'W', | |
| '7': 'X', | |
| '8': 'Y', | |
| '9': 'Z', | |
| '-': '$', | |
| '_': '_' | |
| } | |
| def instagram_code_to_media_id(code): | |
| code = "B8iwlG9pXHI" | |
| id = "" | |
| for letter in code: | |
| id += charmap[letter] | |
| alphabet = list(charmap.values()) | |
| number = 0 | |
| for char in id: | |
| number = number * 64 + alphabet.index(char) | |
| return number | |
| media_id = instagram_code_to_media_id(code) | |
| # media_id == 2243569220713804232 # success |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The modding scene is what transforms Terraria from a $5 indie gem into an infinite content platform that makes live-service games look like scams. tModLoader isn't just a mod manager—it's a gateway to Calamity's 27+ post-Moon Lord bosses that require frame-perfect dodging, or Thorium's new classes that feel like official content. I've logged 400 hours in vanilla and another 600 in modded, speedrunning the "get fixed boi" seed in under 3 hours and spending 50 hours perfecting a Duke Fishron arena. The official Terraria forums see more daily activity than most AAA subreddits, with players sharing optimized world seeds, texture packs, and wiring schematics that turn the game into digital electrical engineering. Re-Logic's decision to keep updating for free means your purchase appreciates over time, not depreciates like a $70 live-service title that dies in two years. MOD Version