metascraper-tiktok 5.56.2 → 5.58.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.js +32 -13
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-tiktok",
|
|
3
3
|
"description": "Metascraper rules tailored for TikTok pages — richer metadata than generic HTML parsers.",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-tiktok",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.58.3",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"author": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
47
47
|
},
|
|
48
48
|
"license": "MIT",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "b3e17a907db0abbd141d6ee5a85f731ef429ecfc"
|
|
50
50
|
}
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,8 @@ const {
|
|
|
4
4
|
$meta,
|
|
5
5
|
author,
|
|
6
6
|
date,
|
|
7
|
+
description,
|
|
8
|
+
image,
|
|
7
9
|
memoizeOne,
|
|
8
10
|
parseUrl,
|
|
9
11
|
title,
|
|
@@ -12,6 +14,8 @@ const {
|
|
|
12
14
|
|
|
13
15
|
const toAuthor = toRule(author)
|
|
14
16
|
const toDate = toRule(date)
|
|
17
|
+
const toDescription = toRule(description)
|
|
18
|
+
const toImage = toRule(image)
|
|
15
19
|
const toTitle = toRule(title)
|
|
16
20
|
|
|
17
21
|
const test = memoizeOne(url => parseUrl(url).domain === 'tiktok.com')
|
|
@@ -22,7 +26,24 @@ const getTimestampFromId = id => {
|
|
|
22
26
|
return new Date(timestamp * 1000).toISOString()
|
|
23
27
|
}
|
|
24
28
|
|
|
29
|
+
const getScope = memoizeOne($ => {
|
|
30
|
+
const content = $('script[id="__UNIVERSAL_DATA_FOR_REHYDRATION__"]').text()
|
|
31
|
+
if (!content) return
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(content).__DEFAULT_SCOPE__
|
|
34
|
+
} catch {}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const getVideo = $ => getScope($)?.['webapp.video-detail']?.itemInfo?.itemStruct
|
|
38
|
+
|
|
39
|
+
const getUser = $ => getScope($)?.['webapp.user-detail']?.userInfo?.user
|
|
40
|
+
|
|
25
41
|
const getAuthorAndUsername = memoizeOne((url, $) => {
|
|
42
|
+
const video = getVideo($)
|
|
43
|
+
const user = video?.author || getUser($)
|
|
44
|
+
if (user?.nickname) {
|
|
45
|
+
return { authorName: user.nickname, username: user.uniqueId }
|
|
46
|
+
}
|
|
26
47
|
const ogTitle = $meta('og:title')($)
|
|
27
48
|
const authorName = ogTitle
|
|
28
49
|
?.split(' on TikTok')[0]
|
|
@@ -49,6 +70,13 @@ module.exports = () => {
|
|
|
49
70
|
: authorName
|
|
50
71
|
})
|
|
51
72
|
],
|
|
73
|
+
description: [toDescription($ => getVideo($)?.desc)],
|
|
74
|
+
image: [
|
|
75
|
+
toImage($ => getVideo($)?.video?.originCover),
|
|
76
|
+
toImage($ => getVideo($)?.video?.cover),
|
|
77
|
+
toImage($ => getUser($)?.avatarLarger)
|
|
78
|
+
],
|
|
79
|
+
publisher: () => 'TikTok',
|
|
52
80
|
date: [
|
|
53
81
|
toDate((_, url) => {
|
|
54
82
|
const id = url.split('/video/')[1]?.split('?')[0]
|
|
@@ -56,19 +84,10 @@ module.exports = () => {
|
|
|
56
84
|
return getTimestampFromId(id)
|
|
57
85
|
}),
|
|
58
86
|
toDate($ => {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
const json = JSON.parse(content)
|
|
65
|
-
const createTime =
|
|
66
|
-
json.__DEFAULT_SCOPE__?.['webapp.user-detail']?.userInfo?.user
|
|
67
|
-
?.createTime
|
|
68
|
-
return createTime
|
|
69
|
-
? new Date(createTime * 1000).toISOString()
|
|
70
|
-
: undefined
|
|
71
|
-
} catch (_) {}
|
|
87
|
+
const createTime = getVideo($)?.createTime ?? getUser($)?.createTime
|
|
88
|
+
return createTime
|
|
89
|
+
? new Date(createTime * 1000).toISOString()
|
|
90
|
+
: undefined
|
|
72
91
|
})
|
|
73
92
|
]
|
|
74
93
|
}
|