From 99ea2978757a431eeb2a265b3395ccbe4ce202cf Mon Sep 17 00:00:00 2001 From: bashonly <88596187+bashonly@users.noreply.github.com> Date: Sun, 23 Feb 2025 00:53:13 -0600 Subject: [PATCH] [ie/tiktok] Improve error handling (#12445) Closes #8678 Authored by: bashonly --- yt_dlp/extractor/tiktok.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/yt_dlp/extractor/tiktok.py b/yt_dlp/extractor/tiktok.py index 9e53b34072..19336252b1 100644 --- a/yt_dlp/extractor/tiktok.py +++ b/yt_dlp/extractor/tiktok.py @@ -249,6 +249,12 @@ class TikTokBaseIE(InfoExtractor): elif fatal: raise ExtractorError('Unable to extract webpage video data') + if not traverse_obj(video_data, ('video', {dict})) and traverse_obj(video_data, ('isContentClassified', {bool})): + message = 'This post may not be comfortable for some audiences. Log in for access' + if fatal: + self.raise_login_required(message) + self.report_warning(f'{message}. {self._login_hint()}', video_id=video_id) + return video_data, status def _get_subtitles(self, aweme_detail, aweme_id, user_name): @@ -895,8 +901,12 @@ class TikTokIE(TikTokBaseIE): if video_data and status == 0: return self._parse_aweme_video_web(video_data, url, video_id) - elif status == 10216: - raise ExtractorError('This video is private', expected=True) + elif status in (10216, 10222): + # 10216: private post; 10222: private account + self.raise_login_required( + 'You do not have permission to view this post. Log into an account that has access') + elif status == 10204: + raise ExtractorError('Your IP address is blocked from accessing this post', expected=True) raise ExtractorError(f'Video not available, status code {status}', video_id=video_id)