From 3bf20ffb70e2f0cb9c9b9c167c57945a25d31d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 10 Aug 2019 13:45:59 +0200 Subject: [PATCH] [instagram] add support for story highlights --- gallery_dl/extractor/instagram.py | 39 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/gallery_dl/extractor/instagram.py b/gallery_dl/extractor/instagram.py index 41eb3ea3..b2113fe9 100644 --- a/gallery_dl/extractor/instagram.py +++ b/gallery_dl/extractor/instagram.py @@ -140,29 +140,37 @@ class InstagramExtractor(Extractor): return medias def _extract_stories(self, url): - page = self.request(url).text - shared_data = self._extract_shared_data(page) + if self.highlight_id: + user_id = '' + highlight_id = '"{}"'.format(self.highlight_id) + query_hash = '30a89afdd826d78a5376008a7b81c205' + else: + page = self.request(url).text + shared_data = self._extract_shared_data(page) - # If no stories are present the URL redirect to `ProfilePage' - if 'StoriesPage' not in shared_data['entry_data']: - return [] + # If no stories are present the URL redirects to `ProfilePage' + if 'StoriesPage' not in shared_data['entry_data']: + return [] + + user_id = '"{}"'.format( + shared_data['entry_data']['StoriesPage'][0]['user']['id']) + highlight_id = '' + query_hash = 'cda12de4f7fd3719c0569ce03589f4c4' - user_id = shared_data['entry_data']['StoriesPage'][0]['user']['id'] variables = ( '{{' - '"reel_ids":["{user_id}"],' - '"tag_names":[],"location_ids":[],' - '"highlight_reel_ids":[],"precomposed_overlay":true,' + '"reel_ids":[{}],"tag_names":[],"location_ids":[],' + '"highlight_reel_ids":[{}],"precomposed_overlay":true,' '"show_story_viewer_list":true,' '"story_viewer_fetch_count":50,"story_viewer_cursor":"",' '"stories_video_dash_manifest":false}}' - ).format(user_id=user_id) + ).format(user_id, highlight_id) headers = { "X-Requested-With": "XMLHttpRequest", } url = '{}/graphql/query/?query_hash={}&variables={}'.format( self.root, - 'cda12de4f7fd3719c0569ce03589f4c4', + query_hash, variables, ) shared_data = self.request(url, headers=headers).json() @@ -440,12 +448,15 @@ class InstagramStoriesExtractor(InstagramExtractor): """Extractor for StoriesPage""" subcategory = "stories" pattern = (r"(?:https?://)?(?:www\.)?instagram\.com" - r"/stories/([^/?&#]+)") - test = ("https://www.instagram.com/stories/instagram/",) + r"/stories/([^/?&#]+)(?:/(\d+))?") + test = ( + ("https://www.instagram.com/stories/instagram/"), + ("https://www.instagram.com/stories/highlights/18042509488170095/"), + ) def __init__(self, match): InstagramExtractor.__init__(self, match) - self.username = match.group(1) + self.username, self.highlight_id = match.groups() def instagrams(self): url = '{}/stories/{}/'.format(self.root, self.username)