aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/comments.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-05-09 23:07:43 -0700
committerJames Taylor <user234683@users.noreply.github.com>2019-05-09 23:07:43 -0700
commit9f93b9429c77e631972186049fbc7518e2cf5d4b (patch)
treec5725e6bd218a29e8bd7d818cd596530f38ebbbe /youtube/comments.py
parentc466dcdebea119abb36f12d18a9764014f697dbb (diff)
downloadyt-local-9f93b9429c77e631972186049fbc7518e2cf5d4b.tar.lz
yt-local-9f93b9429c77e631972186049fbc7518e2cf5d4b.tar.xz
yt-local-9f93b9429c77e631972186049fbc7518e2cf5d4b.zip
Fix comment parsing error due to comments from deleted channels
Diffstat (limited to 'youtube/comments.py')
-rw-r--r--youtube/comments.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/youtube/comments.py b/youtube/comments.py
index 4087b47..94b086e 100644
--- a/youtube/comments.py
+++ b/youtube/comments.py
@@ -234,10 +234,7 @@ def parse_comments_polymer(content, replies=False):
comment_raw = comment_raw['commentRenderer']
comment = {
- 'author': yt_data_extract.get_plain_text(comment_raw['authorText']),
- 'author_url': comment_raw['authorEndpoint']['commandMetadata']['webCommandMetadata']['url'],
- 'author_channel_id': comment_raw['authorEndpoint']['browseEndpoint']['browseId'],
- 'author_id': comment_raw['authorId'],
+ 'author_id': comment_raw.get('authorId', ''),
'author_avatar': comment_raw['authorThumbnail']['thumbnails'][0]['url'],
'likes': comment_raw['likeCount'],
'published': yt_data_extract.get_plain_text(comment_raw['publishedTimeText']),
@@ -247,6 +244,16 @@ def parse_comments_polymer(content, replies=False):
'video_id': video_id,
'comment_id': comment_raw['commentId'],
}
+
+ if 'authorText' in comment_raw: # deleted channels have no name or channel link
+ comment['author'] = yt_data_extract.get_plain_text(comment_raw['authorText'])
+ comment['author_url'] = comment_raw['authorEndpoint']['commandMetadata']['webCommandMetadata']['url']
+ comment['author_channel_id'] = comment_raw['authorEndpoint']['browseEndpoint']['browseId']
+ else:
+ comment['author'] = ''
+ comment['author_url'] = ''
+ comment['author_channel_id'] = ''
+
comments.append(comment)
except Exception as e:
print('Error parsing comments: ' + str(e))