tiktok: improve web-app parsing error handling

This commit is contained in:
Damir Modyarov 2024-05-21 16:24:18 +03:00
parent 97850e08af
commit 6e8af30227
No known key found for this signature in database

View File

@ -38,11 +38,17 @@ export default async function(obj) {
updateCookie(cookie, res.headers) updateCookie(cookie, res.headers)
const html = await res.text() const html = await res.text()
let detail
try {
const json = html const json = html
.split('<script id="__UNIVERSAL_DATA_FOR_REHYDRATION__" type="application/json">')[1] .split('<script id="__UNIVERSAL_DATA_FOR_REHYDRATION__" type="application/json">')[1]
.split('</script>')[0] .split('</script>')[0]
const data = JSON.parse(json) const data = JSON.parse(json)
const detail = data["__DEFAULT_SCOPE__"]["webapp.video-detail"]["itemInfo"]["itemStruct"] detail = data["__DEFAULT_SCOPE__"]["webapp.video-detail"]["itemInfo"]["itemStruct"]
} catch {
return { error: 'ErrorCouldntFetch' };
}
let video, videoFilename, audioFilename, audio, images, let video, videoFilename, audioFilename, audio, images,
filenameBase = `tiktok_${detail.author.uniqueId}_${postId}`, filenameBase = `tiktok_${detail.author.uniqueId}_${postId}`,