aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2020-12-26 22:58:27 +0700
committerSergey M․ <dstftw@gmail.com>2020-12-26 23:00:15 +0700
commit12053450dceda14ec63e3e721c72731f2cc40b34 (patch)
tree2316480bc92a525506c1a4250cebd4490aaed3fd
parent46cffb0c47bf57b7aba45916bae6cb4092965686 (diff)
[instagram] Fix comment count extraction
-rw-r--r--youtube_dl/extractor/instagram.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/youtube_dl/extractor/instagram.py b/youtube_dl/extractor/instagram.py
index e15508fca..07c8df7a6 100644
--- a/youtube_dl/extractor/instagram.py
+++ b/youtube_dl/extractor/instagram.py
@@ -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'),