[tiktok] detect private videos(closes #28453)
authorRemita Amine <remitamine@gmail.com>
Sun, 21 Mar 2021 08:10:38 +0000 (09:10 +0100)
committerRemita Amine <remitamine@gmail.com>
Sun, 21 Mar 2021 08:10:38 +0000 (09:10 +0100)
youtube_dl/extractor/tiktok.py

index ea1beb8af7dfa2cd44057c0be88960819435095d..4faa6de543fd1d086c2daa3a384d9f6c7b057408 100644 (file)
@@ -107,9 +107,12 @@ class TikTokIE(TikTokBaseIE):
     def _real_extract(self, url):
         video_id = self._match_id(url)
         webpage = self._download_webpage(url, video_id)
-        data = self._parse_json(self._search_regex(
+        page_props = self._parse_json(self._search_regex(
             r'<script[^>]+\bid=["\']__NEXT_DATA__[^>]+>\s*({.+?})\s*</script',
-            webpage, 'data'), video_id)['props']['pageProps']['itemInfo']['itemStruct']
+            webpage, 'data'), video_id)['props']['pageProps']
+        data = try_get(page_props, lambda x: x['itemInfo']['itemStruct'], dict)
+        if not data and page_props.get('statusCode') == 10216:
+            raise ExtractorError('This video is private', expected=True)
         return self._extract_video(data, video_id)