[instagram] Fix comment count extraction

This commit is contained in:
=?UTF-8?q?Sergey=20M=E2=80=A4?= 2021-02-26 15:39:04 +01:00 committed by Laura Liberda
parent 477e444c3b
commit 97c3432659

View file

@ -164,12 +164,18 @@ class InstagramIE(InfoExtractor):
uploader = media.get('owner', {}).get('full_name')
uploader_id = media.get('owner', {}).get('username')
def get_count(key, kind):
return int_or_none(try_get(
media, (lambda x: x['edge_media_%s' % key]['count'],
lambda x: x['%ss' % kind]['count'])))
def get_count(keys, kind):
if not isinstance(keys, (list, tuple)):
keys = [keys]
for key in keys:
count = int_or_none(try_get(
media, (lambda x: x['edge_media_%s' % key]['count'],
lambda x: x['%ss' % kind]['count'])))
if count is not None:
return count
like_count = get_count('preview_like', 'like')
comment_count = get_count('to_comment', 'comment')
comment_count = get_count(
('preview_comment', 'to_comment', 'to_parent_comment'), 'comment')
comments = [{
'author': comment.get('user', {}).get('username'),