]> jfr.im git - yt-dlp.git/commitdiff
[youtube:comments] Fix comment section not being extracted in new layouts (#1324)
authorcoletdjnz <redacted>
Mon, 18 Oct 2021 02:58:42 +0000 (15:58 +1300)
committerGitHub <redacted>
Mon, 18 Oct 2021 02:58:42 +0000 (02:58 +0000)
Co-authored-by: coletdjnz, pukkandan
yt_dlp/extractor/youtube.py

index dc9aa8ab70b6c28467a2d10e22039c3567722352..892993c9bbf7349669bd15772221d1dbdad668fd 100644 (file)
@@ -2314,6 +2314,10 @@ def extract_thread(contents):
             continuation_token = self._generate_comment_continuation(video_id)
             continuation = self._build_api_continuation_query(continuation_token, None)
 
+        message = self._get_text(root_continuation_data, ('contents', ..., 'messageRenderer', 'text'), max_runs=1)
+        if message and not parent:
+            self.report_warning(message, video_id=video_id)
+
         visitor_data = None
         is_first_continuation = parent is None
 
@@ -2416,8 +2420,10 @@ def _generate_comment_continuation(video_id):
     def _get_comments(self, ytcfg, video_id, contents, webpage):
         """Entry for comment extraction"""
         def _real_comment_extract(contents):
-            yield from self._comment_entries(
-                traverse_obj(contents, (..., 'itemSectionRenderer'), get_all=False), ytcfg, video_id)
+            renderer = next((
+                item for item in traverse_obj(contents, (..., 'itemSectionRenderer'), default={})
+                if item.get('sectionIdentifier') == 'comment-item-section'), None)
+            yield from self._comment_entries(renderer, ytcfg, video_id)
 
         max_comments = int_or_none(self._configuration_arg('max_comments', [''])[0])
         # Force English regardless of account setting to prevent parsing issues