From d59a219b65329fdd97a8aa37895fbae2374d409a Mon Sep 17 00:00:00 2001 From: Dan <31395415+cakedan@users.noreply.github.com> Date: Sun, 19 Feb 2023 10:30:02 -0700 Subject: [PATCH] [extractor/instagram] Fix Login Script Parsing Fix login script for instagram --- yt_dlp/extractor/instagram.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yt_dlp/extractor/instagram.py b/yt_dlp/extractor/instagram.py index 02335138f1..c8ba76c9e4 100644 --- a/yt_dlp/extractor/instagram.py +++ b/yt_dlp/extractor/instagram.py @@ -58,14 +58,15 @@ def _perform_login(self, username, password): self._LOGIN_URL, None, note='Downloading login webpage', errnote='Failed to download login webpage') shared_data = self._parse_json(self._search_regex( - r'window\._sharedData\s*=\s*({.+?});', login_webpage, 'shared data', default='{}'), None) + r'\["XIGSharedData",\s*\[\],\s*({.+?}),\d+\]', login_webpage, 'shared data', default='{}'), None) + shared_data = shared_data.get('native', {}) login = self._download_json( f'{self._LOGIN_URL}/ajax/', None, note='Logging in', headers={ **self._API_HEADERS, 'X-Requested-With': 'XMLHttpRequest', - 'X-CSRFToken': shared_data['config']['csrf_token'], - 'X-Instagram-AJAX': shared_data['rollout_hash'], + 'X-CSRFToken': shared_data.get('config', {}).get('csrf_token'), + 'X-Instagram-AJAX': shared_data.get('rollout_hash'), 'Referer': 'https://www.instagram.com/', }, data=urlencode_postdata({ 'enc_password': f'#PWD_INSTAGRAM_BROWSER:0:{int(time.time())}:{password}',