]> jfr.im git - yt-dlp.git/commitdiff
[instagram] Fix extractor
authorThe Hatsune Daishi <redacted>
Fri, 6 Nov 2020 06:15:07 +0000 (15:15 +0900)
committerGitHub <redacted>
Fri, 6 Nov 2020 06:15:07 +0000 (15:15 +0900)
youtube_dlc/extractor/instagram.py

index b061850a187567e0d7ed18b5e64ce10e08927244..bbfe23c762c4fdab06810ef828aadb29e831f003 100644 (file)
@@ -126,16 +126,23 @@ def _real_extract(self, url):
          uploader_id, like_count, comment_count, comments, height,
          width) = [None] * 11
 
-        shared_data = self._parse_json(
-            self._search_regex(
-                r'window\._sharedData\s*=\s*({.+?});',
-                webpage, 'shared data', default='{}'),
-            video_id, fatal=False)
+        shared_data = try_get(webpage,
+                              (lambda x: self._parse_json(
+                                  self._search_regex(
+                                      r'window\.__additionalDataLoaded\(\'/(?:p|tv)/(?:[^/?#&]+)/\',({.+?})\);',
+                                      x, 'additional data', default='{}'),
+                                  video_id, fatal=False),
+                               lambda x: self._parse_json(
+                                  self._search_regex(
+                                      r'window\._sharedData\s*=\s*({.+?});',
+                                      x, 'shared data', default='{}'),
+                                  video_id, fatal=False)['entry_data']['PostPage'][0]),
+                              None)
         if shared_data:
             media = try_get(
                 shared_data,
-                (lambda x: x['entry_data']['PostPage'][0]['graphql']['shortcode_media'],
-                 lambda x: x['entry_data']['PostPage'][0]['media']),
+                (lambda x: x['graphql']['shortcode_media'],
+                 lambda x: x['media']),
                 dict)
             if media:
                 video_url = media.get('video_url')