Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed code/shortcode conversion for (private) URLs
Browse files Browse the repository at this point in the history
lyubomyr-shaydariv committed Jan 1, 2024
1 parent c74dafe commit 3cee7c7
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion instagrapi/mixins/media.py
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ def media_pk_from_code(self, code: str) -> str:
B-fKL9qpeab -> 2278584739065882267
CCQQsCXjOaBfS3I2PpqsNkxElV9DXj61vzo5xs0 -> 2346448800803776129
"""
return InstagramIdCodec.decode(code[:11])
return InstagramIdCodec.decode(code)

def media_pk_from_url(self, url: str) -> str:
"""
6 changes: 4 additions & 2 deletions instagrapi/utils.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import urllib


# $$("meta[property^='al:ios:url']")[0].getAttribute("content").split("media?id=")[1]
class InstagramIdCodec:
ENCODING_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"

@@ -26,8 +27,9 @@ def encode(num, alphabet=ENCODING_CHARS):
return "".join(arr)

@staticmethod
def decode(shortcode, alphabet=ENCODING_CHARS):
"""Covert a shortcode to a numeric value."""
def decode(code, alphabet=ENCODING_CHARS):
"""Covert a code to a numeric value."""
shortcode = code[:11] if code[0] != "-" and code[0] != "_" else code[:10]
base = len(alphabet)
strlen = len(shortcode)
num = 0

0 comments on commit 3cee7c7

Please sign in to comment.