[tiktok] do not fail entire extraction if one post fails (#8962)

This commit is contained in:
CasualYouTuber31
2026-01-30 22:03:59 +00:00
committed by GitHub
parent fd5f5611f6
commit 01657caa15

View File

@@ -57,21 +57,24 @@ class TiktokExtractor(Extractor):
def items(self):
for tiktok_url in self.posts():
try:
tiktok_url = self._sanitize_url(tiktok_url)
data = self._extract_rehydration_data(tiktok_url)
if "webapp.video-detail" not in data:
# Only /video/ links result in the video-detail dict we need.
# Try again using that form of link.
# Only /video/ links result in the video-detail dict we
# need. Try again using that form of link.
tiktok_url = self._sanitize_url(
data["seo.abtest"]["canonical"])
data = self._extract_rehydration_data(tiktok_url)
video_detail = data["webapp.video-detail"]
if not self._check_status_code(video_detail, tiktok_url, "post"):
if not self._check_status_code(
video_detail, tiktok_url, "post"):
continue
post = video_detail["itemInfo"]["itemStruct"]
post["user"] = (a := post.get("author")) and a["uniqueId"] or ""
post["user"] = \
(a := post.get("author")) and a["uniqueId"] or ""
post["date"] = self.parse_timestamp(post["createTime"])
post["post_type"] = "image" if "imagePost" in post else "video"
original_title = title = post["desc"]
@@ -137,7 +140,8 @@ class TiktokExtractor(Extractor):
"type" : ytdl_media,
"image" : None,
"filename" : "",
"extension" : "mp3" if ytdl_media == "audio" else "mp4",
"extension" :
"mp3" if ytdl_media == "audio" else "mp4",
"title" : title,
"num" : 0,
"file_id" : "",
@@ -145,6 +149,10 @@ class TiktokExtractor(Extractor):
"height" : 0,
})
yield Message.Url, "ytdl:" + tiktok_url, post
except Exception as exc:
self.log.traceback(exc)
self.log.error("%s: Failed to extract post (%s: %s)",
tiktok_url, exc.__class__.__name__, exc)
def _sanitize_url(self, url):
return text.ensure_http_scheme(url.replace("/photo/", "/video/", 1))