diff --git a/youtube/__init__.py b/youtube/__init__.py index b646ab42..9c81a047 100644 --- a/youtube/__init__.py +++ b/youtube/__init__.py @@ -39,7 +39,10 @@ def commatize(num): if num is None: return '' if isinstance(num, str): - num = int(num) + try: + num = int(num) + except ValueError: + return num return '{:,}'.format(num) def timestamp_replacement(match): diff --git a/youtube/templates/watch.html b/youtube/templates/watch.html index e25a917f..d90ab8bd 100644 --- a/youtube/templates/watch.html +++ b/youtube/templates/watch.html @@ -670,7 +670,7 @@

{{ title }}

Comments disabled
{% else %}
- {{ comment_count|commatize }} comment{{'s' if comment_count != 1 else ''}} + {{ comment_count|commatize }} comment{{'s' if comment_count != '1' else ''}}
{% if comments_info %} {{ comments.video_comments(comments_info) }} diff --git a/youtube/yt_data_extract/watch_extraction.py b/youtube/yt_data_extract/watch_extraction.py index b6d12721..24a502f8 100644 --- a/youtube/yt_data_extract/watch_extraction.py +++ b/youtube/yt_data_extract/watch_extraction.py @@ -363,12 +363,12 @@ def _extract_watch_info_mobile(top_level): comment_count_text = extract_str(deep_get(comment_info, 'header', 'commentSectionHeaderRenderer', 'countText')) if comment_count_text == 'Comments': # just this with no number, means 0 comments - info['comment_count'] = 0 + info['comment_count'] = '0' else: - info['comment_count'] = extract_int(comment_count_text) + info['comment_count'] = extract_approx_int(comment_count_text) info['comments_disabled'] = False else: # no comment section present means comments are disabled - info['comment_count'] = 0 + info['comment_count'] = '0' info['comments_disabled'] = True # check for limited state