From 132b8454899155bfb90b60bb6330e3cd619a35ac Mon Sep 17 00:00:00 2001 From: Lyubomyr Shaydariv Date: Sat, 16 Sep 2023 20:53:22 +0300 Subject: [PATCH] Fixed code/shortcode conversion for (private) URLs --- instagrapi/mixins/media.py | 2 +- instagrapi/utils.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/instagrapi/mixins/media.py b/instagrapi/mixins/media.py index 48ec4a7c..4980079e 100644 --- a/instagrapi/mixins/media.py +++ b/instagrapi/mixins/media.py @@ -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: """ diff --git a/instagrapi/utils.py b/instagrapi/utils.py index c4834108..f62dcd67 100644 --- a/instagrapi/utils.py +++ b/instagrapi/utils.py @@ -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