mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-29 22:24:25 +01:00
[extractor/youtube] Differentiate between no and disabled comments (#5491)
`comments` and `comment_count` will be set to None, as opposed to an empty list and 0, respectively. Fixes https://github.com/yt-dlp/yt-dlp/issues/5068 Authored by: coletdjnz, pukkandan
This commit is contained in:
parent
dc3028d233
commit
0cf643b234
2 changed files with 6 additions and 0 deletions
|
@ -3738,6 +3738,9 @@ class InfoExtractor:
|
||||||
def _get_subtitles(self, *args, **kwargs):
|
def _get_subtitles(self, *args, **kwargs):
|
||||||
raise NotImplementedError('This method must be implemented by subclasses')
|
raise NotImplementedError('This method must be implemented by subclasses')
|
||||||
|
|
||||||
|
class CommentsDisabled(Exception):
|
||||||
|
"""Raise in _get_comments if comments are disabled for the video"""
|
||||||
|
|
||||||
def extract_comments(self, *args, **kwargs):
|
def extract_comments(self, *args, **kwargs):
|
||||||
if not self.get_param('getcomments'):
|
if not self.get_param('getcomments'):
|
||||||
return None
|
return None
|
||||||
|
@ -3753,6 +3756,8 @@ class InfoExtractor:
|
||||||
interrupted = False
|
interrupted = False
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.to_screen('Interrupted by user')
|
self.to_screen('Interrupted by user')
|
||||||
|
except self.CommentsDisabled:
|
||||||
|
return {'comments': None, 'comment_count': None}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.get_param('ignoreerrors') is not True:
|
if self.get_param('ignoreerrors') is not True:
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -3270,6 +3270,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||||
message = self._get_text(root_continuation_data, ('contents', ..., 'messageRenderer', 'text'), max_runs=1)
|
message = self._get_text(root_continuation_data, ('contents', ..., 'messageRenderer', 'text'), max_runs=1)
|
||||||
if message and not parent and tracker['running_total'] == 0:
|
if message and not parent and tracker['running_total'] == 0:
|
||||||
self.report_warning(f'Youtube said: {message}', video_id=video_id, only_once=True)
|
self.report_warning(f'Youtube said: {message}', video_id=video_id, only_once=True)
|
||||||
|
raise self.CommentsDisabled
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _generate_comment_continuation(video_id):
|
def _generate_comment_continuation(video_id):
|
||||||
|
|
Loading…
Reference in a new issue