diff --git a/instagrapi/config.py b/instagrapi/config.py index 02fe686b..e87d6c55 100644 --- a/instagrapi/config.py +++ b/instagrapi/config.py @@ -1,8 +1,6 @@ SIG_KEY_VERSION = "4" IG_SIG_KEY = "a86109795736d73c9a94172cd9b736917d7d94ca61c9101164894b3f0d43bef4" - API_DOMAIN = "i.instagram.com" -API_URL = "https://{domain}/api/v1/".format(domain=API_DOMAIN) # Instagram 134.0.0.26.121 # Android (26/8.0.0; diff --git a/instagrapi/mixins/media.py b/instagrapi/mixins/media.py index 78105882..f853f892 100644 --- a/instagrapi/mixins/media.py +++ b/instagrapi/mixins/media.py @@ -2,6 +2,7 @@ import random import time from copy import deepcopy +from datetime import datetime from typing import Dict, List from urllib.parse import urlparse @@ -526,3 +527,41 @@ def user_medias(self, user_id: int, amount: int = 50) -> List[Media]: # it is better to try through a Private API) medias = self.user_medias_v1(user_id, amount) return medias + + def media_seen(self, media_ids: List[str], skipped_media_ids: List[str] = []): + """ + Mark a media as seen + + Parameters + ---------- + media_id: str + + Returns + ------- + bool + A boolean value + """ + + def gen(media_ids): + result = {} + for media_id in media_ids: + media_pk, user_id = self.media_id(media_id).split('_') + end = int(datetime.now().timestamp()) + begin = end - random.randint(100, 3000) + result[f"{media_pk}_{user_id}_{user_id}"] = [f"{begin}_{end}"] + return result + + data = { + "container_module": "feed_timeline", + "live_vods_skipped": {}, + "nuxes_skipped": {}, + "nuxes": {}, + "reels": gen(media_ids), + "live_vods": {}, + "reel_media_skipped": gen(skipped_media_ids) + } + result = self.private_request( + "/v2/media/seen/?reel=1&live_vod=0", + self.with_default_data(data) + ) + return result["status"] == "ok" diff --git a/instagrapi/mixins/private.py b/instagrapi/mixins/private.py index 26eab96c..bbb7a5e3 100644 --- a/instagrapi/mixins/private.py +++ b/instagrapi/mixins/private.py @@ -174,8 +174,6 @@ def _send_private_request( self.last_response = None self.last_json = last_json = {} # for Sentry context in traceback self.private.headers.update(self.base_headers) - if endpoint.startswith("/"): - endpoint = endpoint[1:] if headers: self.private.headers.update(headers) if not login: @@ -183,6 +181,9 @@ def _send_private_request( if self.user_id and login: raise Exception(f"User already login ({self.user_id})") try: + if not endpoint.startswith('/'): + endpoint = f"/v1/{endpoint}" + api_url = f"https://{config.API_DOMAIN}/api{endpoint}" if data: # POST # Client.direct_answer raw dict # data = json.dumps(data) @@ -192,11 +193,10 @@ def _send_private_request( if extra_sig: data += "&".join(extra_sig) response = self.private.post( - config.API_URL + endpoint, data=data, params=params + api_url, data=data, params=params ) else: # GET - response = self.private.get( - config.API_URL + endpoint, params=params) + response = self.private.get(api_url, params=params) self.logger.debug( "private_request %s: %s (%s)", response.status_code, response.url, response.text ) diff --git a/instagrapi/mixins/story.py b/instagrapi/mixins/story.py index 1ac335b9..eb5b0d29 100644 --- a/instagrapi/mixins/story.py +++ b/instagrapi/mixins/story.py @@ -126,3 +126,21 @@ def user_stories(self, user_id: int, amount: int = None) -> List[Story]: """ # TODO: Add user_stories_gql return self.user_stories_v1(user_id, amount) + + def story_seen(self, story_pks: List[int], skipped_story_pks: List[int] = []): + """ + Mark a story as seen + + Parameters + ---------- + story_pk: int + + Returns + ------- + bool + A boolean value + """ + return self.media_seen( + [self.media_id(mid) for mid in story_pks], + [self.media_id(mid) for mid in skipped_story_pks] + ) diff --git a/setup.py b/setup.py index 57fc62b4..d05924bc 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup( name='instagrapi', - version='1.4.4', + version='1.4.5', author='Mikhail Andreev', author_email='x11org@gmail.com', license='MIT',