+
+ 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):
+ query = {
+ '__a': 1,
+ }
+
+ def get_count(kind):
+ return int_or_none(try_get(
+ node, lambda x: x['%ss' % kind]['count']))
+
+ for page_num in itertools.count(1):
+ page = self._download_json(
+ 'https://instagram.com/%s/' % uploader_id, uploader_id,
+ note='Downloading page %d' % page_num,
+ fatal=False, query=query)
+ if not page:
+ break
+
+ nodes = try_get(page, lambda x: x['user']['media']['nodes'], list)
+ if not nodes:
+ break
+
+ max_id = None
+
+ for node in nodes:
+ node_id = node.get('id')
+ if node_id:
+ max_id = node_id
+
+ if node.get('__typename') != 'GraphVideo' and node.get('is_video') is not True:
+ continue
+ video_id = node.get('code')
+ 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['caption'], lambda x: x['text']['id']],
+ compat_str)
+ thumbnail = node.get('thumbnail_src') or node.get('display_src')
+ timestamp = int_or_none(node.get('date'))
+
+ comment_count = get_count('comment')
+ like_count = get_count('like')
+ view_count = int_or_none(node.get('video_views'))
+
+ info.update({
+ 'description': description,
+ 'thumbnail': thumbnail,
+ 'timestamp': timestamp,
+ 'comment_count': comment_count,
+ 'like_count': like_count,
+ 'view_count': view_count,
+ })
+
+ yield info
+
+ if not max_id:
+ break
+
+ query['max_id'] = max_id
+
+ def _real_extract(self, url):
+ uploader_id = self._match_id(url)
+ return self.playlist_result(
+ self._entries(uploader_id), uploader_id, uploader_id)