[youtube:comments] Improve comment vote count parsing (fixes #506) (#508)

Authored by: colethedj
This commit is contained in:
coletdjnz 2021-07-15 11:24:42 +12:00 committed by GitHub
parent 182b6ae8a6
commit 49bd8c66d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,7 @@ from ..utils import (
intlist_to_bytes, intlist_to_bytes,
mimetype2ext, mimetype2ext,
parse_codecs, parse_codecs,
parse_count,
parse_duration, parse_duration,
qualities, qualities,
remove_start, remove_start,
@ -1992,12 +1993,13 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
text = self._join_text_entries(comment_text_runs) or '' text = self._join_text_entries(comment_text_runs) or ''
comment_time_text = try_get(comment_renderer, lambda x: x['publishedTimeText']['runs']) or [] comment_time_text = try_get(comment_renderer, lambda x: x['publishedTimeText']['runs']) or []
time_text = self._join_text_entries(comment_time_text) time_text = self._join_text_entries(comment_time_text)
# note: timestamp is an estimate calculated from the current time and time_text
timestamp = calendar.timegm(self.parse_time_text(time_text).timetuple()) timestamp = calendar.timegm(self.parse_time_text(time_text).timetuple())
author = try_get(comment_renderer, lambda x: x['authorText']['simpleText'], compat_str) author = try_get(comment_renderer, lambda x: x['authorText']['simpleText'], compat_str)
author_id = try_get(comment_renderer, author_id = try_get(comment_renderer,
lambda x: x['authorEndpoint']['browseEndpoint']['browseId'], compat_str) lambda x: x['authorEndpoint']['browseEndpoint']['browseId'], compat_str)
votes = str_to_int(try_get(comment_renderer, (lambda x: x['voteCount']['simpleText'], votes = parse_count(try_get(comment_renderer, (lambda x: x['voteCount']['simpleText'],
lambda x: x['likeCount']), compat_str)) or 0 lambda x: x['likeCount']), compat_str)) or 0
author_thumbnail = try_get(comment_renderer, author_thumbnail = try_get(comment_renderer,
lambda x: x['authorThumbnail']['thumbnails'][-1]['url'], compat_str) lambda x: x['authorThumbnail']['thumbnails'][-1]['url'], compat_str)