Skip to content

Commit

Permalink
[extractor/youtube] Fix comment loop detection for pinned comments (#…
Browse files Browse the repository at this point in the history
…6714)

Pinned comments may repeat a second time - this is expected.

Fixes #6712

Authored by: coletdjnz
  • Loading branch information
coletdjnz committed Apr 6, 2023
1 parent 68be95b commit 141a8df
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions yt_dlp/extractor/youtube.py
Expand Up @@ -3316,9 +3316,17 @@ def extract_thread(contents):
comment = self._extract_comment(comment_renderer, parent)
if not comment:
continue
is_pinned = bool(traverse_obj(comment_renderer, 'pinnedCommentBadge'))
comment_id = comment['id']
if is_pinned:
tracker['pinned_comment_ids'].add(comment_id)
# Sometimes YouTube may break and give us infinite looping comments.
# See: https://github.com/yt-dlp/yt-dlp/issues/6290
if comment['id'] in tracker['seen_comment_ids']:
if comment_id in tracker['seen_comment_ids']:
if comment_id in tracker['pinned_comment_ids'] and not is_pinned:
# Pinned comments may appear a second time in newest first sort
# See: https://github.com/yt-dlp/yt-dlp/issues/6712
continue
self.report_warning('Detected YouTube comments looping. Stopping comment extraction as we probably cannot get any more.')
yield
else:
Expand Down Expand Up @@ -3348,7 +3356,9 @@ def extract_thread(contents):
current_page_thread=0,
total_parent_comments=0,
total_reply_comments=0,
seen_comment_ids=set())
seen_comment_ids=set(),
pinned_comment_ids=set()
)

# TODO: Deprecated
# YouTube comments have a max depth of 2
Expand Down

0 comments on commit 141a8df

Please sign in to comment.