Skip to content

Commit

Permalink
Fixed code/shortcode conversion for (private) URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
lyubomyr-shaydariv committed Nov 12, 2023
1 parent 073b748 commit 5501476
Show file tree
Hide file tree
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
Expand Up @@ -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:
"""
Expand Down
6 changes: 4 additions & 2 deletions instagrapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import urllib


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

Expand All @@ -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
Expand Down

0 comments on commit 5501476

Please sign in to comment.