+
+ if not uploader_id:
+ uploader_id = self._search_regex(
+ r'"owner"\s*:\s*{\s*"username"\s*:\s*"(.+?)"',
+ webpage, 'uploader id', fatal=False)
+
+ if not description:
+ description = self._search_regex(
+ r'"caption"\s*:\s*"(.+?)"', webpage, 'description', default=None)
+ if description is not None:
+ description = lowercase_escape(description)
+
+ if not thumbnail:
+ thumbnail = self._og_search_thumbnail(webpage)
+
+ return {
+ 'id': video_id,
+ 'formats': formats,
+ 'ext': 'mp4',
+ 'title': 'Video by %s' % uploader_id,
+ 'description': description,
+ 'thumbnail': thumbnail,
+ 'timestamp': timestamp,
+ 'uploader_id': uploader_id,
+ 'uploader': uploader,
+ 'like_count': like_count,
+ 'comment_count': comment_count,
+ 'comments': comments,
+ }
+
+
+class InstagramUserIE(InfoExtractor):
+ _VALID_URL = r'https?://(?:www\.)?instagram\.com/(?P<id>[^/]{2,})/?(?:$|[?#])'
+ IE_DESC = 'Instagram user profile'
+ IE_NAME = 'instagram:user'
+ _TEST = {
+ 'url': 'https://instagram.com/porsche',
+ 'info_dict': {
+ 'id': 'porsche',
+ 'title': 'porsche',
+ },
+ 'playlist_count': 5,
+ 'params': {
+ 'extract_flat': True,
+ 'skip_download': True,
+ 'playlistend': 5,
+ }
+ }
+
+ def _entries(self, uploader_id):
+ def get_count(suffix):
+ return int_or_none(try_get(
+ node, lambda x: x['edge_media_' + suffix]['count']))
+
+ edges = self._download_json(
+ 'https://www.instagram.com/graphql/query/', uploader_id, query={
+ 'query_hash': '472f257a40c653c64c666ce877d59d2b',
+ 'variables': json.dumps({
+ 'id': uploader_id,
+ 'first': 999999999,
+ })
+ })['data']['user']['edge_owner_to_timeline_media']['edges']
+
+ for edge in edges:
+ node = edge['node']
+
+ if node.get('__typename') != 'GraphVideo' and node.get('is_video') is not True:
+ continue
+ video_id = node.get('shortcode')
+ if not video_id:
+ continue
+
+ info = self.url_result(
+ 'https://instagram.com/p/%s/' % video_id,
+ ie=InstagramIE.ie_key(), video_id=video_id)
+
+ description = try_get(
+ node, lambda x: x['edge_media_to_caption']['edges'][0]['node']['text'],
+ compat_str)
+ thumbnail = node.get('thumbnail_src') or node.get('display_src')
+ timestamp = int_or_none(node.get('taken_at_timestamp'))
+
+ comment_count = get_count('to_comment')
+ like_count = get_count('preview_like')
+ view_count = int_or_none(node.get('video_view_count'))
+
+ info.update({
+ 'description': description,
+ 'thumbnail': thumbnail,
+ 'timestamp': timestamp,
+ 'comment_count': comment_count,
+ 'like_count': like_count,
+ 'view_count': view_count,
+ })
+
+ yield info
+
+ def _real_extract(self, url):
+ username = self._match_id(url)
+ uploader_id = self._download_json(
+ 'https://instagram.com/%s/' % username, username, query={
+ '__a': 1,
+ })['graphql']['user']['id']
+ return self.playlist_result(
+ self._entries(uploader_id), username, username)