From 885d36d4e47aa225ab3a35ef4dc3c065ccfff2f3 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Fri, 5 Feb 2021 16:28:31 +0530 Subject: [PATCH] [youtube] Fix comment extraction (Closes #53) :ci skip dl --- youtube_dlc/extractor/youtube.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/youtube_dlc/extractor/youtube.py b/youtube_dlc/extractor/youtube.py index 44c8f0eb0..d46546e06 100644 --- a/youtube_dlc/extractor/youtube.py +++ b/youtube_dlc/extractor/youtube.py @@ -1999,8 +1999,10 @@ class YoutubeIE(YoutubeBaseInfoExtractor): raise ExtractorError('Unexpected HTTP error code: %s' % response_code) first_continuation = True + chain_msg = '' + self.to_screen('Downloading comments') while continuations: - continuation, itct = continuations.pop() + continuation = continuations.pop() comment_response = get_continuation(continuation, xsrf_token) if not comment_response: continue @@ -2046,9 +2048,10 @@ class YoutubeIE(YoutubeBaseInfoExtractor): continue if self._downloader.params.get('verbose', False): - self.to_screen('[debug] Comments downloaded (chain %s) %s of ~%s' % (comment['commentId'], len(video_comments), expected_video_comment_count)) + chain_msg = ' (chain %s)' % comment['commentId'] + self.to_screen('Comments downloaded: %d of ~%d%s' % (len(video_comments), expected_video_comment_count, chain_msg)) reply_comment_meta = replies_data[1]['response']['continuationContents']['commentRepliesContinuation'] - for reply_meta in replies_data[1]['response']['continuationContents']['commentRepliesContinuation']['contents']: + for reply_meta in reply_comment_meta.get('contents', {}): reply_comment = reply_meta['commentRenderer'] video_comments.append({ 'id': reply_comment['commentId'], @@ -2063,12 +2066,12 @@ class YoutubeIE(YoutubeBaseInfoExtractor): continue reply_continuations += [rcn['nextContinuationData']['continuation'] for rcn in reply_comment_meta['continuations']] - self.to_screen('Comments downloaded %s of ~%s' % (len(video_comments), expected_video_comment_count)) + self.to_screen('Comments downloaded: %d of ~%d' % (len(video_comments), expected_video_comment_count)) if 'continuations' in item_section: continuations += [ncd['nextContinuationData']['continuation'] for ncd in item_section['continuations']] time.sleep(1) - self.to_screen('Total comments downloaded %s of ~%s' % (len(video_comments), expected_video_comment_count)) + self.to_screen('Total comments downloaded: %d of ~%d' % (len(video_comments), expected_video_comment_count)) info.update({ 'comments': video_comments, 'comment_count': expected_video_comment_count