@nxgiang/tiktok-api 1.3.7
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/CHANGELOG.md +492 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +95 -0
- package/LICENSE +201 -0
- package/README.md +1663 -0
- package/bun.lock +367 -0
- package/helper/signature.js +390 -0
- package/helper/webmssdk.js +4586 -0
- package/helper/xbogus.js +563 -0
- package/install.sh +51 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +809 -0
- package/lib/constants/api.d.ts +22 -0
- package/lib/constants/api.js +39 -0
- package/lib/constants/headers.d.ts +2 -0
- package/lib/constants/headers.js +5 -0
- package/lib/constants/index.d.ts +23 -0
- package/lib/constants/index.js +26 -0
- package/lib/constants/params.d.ts +19 -0
- package/lib/constants/params.js +531 -0
- package/lib/index.d.ts +93 -0
- package/lib/index.js +137 -0
- package/lib/lib/logger.d.ts +8 -0
- package/lib/lib/logger.js +25 -0
- package/lib/services/cookieManager.d.ts +10 -0
- package/lib/services/cookieManager.js +51 -0
- package/lib/services/downloadManager.d.ts +5 -0
- package/lib/services/downloadManager.js +188 -0
- package/lib/services/tiktokService.d.ts +14 -0
- package/lib/services/tiktokService.js +78 -0
- package/lib/types/common.d.ts +65 -0
- package/lib/types/common.js +2 -0
- package/lib/types/cookieManager.d.ts +13 -0
- package/lib/types/cookieManager.js +2 -0
- package/lib/types/downloader/musicaldownDownloader.d.ts +27 -0
- package/lib/types/downloader/musicaldownDownloader.js +2 -0
- package/lib/types/downloader/ssstikDownloader.d.ts +30 -0
- package/lib/types/downloader/ssstikDownloader.js +2 -0
- package/lib/types/downloader/tiktokApiDownloader.d.ts +38 -0
- package/lib/types/downloader/tiktokApiDownloader.js +2 -0
- package/lib/types/get/getCollection.d.ts +53 -0
- package/lib/types/get/getCollection.js +2 -0
- package/lib/types/get/getComments.d.ts +26 -0
- package/lib/types/get/getComments.js +2 -0
- package/lib/types/get/getMusicDetail.d.ts +49 -0
- package/lib/types/get/getMusicDetail.js +2 -0
- package/lib/types/get/getMusicVideos.d.ts +93 -0
- package/lib/types/get/getMusicVideos.js +2 -0
- package/lib/types/get/getPlaylist.d.ts +65 -0
- package/lib/types/get/getPlaylist.js +2 -0
- package/lib/types/get/getProfile.d.ts +71 -0
- package/lib/types/get/getProfile.js +2 -0
- package/lib/types/get/getTrendings.d.ts +61 -0
- package/lib/types/get/getTrendings.js +2 -0
- package/lib/types/get/getUserLiked.d.ts +90 -0
- package/lib/types/get/getUserLiked.js +2 -0
- package/lib/types/get/getUserPosts.d.ts +68 -0
- package/lib/types/get/getUserPosts.js +2 -0
- package/lib/types/get/getUserReposts.d.ts +104 -0
- package/lib/types/get/getUserReposts.js +2 -0
- package/lib/types/search/index.d.ts +15 -0
- package/lib/types/search/index.js +2 -0
- package/lib/types/search/liveSearch.d.ts +48 -0
- package/lib/types/search/liveSearch.js +2 -0
- package/lib/types/search/userSearch.d.ts +32 -0
- package/lib/types/search/userSearch.js +2 -0
- package/lib/types/search/videoSearch.d.ts +62 -0
- package/lib/types/search/videoSearch.js +2 -0
- package/lib/utils/downloader/musicaldownDownloader.d.ts +2 -0
- package/lib/utils/downloader/musicaldownDownloader.js +193 -0
- package/lib/utils/downloader/ssstikDownloader.d.ts +2 -0
- package/lib/utils/downloader/ssstikDownloader.js +177 -0
- package/lib/utils/downloader/tiktokAPIDownloader.d.ts +3 -0
- package/lib/utils/downloader/tiktokAPIDownloader.js +221 -0
- package/lib/utils/get/getCollection.d.ts +7 -0
- package/lib/utils/get/getCollection.js +113 -0
- package/lib/utils/get/getComments.d.ts +2 -0
- package/lib/utils/get/getComments.js +139 -0
- package/lib/utils/get/getMusicDetail.d.ts +2 -0
- package/lib/utils/get/getMusicDetail.js +68 -0
- package/lib/utils/get/getMusicVideos.d.ts +2 -0
- package/lib/utils/get/getMusicVideos.js +249 -0
- package/lib/utils/get/getPlaylist.d.ts +7 -0
- package/lib/utils/get/getPlaylist.js +115 -0
- package/lib/utils/get/getProfile.d.ts +2 -0
- package/lib/utils/get/getProfile.js +92 -0
- package/lib/utils/get/getTrendings.d.ts +7 -0
- package/lib/utils/get/getTrendings.js +120 -0
- package/lib/utils/get/getUserLiked.d.ts +2 -0
- package/lib/utils/get/getUserLiked.js +204 -0
- package/lib/utils/get/getUserPosts.d.ts +2 -0
- package/lib/utils/get/getUserPosts.js +199 -0
- package/lib/utils/get/getUserRepost.d.ts +2 -0
- package/lib/utils/get/getUserRepost.js +239 -0
- package/lib/utils/search/liveSearch.d.ts +2 -0
- package/lib/utils/search/liveSearch.js +99 -0
- package/lib/utils/search/userSearch.d.ts +2 -0
- package/lib/utils/search/userSearch.js +76 -0
- package/lib/utils/search/videoSearch.d.ts +2 -0
- package/lib/utils/search/videoSearch.js +140 -0
- package/lib/utils/urlExtractors.d.ts +3 -0
- package/lib/utils/urlExtractors.js +37 -0
- package/lib/utils/validator.d.ts +1 -0
- package/lib/utils/validator.js +13 -0
- package/package.json +60 -0
- package/test/collection-test.ts +73 -0
- package/test/comments-test.ts +54 -0
- package/test/downloader-v1-test.ts +49 -0
- package/test/downloader-v2-test.ts +47 -0
- package/test/downloader-v3-test.ts +35 -0
- package/test/music-detail-test.ts +97 -0
- package/test/music-videos-test.ts +86 -0
- package/test/playlist-test.ts +48 -0
- package/test/profile-test.ts +49 -0
- package/test/search-live-test.ts +42 -0
- package/test/search-user-test.ts +46 -0
- package/test/search-video-test.ts +53 -0
- package/test/trending-test.ts +128 -0
- package/test/userliked-test.ts +65 -0
- package/test/userposts-test.ts +56 -0
- package/test/userreposts-test.ts +57 -0
- package/tobyg74-tiktok-api-1.3.7.tgz +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getUserLiked = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const api_1 = require("../../constants/api");
|
|
9
|
+
const getProfile_1 = require("./getProfile");
|
|
10
|
+
const params_1 = require("../../constants/params");
|
|
11
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
12
|
+
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
13
|
+
const tiktokService_1 = require("../../services/tiktokService");
|
|
14
|
+
const async_retry_1 = __importDefault(require("async-retry"));
|
|
15
|
+
const getUserLiked = (username, cookie, proxy, postLimit) => new Promise((resolve) => {
|
|
16
|
+
if (!cookie) {
|
|
17
|
+
return {
|
|
18
|
+
status: "error",
|
|
19
|
+
message: "Cookie is required!"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
(0, getProfile_1.StalkUser)(username).then(async (res) => {
|
|
23
|
+
if (res.status === "error") {
|
|
24
|
+
return resolve({
|
|
25
|
+
status: "error",
|
|
26
|
+
message: res.message
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const id = res.result.user.uid;
|
|
30
|
+
const secUid = res.result.user.secUid;
|
|
31
|
+
const data = await parseUserLiked(id, secUid, cookie, postLimit, proxy);
|
|
32
|
+
if (!data.length)
|
|
33
|
+
return resolve({
|
|
34
|
+
status: "error",
|
|
35
|
+
message: "User not found!"
|
|
36
|
+
});
|
|
37
|
+
resolve({
|
|
38
|
+
status: "success",
|
|
39
|
+
result: data,
|
|
40
|
+
totalPosts: data.length
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
exports.getUserLiked = getUserLiked;
|
|
45
|
+
const parseUserLiked = async (id, secUid, cookie, postLimit, proxy) => {
|
|
46
|
+
let hasMore = true;
|
|
47
|
+
const favorites = [];
|
|
48
|
+
let counter = 0;
|
|
49
|
+
while (hasMore) {
|
|
50
|
+
let result = null;
|
|
51
|
+
result = await requestUserLiked(id, secUid, cookie, postLimit, proxy);
|
|
52
|
+
result?.itemList?.forEach((v) => {
|
|
53
|
+
const statsAuthor = {
|
|
54
|
+
likeCount: v.authorStats.diggCount,
|
|
55
|
+
followerCount: v.authorStats.followerCount,
|
|
56
|
+
followingCount: v.authorStats.followingCount,
|
|
57
|
+
friendCount: v.authorStats.friendCount,
|
|
58
|
+
heartCount: v.authorStats.heartCount,
|
|
59
|
+
postsCount: v.authorStats.videoCount
|
|
60
|
+
};
|
|
61
|
+
const author = {
|
|
62
|
+
id: v.author.id,
|
|
63
|
+
username: v.author.uniqueId,
|
|
64
|
+
nickname: v.author.nickname,
|
|
65
|
+
avatarLarger: v.author.avatarLarger,
|
|
66
|
+
avatarThumb: v.author.avatarThumb,
|
|
67
|
+
avatarMedium: v.author.avatarMedium,
|
|
68
|
+
signature: v.author.signature,
|
|
69
|
+
verified: v.author.verified,
|
|
70
|
+
openFavorite: v.author.openFavorite,
|
|
71
|
+
privateAccount: v.author.privateAccount,
|
|
72
|
+
isADVirtual: v.author.isADVirtual,
|
|
73
|
+
isEmbedBanned: v.author.isEmbedBanned,
|
|
74
|
+
stats: statsAuthor
|
|
75
|
+
};
|
|
76
|
+
const stats = {
|
|
77
|
+
collectCount: v.statsV2.collectCount,
|
|
78
|
+
commentCount: v.statsV2.commentCount,
|
|
79
|
+
diggCount: v.statsV2.diggCount,
|
|
80
|
+
playCount: v.statsV2.playCount,
|
|
81
|
+
repostCount: v.statsV2.repostCount,
|
|
82
|
+
shareCount: v.statsV2.shareCount
|
|
83
|
+
};
|
|
84
|
+
const music = {
|
|
85
|
+
id: v.music.id,
|
|
86
|
+
title: v.music.title,
|
|
87
|
+
playUrl: v.music.playUrl,
|
|
88
|
+
coverThumb: v.music.coverThumb,
|
|
89
|
+
coverMedium: v.music.coverMedium,
|
|
90
|
+
coverLarge: v.music.coverLarge,
|
|
91
|
+
authorName: v.music.authorName,
|
|
92
|
+
original: v.music.original,
|
|
93
|
+
album: v.music.album,
|
|
94
|
+
duration: v.music.duration,
|
|
95
|
+
isCopyrighted: v.music.isCopyrighted,
|
|
96
|
+
private: v.music.private
|
|
97
|
+
};
|
|
98
|
+
const response = {
|
|
99
|
+
id: v.id,
|
|
100
|
+
desc: v.desc,
|
|
101
|
+
createTime: v.createTime,
|
|
102
|
+
duetEnabled: v.duetEnabled || false,
|
|
103
|
+
digged: v.digged || false,
|
|
104
|
+
forFriend: v.forFriend || false,
|
|
105
|
+
isAd: v.isAd || false,
|
|
106
|
+
originalItem: v.originalItem || false,
|
|
107
|
+
privateItem: v.privateItem || false,
|
|
108
|
+
officialItem: v.officialItem || false,
|
|
109
|
+
secret: v.secret || false,
|
|
110
|
+
shareEnabled: v.shareEnabled || false,
|
|
111
|
+
stitchEanbled: v.stitchEanbled || false,
|
|
112
|
+
textTranslatable: v.textTranslatable || false
|
|
113
|
+
};
|
|
114
|
+
if (v.imagePost) {
|
|
115
|
+
const imagePost = [];
|
|
116
|
+
v.imagePost.images.forEach((image) => {
|
|
117
|
+
imagePost.push({
|
|
118
|
+
title: image.title,
|
|
119
|
+
images: image.imageURL.urlList[0]
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
favorites.push({
|
|
123
|
+
...response,
|
|
124
|
+
author,
|
|
125
|
+
stats,
|
|
126
|
+
imagePost,
|
|
127
|
+
music
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const video = {
|
|
132
|
+
id: v.video.id,
|
|
133
|
+
videoID: v.video.id,
|
|
134
|
+
duration: v.video.duration,
|
|
135
|
+
ratio: v.video.ratio,
|
|
136
|
+
cover: v.video.cover,
|
|
137
|
+
originCover: v.video.originCover,
|
|
138
|
+
dynamicCover: v.video.dynamicCover,
|
|
139
|
+
playAddr: v.video.playAddr,
|
|
140
|
+
downloadAddr: v.video.downloadAddr,
|
|
141
|
+
format: v.video.format,
|
|
142
|
+
bitrate: v.video.bitrate,
|
|
143
|
+
bitrateInfo: v.video.bitrateInfo
|
|
144
|
+
};
|
|
145
|
+
favorites.push({
|
|
146
|
+
...response,
|
|
147
|
+
author,
|
|
148
|
+
stats,
|
|
149
|
+
video,
|
|
150
|
+
music
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
hasMore = result.hasMore;
|
|
155
|
+
counter++;
|
|
156
|
+
if (postLimit && favorites.length >= postLimit) {
|
|
157
|
+
hasMore = false;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return postLimit ? favorites.slice(0, postLimit) : favorites;
|
|
162
|
+
};
|
|
163
|
+
const requestUserLiked = async (id, secUid, cookie, postLimit, proxy) => {
|
|
164
|
+
const Tiktok = new tiktokService_1.TiktokService();
|
|
165
|
+
const url = new URL((0, api_1._tiktokGetUserLiked)((0, params_1._getUserLikedParams)(id, secUid, postLimit)));
|
|
166
|
+
const signature = Tiktok.generateSignature(url);
|
|
167
|
+
url.searchParams.append("_signature", signature);
|
|
168
|
+
const xbogus = Tiktok.generateXBogus(url, signature);
|
|
169
|
+
url.searchParams.append("X-Bogus", xbogus);
|
|
170
|
+
const xttparams = Tiktok.generateXTTParams(url.searchParams.toString());
|
|
171
|
+
return await (0, async_retry_1.default)(async (bail, attempt) => {
|
|
172
|
+
try {
|
|
173
|
+
const { data } = await axios_1.default.get(url.toString(), {
|
|
174
|
+
headers: {
|
|
175
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35",
|
|
176
|
+
cookie: Array.isArray(cookie) ? cookie.join("; ") : cookie,
|
|
177
|
+
"x-tt-params": xttparams
|
|
178
|
+
},
|
|
179
|
+
httpsAgent: (proxy &&
|
|
180
|
+
(proxy.startsWith("http") || proxy.startsWith("https")
|
|
181
|
+
? new https_proxy_agent_1.HttpsProxyAgent(proxy)
|
|
182
|
+
: proxy.startsWith("socks")
|
|
183
|
+
? new socks_proxy_agent_1.SocksProxyAgent(proxy)
|
|
184
|
+
: undefined)) ||
|
|
185
|
+
undefined
|
|
186
|
+
});
|
|
187
|
+
if (data === "") {
|
|
188
|
+
throw new Error("Empty response");
|
|
189
|
+
}
|
|
190
|
+
return data;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (attempt === 3) {
|
|
194
|
+
bail(error);
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}, {
|
|
199
|
+
retries: 10,
|
|
200
|
+
minTimeout: 1000,
|
|
201
|
+
maxTimeout: 5000,
|
|
202
|
+
factor: 2
|
|
203
|
+
});
|
|
204
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getUserPosts = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const api_1 = require("../../constants/api");
|
|
9
|
+
const params_1 = require("../../constants/params");
|
|
10
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
11
|
+
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
12
|
+
const tiktokService_1 = require("../../services/tiktokService");
|
|
13
|
+
const getProfile_1 = require("../get/getProfile");
|
|
14
|
+
const async_retry_1 = __importDefault(require("async-retry"));
|
|
15
|
+
const getUserPosts = (username, proxy, postLimit) => new Promise((resolve) => {
|
|
16
|
+
try {
|
|
17
|
+
(0, getProfile_1.StalkUser)(username).then(async (res) => {
|
|
18
|
+
if (res.status === "error") {
|
|
19
|
+
return resolve({
|
|
20
|
+
status: "error",
|
|
21
|
+
message: res.message
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const secUid = res.result.user.secUid;
|
|
25
|
+
const data = await parseUserPosts(secUid, postLimit, proxy);
|
|
26
|
+
if (!data.length)
|
|
27
|
+
return resolve({
|
|
28
|
+
status: "error",
|
|
29
|
+
message: "User not found!"
|
|
30
|
+
});
|
|
31
|
+
resolve({
|
|
32
|
+
status: "success",
|
|
33
|
+
result: data,
|
|
34
|
+
totalPosts: data.length
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (err.status == 400 ||
|
|
40
|
+
(err.response.data && err.response.data.statusCode == 10201)) {
|
|
41
|
+
return resolve({
|
|
42
|
+
status: "error",
|
|
43
|
+
message: "Video not found!"
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
exports.getUserPosts = getUserPosts;
|
|
49
|
+
const parseUserPosts = async (secUid, postLimit, proxy) => {
|
|
50
|
+
let page = 1;
|
|
51
|
+
let hasMore = true;
|
|
52
|
+
let responseCursor = 0;
|
|
53
|
+
const posts = [];
|
|
54
|
+
let counter = 0;
|
|
55
|
+
const Tiktok = new tiktokService_1.TiktokService();
|
|
56
|
+
while (hasMore) {
|
|
57
|
+
let result = null;
|
|
58
|
+
let xttparams = "";
|
|
59
|
+
let urlCursor = 0;
|
|
60
|
+
let urlCount = 0;
|
|
61
|
+
if (page === 1) {
|
|
62
|
+
urlCount = 0;
|
|
63
|
+
urlCursor = 0;
|
|
64
|
+
xttparams = Tiktok.generateXTTParams((0, params_1._xttParams)(secUid, 0, 35));
|
|
65
|
+
}
|
|
66
|
+
else if (page === 2) {
|
|
67
|
+
urlCount = 35;
|
|
68
|
+
urlCursor = 0;
|
|
69
|
+
xttparams = Tiktok.generateXTTParams((0, params_1._xttParams)(secUid, 0, 30));
|
|
70
|
+
}
|
|
71
|
+
else if (page === 3) {
|
|
72
|
+
urlCount = 30;
|
|
73
|
+
urlCursor = 0;
|
|
74
|
+
xttparams = Tiktok.generateXTTParams((0, params_1._xttParams)(secUid, responseCursor, 16));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
urlCount = 16;
|
|
78
|
+
urlCursor = responseCursor;
|
|
79
|
+
xttparams = Tiktok.generateXTTParams((0, params_1._xttParams)(secUid, responseCursor, 16));
|
|
80
|
+
}
|
|
81
|
+
result = await requestUserPosts(proxy, xttparams);
|
|
82
|
+
result?.itemList?.forEach((v) => {
|
|
83
|
+
const author = {
|
|
84
|
+
id: v.author.id,
|
|
85
|
+
username: v.author.uniqueId,
|
|
86
|
+
nickname: v.author.nickname,
|
|
87
|
+
avatarLarger: v.author.avatarLarger,
|
|
88
|
+
avatarThumb: v.author.avatarThumb,
|
|
89
|
+
avatarMedium: v.author.avatarMedium,
|
|
90
|
+
signature: v.author.signature,
|
|
91
|
+
verified: v.author.verified,
|
|
92
|
+
openFavorite: v.author.openFavorite,
|
|
93
|
+
privateAccount: v.author.privateAccount,
|
|
94
|
+
isADVirtual: v.author.isADVirtual,
|
|
95
|
+
isEmbedBanned: v.author.isEmbedBanned
|
|
96
|
+
};
|
|
97
|
+
if (v.imagePost) {
|
|
98
|
+
const imagePost = v.imagePost.images.map((img) => img.imageURL.urlList[0]);
|
|
99
|
+
posts.push({
|
|
100
|
+
id: v.id,
|
|
101
|
+
desc: v.desc,
|
|
102
|
+
createTime: v.createTime,
|
|
103
|
+
digged: v.digged,
|
|
104
|
+
duetEnabled: v.duetEnabled,
|
|
105
|
+
forFriend: v.forFriend,
|
|
106
|
+
officalItem: v.officalItem,
|
|
107
|
+
originalItem: v.originalItem,
|
|
108
|
+
privateItem: v.privateItem,
|
|
109
|
+
shareEnabled: v.shareEnabled,
|
|
110
|
+
stitchEnabled: v.stitchEnabled,
|
|
111
|
+
stats: v.stats,
|
|
112
|
+
music: v.music,
|
|
113
|
+
author,
|
|
114
|
+
imagePost
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const video = {
|
|
119
|
+
id: v.video.id,
|
|
120
|
+
duration: v.video.duration,
|
|
121
|
+
format: v.video.format,
|
|
122
|
+
bitrate: v.video.bitrate,
|
|
123
|
+
ratio: v.video.ratio,
|
|
124
|
+
playAddr: v.video.playAddr,
|
|
125
|
+
cover: v.video.cover,
|
|
126
|
+
originCover: v.video.originCover,
|
|
127
|
+
dynamicCover: v.video.dynamicCover,
|
|
128
|
+
downloadAddr: v.video.downloadAddr
|
|
129
|
+
};
|
|
130
|
+
posts.push({
|
|
131
|
+
id: v.id,
|
|
132
|
+
desc: v.desc,
|
|
133
|
+
createTime: v.createTime,
|
|
134
|
+
digged: v.digged,
|
|
135
|
+
duetEnabled: v.duetEnabled,
|
|
136
|
+
forFriend: v.forFriend,
|
|
137
|
+
officalItem: v.officalItem,
|
|
138
|
+
originalItem: v.originalItem,
|
|
139
|
+
privateItem: v.privateItem,
|
|
140
|
+
shareEnabled: v.shareEnabled,
|
|
141
|
+
stitchEnabled: v.stitchEnabled,
|
|
142
|
+
stats: v.stats,
|
|
143
|
+
music: v.music,
|
|
144
|
+
author,
|
|
145
|
+
video
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
hasMore = result.hasMore;
|
|
150
|
+
responseCursor = hasMore ? result.cursor : 0;
|
|
151
|
+
page++;
|
|
152
|
+
counter++;
|
|
153
|
+
if (postLimit && posts.length >= postLimit) {
|
|
154
|
+
hasMore = false;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return postLimit ? posts.slice(0, postLimit) : posts;
|
|
159
|
+
};
|
|
160
|
+
const requestUserPosts = async (proxy, xttparams = "") => {
|
|
161
|
+
return (0, async_retry_1.default)(async (bail, attempt) => {
|
|
162
|
+
try {
|
|
163
|
+
let urlParams = (0, params_1._getUserPostsParams)();
|
|
164
|
+
const { data } = await axios_1.default.get(`${(0, api_1._tiktokGetPosts)(urlParams)}`, {
|
|
165
|
+
headers: {
|
|
166
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35",
|
|
167
|
+
"x-tt-params": xttparams
|
|
168
|
+
},
|
|
169
|
+
httpsAgent: (proxy &&
|
|
170
|
+
(proxy.startsWith("http") || proxy.startsWith("https")
|
|
171
|
+
? new https_proxy_agent_1.HttpsProxyAgent(proxy)
|
|
172
|
+
: proxy.startsWith("socks")
|
|
173
|
+
? new socks_proxy_agent_1.SocksProxyAgent(proxy)
|
|
174
|
+
: undefined)) ||
|
|
175
|
+
undefined
|
|
176
|
+
});
|
|
177
|
+
if (data === "") {
|
|
178
|
+
throw new Error("Empty response");
|
|
179
|
+
}
|
|
180
|
+
return data;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (error.response?.status === 400 ||
|
|
184
|
+
error.response?.data?.statusCode === 10201) {
|
|
185
|
+
bail(new Error("Video not found!"));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}, {
|
|
191
|
+
retries: 10,
|
|
192
|
+
minTimeout: 1000,
|
|
193
|
+
maxTimeout: 5000,
|
|
194
|
+
factor: 2,
|
|
195
|
+
onRetry: (error, attempt) => {
|
|
196
|
+
console.log(`Retry attempt ${attempt} due to: ${error}`);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getUserReposts = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const api_1 = require("../../constants/api");
|
|
9
|
+
const params_1 = require("../../constants/params");
|
|
10
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
11
|
+
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
12
|
+
const getProfile_1 = require("../get/getProfile");
|
|
13
|
+
const async_retry_1 = __importDefault(require("async-retry"));
|
|
14
|
+
const getUserReposts = (username, proxy, postLimit, filterDeletedPost = true) => new Promise((resolve) => {
|
|
15
|
+
try {
|
|
16
|
+
(0, getProfile_1.StalkUser)(username).then(async (res) => {
|
|
17
|
+
if (res.status === "error") {
|
|
18
|
+
return resolve({
|
|
19
|
+
status: "error",
|
|
20
|
+
message: res.message
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const secUid = res.result.user.secUid;
|
|
24
|
+
const data = await parseUserReposts(secUid, postLimit, proxy, filterDeletedPost);
|
|
25
|
+
if (!data.length)
|
|
26
|
+
return resolve({
|
|
27
|
+
status: "error",
|
|
28
|
+
message: "User not found!"
|
|
29
|
+
});
|
|
30
|
+
resolve({
|
|
31
|
+
status: "success",
|
|
32
|
+
result: data,
|
|
33
|
+
totalReposts: data.length
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (err.status == 400 ||
|
|
39
|
+
(err.response.data && err.response.data.statusCode == 10201)) {
|
|
40
|
+
return resolve({
|
|
41
|
+
status: "error",
|
|
42
|
+
message: "Video not found!"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
exports.getUserReposts = getUserReposts;
|
|
48
|
+
const parseUserReposts = async (secUid, postLimit, proxy, filterDeletedPost) => {
|
|
49
|
+
let page = 1;
|
|
50
|
+
let hasMore = true;
|
|
51
|
+
let responseCursor = 0;
|
|
52
|
+
const posts = [];
|
|
53
|
+
let counter = 0;
|
|
54
|
+
while (hasMore) {
|
|
55
|
+
let result = null;
|
|
56
|
+
let urlCursor = 0;
|
|
57
|
+
let urlCount = 0;
|
|
58
|
+
if (page === 1) {
|
|
59
|
+
urlCount = 16;
|
|
60
|
+
urlCursor = 0;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
urlCount = 16;
|
|
64
|
+
urlCursor = responseCursor;
|
|
65
|
+
}
|
|
66
|
+
result = await requestUserReposts(proxy, secUid, urlCursor, urlCount);
|
|
67
|
+
if (!result || !result.itemList || result.itemList.length === 0) {
|
|
68
|
+
hasMore = false;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
if (filterDeletedPost) {
|
|
72
|
+
result.itemList = result.itemList.filter((item) => item.createTime !== 0);
|
|
73
|
+
}
|
|
74
|
+
result?.itemList?.forEach((v) => {
|
|
75
|
+
const author = {
|
|
76
|
+
id: v.author?.id,
|
|
77
|
+
username: v.author?.uniqueId,
|
|
78
|
+
nickname: v.author?.nickname,
|
|
79
|
+
avatarLarger: v.author?.avatarLarger,
|
|
80
|
+
avatarThumb: v.author?.avatarThumb,
|
|
81
|
+
avatarMedium: v.author?.avatarMedium,
|
|
82
|
+
signature: v.author?.signature,
|
|
83
|
+
verified: v.author?.verified,
|
|
84
|
+
openFavorite: v.author?.openFavorite,
|
|
85
|
+
privateAccount: v.author?.privateAccount,
|
|
86
|
+
isADVirtual: v.author?.isADVirtual,
|
|
87
|
+
isEmbedBanned: v.author?.isEmbedBanned
|
|
88
|
+
};
|
|
89
|
+
if (v.imagePost) {
|
|
90
|
+
const imagePost = {
|
|
91
|
+
title: v.imagePost.title || "",
|
|
92
|
+
images: v.imagePost.images?.map((img) => ({
|
|
93
|
+
imageURL: {
|
|
94
|
+
urlList: img.imageURL?.urlList || []
|
|
95
|
+
}
|
|
96
|
+
})) || []
|
|
97
|
+
};
|
|
98
|
+
posts.push({
|
|
99
|
+
id: v.id,
|
|
100
|
+
desc: v.desc,
|
|
101
|
+
createTime: v.createTime,
|
|
102
|
+
digged: v.digged || false,
|
|
103
|
+
duetEnabled: v.duetEnabled,
|
|
104
|
+
forFriend: v.forFriend || false,
|
|
105
|
+
officalItem: v.officalItem || false,
|
|
106
|
+
originalItem: v.originalItem || false,
|
|
107
|
+
privateItem: v.privateItem || false,
|
|
108
|
+
secret: v.secret || false,
|
|
109
|
+
shareEnabled: v.shareEnabled || false,
|
|
110
|
+
stitchEnabled: v.stitchEnabled,
|
|
111
|
+
stats: v.stats || { shareCount: 0 },
|
|
112
|
+
music: v.music || {},
|
|
113
|
+
author,
|
|
114
|
+
imagePost,
|
|
115
|
+
AIGCDescription: v.AIGCDescription,
|
|
116
|
+
CategoryType: v.CategoryType,
|
|
117
|
+
collected: v.collected,
|
|
118
|
+
contents: v.contents || [],
|
|
119
|
+
challenges: v.challenges || [],
|
|
120
|
+
textExtra: v.textExtra || [],
|
|
121
|
+
textLanguage: v.textLanguage,
|
|
122
|
+
textTranslatable: v.textTranslatable,
|
|
123
|
+
titleLanguage: v.titleLanguage,
|
|
124
|
+
titleTranslatable: v.titleTranslatable,
|
|
125
|
+
isAd: v.isAd,
|
|
126
|
+
isReviewing: v.isReviewing,
|
|
127
|
+
itemCommentStatus: v.itemCommentStatus,
|
|
128
|
+
item_control: v.item_control,
|
|
129
|
+
duetDisplay: v.duetDisplay,
|
|
130
|
+
stitchDisplay: v.stitchDisplay,
|
|
131
|
+
diversificationId: v.diversificationId,
|
|
132
|
+
backendSourceEventTracking: v.backendSourceEventTracking,
|
|
133
|
+
stickersOnItem: v.stickersOnItem || [],
|
|
134
|
+
videoSuggestWordsList: v.videoSuggestWordsList
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const video = {
|
|
139
|
+
id: v.video?.id,
|
|
140
|
+
duration: v.video?.duration,
|
|
141
|
+
format: v.video?.format,
|
|
142
|
+
bitrate: v.video?.bitrate,
|
|
143
|
+
ratio: v.video?.ratio,
|
|
144
|
+
playAddr: v.video?.playAddr,
|
|
145
|
+
cover: v.video?.cover,
|
|
146
|
+
originCover: v.video?.originCover,
|
|
147
|
+
dynamicCover: v.video?.dynamicCover,
|
|
148
|
+
downloadAddr: v.video?.downloadAddr
|
|
149
|
+
};
|
|
150
|
+
posts.push({
|
|
151
|
+
id: v.id,
|
|
152
|
+
desc: v.desc,
|
|
153
|
+
createTime: v.createTime,
|
|
154
|
+
digged: v.digged || false,
|
|
155
|
+
duetEnabled: v.duetEnabled,
|
|
156
|
+
forFriend: v.forFriend || false,
|
|
157
|
+
officalItem: v.officalItem || false,
|
|
158
|
+
originalItem: v.originalItem || false,
|
|
159
|
+
privateItem: v.privateItem || false,
|
|
160
|
+
secret: v.secret || false,
|
|
161
|
+
shareEnabled: v.shareEnabled || false,
|
|
162
|
+
stitchEnabled: v.stitchEnabled,
|
|
163
|
+
stats: v.stats || { shareCount: 0 },
|
|
164
|
+
music: v.music || {},
|
|
165
|
+
author,
|
|
166
|
+
video,
|
|
167
|
+
AIGCDescription: v.AIGCDescription,
|
|
168
|
+
CategoryType: v.CategoryType,
|
|
169
|
+
collected: v.collected,
|
|
170
|
+
contents: v.contents || [],
|
|
171
|
+
challenges: v.challenges || [],
|
|
172
|
+
textExtra: v.textExtra || [],
|
|
173
|
+
textLanguage: v.textLanguage,
|
|
174
|
+
textTranslatable: v.textTranslatable,
|
|
175
|
+
titleLanguage: v.titleLanguage,
|
|
176
|
+
titleTranslatable: v.titleTranslatable,
|
|
177
|
+
isAd: v.isAd,
|
|
178
|
+
isReviewing: v.isReviewing,
|
|
179
|
+
itemCommentStatus: v.itemCommentStatus,
|
|
180
|
+
item_control: v.item_control,
|
|
181
|
+
duetDisplay: v.duetDisplay,
|
|
182
|
+
stitchDisplay: v.stitchDisplay,
|
|
183
|
+
diversificationId: v.diversificationId,
|
|
184
|
+
backendSourceEventTracking: v.backendSourceEventTracking,
|
|
185
|
+
stickersOnItem: v.stickersOnItem || [],
|
|
186
|
+
videoSuggestWordsList: v.videoSuggestWordsList
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
hasMore = result.hasMore;
|
|
191
|
+
responseCursor = hasMore ? result.cursor : 0;
|
|
192
|
+
page++;
|
|
193
|
+
counter++;
|
|
194
|
+
if (postLimit && posts.length >= postLimit) {
|
|
195
|
+
hasMore = false;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return postLimit ? posts.slice(0, postLimit) : posts;
|
|
200
|
+
};
|
|
201
|
+
const requestUserReposts = async (proxy, secUid = "", cursor = 0, count = 0) => {
|
|
202
|
+
return (0, async_retry_1.default)(async (bail, attempt) => {
|
|
203
|
+
try {
|
|
204
|
+
let urlParams = (0, params_1._getUserRepostsParams)(secUid, cursor, count);
|
|
205
|
+
const { data } = await axios_1.default.get(`${(0, api_1._tiktokGetReposts)(urlParams)}`, {
|
|
206
|
+
headers: {
|
|
207
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0"
|
|
208
|
+
},
|
|
209
|
+
httpsAgent: (proxy &&
|
|
210
|
+
(proxy.startsWith("http") || proxy.startsWith("https")
|
|
211
|
+
? new https_proxy_agent_1.HttpsProxyAgent(proxy)
|
|
212
|
+
: proxy.startsWith("socks")
|
|
213
|
+
? new socks_proxy_agent_1.SocksProxyAgent(proxy)
|
|
214
|
+
: undefined)) ||
|
|
215
|
+
undefined
|
|
216
|
+
});
|
|
217
|
+
if (data === "") {
|
|
218
|
+
throw new Error("Empty response");
|
|
219
|
+
}
|
|
220
|
+
return data;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
if (error.response?.status === 400 ||
|
|
224
|
+
error.response?.data?.statusCode === 10201) {
|
|
225
|
+
bail(new Error("Video not found!"));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
retries: 10,
|
|
232
|
+
minTimeout: 1000,
|
|
233
|
+
maxTimeout: 5000,
|
|
234
|
+
factor: 2,
|
|
235
|
+
onRetry: (error, attempt) => {
|
|
236
|
+
console.log(`Retry attempt ${attempt} due to: ${error}`);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
};
|