diff options
author | Astound <kirito@disroot.org> | 2024-01-22 05:59:11 +0800 |
---|---|---|
committer | Astound <kirito@disroot.org> | 2024-01-22 05:59:11 +0800 |
commit | 51a16937891ebb6d419ad21d0189182cb1197430 (patch) | |
tree | 59a87f94f9b22f7785db7d54c697abc83a99e1ac /youtube | |
parent | ca4a7356924450f21228e823b4bcc1416aea05d3 (diff) | |
download | yt-local-51a16937891ebb6d419ad21d0189182cb1197430.tar.lz yt-local-51a16937891ebb6d419ad21d0189182cb1197430.tar.xz yt-local-51a16937891ebb6d419ad21d0189182cb1197430.zip |
Fix comment count extraction due to 'K/M' postfixes
YouTube now displays 2K comments instead of 2359, for instance
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/__init__.py | 5 | ||||
-rw-r--r-- | youtube/templates/watch.html | 2 | ||||
-rw-r--r-- | youtube/yt_data_extract/watch_extraction.py | 6 |
3 files changed, 8 insertions, 5 deletions
diff --git a/youtube/__init__.py b/youtube/__init__.py index b0e8761..64aed56 100644 --- a/youtube/__init__.py +++ b/youtube/__init__.py @@ -54,7 +54,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) diff --git a/youtube/templates/watch.html b/youtube/templates/watch.html index 9679a28..99dbc6d 100644 --- a/youtube/templates/watch.html +++ b/youtube/templates/watch.html @@ -233,7 +233,7 @@ <div class="comments-area-outer comments-disabled">Comments disabled</div> {% else %} <details class="comments-area-outer" {{'open' if settings.comments_mode == 1 else ''}}> - <summary>{{ comment_count|commatize }} comment{{'s' if comment_count != 1 else ''}}</summary> + <summary>{{ comment_count|commatize }} comment{{'s' if comment_count != '1' else ''}}</summary> <div class="comments-area-inner comments-area"> {% 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 1a926b2..b943d35 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 |