Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed code/shortcode conversion for (private) URLs #1582

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,6 +8,7 @@
from exceptions import ValidationError


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

Expand All @@ -27,8 +28,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