@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,90 @@
|
|
|
1
|
+
export type TiktokUserFavoriteVideosResponse = {
|
|
2
|
+
status: "success" | "error";
|
|
3
|
+
message?: string;
|
|
4
|
+
result?: LikedResponse[];
|
|
5
|
+
totalPosts?: number;
|
|
6
|
+
};
|
|
7
|
+
export type LikedResponse = {
|
|
8
|
+
id: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
createTime: string;
|
|
11
|
+
duetEnabled: boolean;
|
|
12
|
+
digged: boolean;
|
|
13
|
+
forFriend: boolean;
|
|
14
|
+
isAd: boolean;
|
|
15
|
+
originalItem: boolean;
|
|
16
|
+
privateItem: boolean;
|
|
17
|
+
officialItem: boolean;
|
|
18
|
+
secret: boolean;
|
|
19
|
+
shareEnabled: boolean;
|
|
20
|
+
stitchEanbled: boolean;
|
|
21
|
+
textTranslatable: boolean;
|
|
22
|
+
author: AuthorLiked;
|
|
23
|
+
stats: StatisticsLiked;
|
|
24
|
+
video?: VideoLiked;
|
|
25
|
+
imagePost?: ImagesLiked[];
|
|
26
|
+
music: MusicLiked;
|
|
27
|
+
};
|
|
28
|
+
export type AuthorLiked = {
|
|
29
|
+
id: string;
|
|
30
|
+
username: string;
|
|
31
|
+
nickname: string;
|
|
32
|
+
avatarLarger: string;
|
|
33
|
+
avatarThumb: string;
|
|
34
|
+
avatarMedium: string;
|
|
35
|
+
signature: string;
|
|
36
|
+
verified: string;
|
|
37
|
+
openFavorite: string;
|
|
38
|
+
privateAccount: string;
|
|
39
|
+
isADVirtual: string;
|
|
40
|
+
isEmbedBanned: string;
|
|
41
|
+
stats: StatisticsAuthorLiked;
|
|
42
|
+
};
|
|
43
|
+
export type StatisticsAuthorLiked = {
|
|
44
|
+
likeCount: string;
|
|
45
|
+
followerCount: string;
|
|
46
|
+
followingCount: string;
|
|
47
|
+
friendCount: string;
|
|
48
|
+
heartCount: string;
|
|
49
|
+
postsCount: string;
|
|
50
|
+
};
|
|
51
|
+
export type StatisticsLiked = {
|
|
52
|
+
collectCount: string;
|
|
53
|
+
commentCount: string;
|
|
54
|
+
diggCount: string;
|
|
55
|
+
playCount: string;
|
|
56
|
+
repostCount: string;
|
|
57
|
+
shareCount: string;
|
|
58
|
+
};
|
|
59
|
+
export type ImagesLiked = {
|
|
60
|
+
title: string;
|
|
61
|
+
images: string[];
|
|
62
|
+
};
|
|
63
|
+
export type VideoLiked = {
|
|
64
|
+
id: string;
|
|
65
|
+
videoID: string;
|
|
66
|
+
duration: number;
|
|
67
|
+
ratio: string;
|
|
68
|
+
cover: string;
|
|
69
|
+
originCover: string;
|
|
70
|
+
dynamicCover: string;
|
|
71
|
+
playAddr: string;
|
|
72
|
+
downloadAddr: string;
|
|
73
|
+
format: string;
|
|
74
|
+
bitrate: number;
|
|
75
|
+
bitrateInfo: any[];
|
|
76
|
+
};
|
|
77
|
+
export type MusicLiked = {
|
|
78
|
+
id: string;
|
|
79
|
+
title: string;
|
|
80
|
+
playUrl: string;
|
|
81
|
+
coverThumb: string;
|
|
82
|
+
coverMedium: string;
|
|
83
|
+
coverLarge: string;
|
|
84
|
+
authorName: string;
|
|
85
|
+
original: boolean;
|
|
86
|
+
album: string;
|
|
87
|
+
duration: number;
|
|
88
|
+
isCopyrighted: boolean;
|
|
89
|
+
private: boolean;
|
|
90
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type TiktokUserPostsResponse = {
|
|
2
|
+
status: "success" | "error";
|
|
3
|
+
message?: string;
|
|
4
|
+
result?: Posts[];
|
|
5
|
+
totalPosts?: number;
|
|
6
|
+
};
|
|
7
|
+
export type Posts = {
|
|
8
|
+
id: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
createTime: number;
|
|
11
|
+
digged: number;
|
|
12
|
+
duetEnabled: number;
|
|
13
|
+
forFriend: number;
|
|
14
|
+
officalItem: number;
|
|
15
|
+
originalItem: number;
|
|
16
|
+
privateItem: number;
|
|
17
|
+
shareEnabled: number;
|
|
18
|
+
stitchEnabled: number;
|
|
19
|
+
stats: StatsPost;
|
|
20
|
+
author: AuthorPost;
|
|
21
|
+
video?: VideoPost;
|
|
22
|
+
music: MusicPost;
|
|
23
|
+
imagePost?: string[];
|
|
24
|
+
};
|
|
25
|
+
export type StatsPost = {
|
|
26
|
+
collectCount: number;
|
|
27
|
+
commentCount: number;
|
|
28
|
+
likeCount: number;
|
|
29
|
+
playCount: number;
|
|
30
|
+
shareCount: number;
|
|
31
|
+
};
|
|
32
|
+
export type AuthorPost = {
|
|
33
|
+
id: string;
|
|
34
|
+
username: string;
|
|
35
|
+
nickname: string;
|
|
36
|
+
avatarLarger: string;
|
|
37
|
+
avatarThumb: string;
|
|
38
|
+
avatarMedium: string;
|
|
39
|
+
signature: string;
|
|
40
|
+
verified: boolean;
|
|
41
|
+
openFavorite: boolean;
|
|
42
|
+
privateAccount: boolean;
|
|
43
|
+
isADVirtual: boolean;
|
|
44
|
+
isEmbedBanned: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type VideoPost = {
|
|
47
|
+
id: string;
|
|
48
|
+
duration: number;
|
|
49
|
+
ratio: string;
|
|
50
|
+
cover: string;
|
|
51
|
+
originCover: string;
|
|
52
|
+
dynamicCover: string;
|
|
53
|
+
playAddr: string;
|
|
54
|
+
downloadAddr: string;
|
|
55
|
+
format: string;
|
|
56
|
+
bitrate: number;
|
|
57
|
+
};
|
|
58
|
+
export type MusicPost = {
|
|
59
|
+
authorName: string;
|
|
60
|
+
coverLarge: string;
|
|
61
|
+
coverMedium: string;
|
|
62
|
+
coverThumb: string;
|
|
63
|
+
duration: number;
|
|
64
|
+
id: string;
|
|
65
|
+
title: string;
|
|
66
|
+
playUrl: string;
|
|
67
|
+
original: boolean;
|
|
68
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export type TiktokUserRepostsResponse = {
|
|
2
|
+
status: "success" | "error";
|
|
3
|
+
message?: string;
|
|
4
|
+
result?: Reposts[];
|
|
5
|
+
totalReposts?: number;
|
|
6
|
+
};
|
|
7
|
+
export type Reposts = {
|
|
8
|
+
id: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
createTime: number;
|
|
11
|
+
digged: boolean;
|
|
12
|
+
duetEnabled?: boolean;
|
|
13
|
+
forFriend: boolean;
|
|
14
|
+
officalItem: boolean;
|
|
15
|
+
originalItem: boolean;
|
|
16
|
+
privateItem: boolean;
|
|
17
|
+
secret: boolean;
|
|
18
|
+
shareEnabled: boolean;
|
|
19
|
+
stitchEnabled?: boolean;
|
|
20
|
+
stats: StatsRepost;
|
|
21
|
+
author: AuthorRepost;
|
|
22
|
+
video?: VideoRepost;
|
|
23
|
+
music: MusicRepost;
|
|
24
|
+
imagePost?: ImageRepost;
|
|
25
|
+
AIGCDescription?: string;
|
|
26
|
+
CategoryType?: number;
|
|
27
|
+
collected?: boolean;
|
|
28
|
+
contents?: any[];
|
|
29
|
+
challenges?: any[];
|
|
30
|
+
textExtra?: any[];
|
|
31
|
+
textLanguage?: string;
|
|
32
|
+
textTranslatable?: boolean;
|
|
33
|
+
titleLanguage?: string;
|
|
34
|
+
titleTranslatable?: boolean;
|
|
35
|
+
isAd?: boolean;
|
|
36
|
+
isReviewing?: boolean;
|
|
37
|
+
itemCommentStatus?: number;
|
|
38
|
+
item_control?: ItemControl;
|
|
39
|
+
duetDisplay?: number;
|
|
40
|
+
stitchDisplay?: number;
|
|
41
|
+
diversificationId?: number;
|
|
42
|
+
backendSourceEventTracking?: string;
|
|
43
|
+
stickersOnItem?: any[];
|
|
44
|
+
videoSuggestWordsList?: any;
|
|
45
|
+
};
|
|
46
|
+
export type StatsRepost = {
|
|
47
|
+
shareCount: number;
|
|
48
|
+
collectCount?: number;
|
|
49
|
+
commentCount?: number;
|
|
50
|
+
likeCount?: number;
|
|
51
|
+
playCount?: number;
|
|
52
|
+
repostCount?: number;
|
|
53
|
+
};
|
|
54
|
+
export type AuthorRepost = {
|
|
55
|
+
id: string;
|
|
56
|
+
username: string;
|
|
57
|
+
nickname: string;
|
|
58
|
+
avatarLarger: string;
|
|
59
|
+
avatarThumb: string;
|
|
60
|
+
avatarMedium: string;
|
|
61
|
+
signature: string;
|
|
62
|
+
verified: boolean;
|
|
63
|
+
openFavorite?: boolean;
|
|
64
|
+
privateAccount?: boolean;
|
|
65
|
+
isADVirtual?: boolean;
|
|
66
|
+
isEmbedBanned?: boolean;
|
|
67
|
+
};
|
|
68
|
+
export type VideoRepost = {
|
|
69
|
+
id: string;
|
|
70
|
+
duration: number;
|
|
71
|
+
ratio: string;
|
|
72
|
+
cover: string;
|
|
73
|
+
originCover: string;
|
|
74
|
+
dynamicCover: string;
|
|
75
|
+
playAddr: string;
|
|
76
|
+
downloadAddr: string;
|
|
77
|
+
format: string;
|
|
78
|
+
bitrate: number;
|
|
79
|
+
};
|
|
80
|
+
export type MusicRepost = {
|
|
81
|
+
authorName?: string;
|
|
82
|
+
coverLarge?: string;
|
|
83
|
+
coverMedium?: string;
|
|
84
|
+
coverThumb?: string;
|
|
85
|
+
duration?: number;
|
|
86
|
+
id?: string;
|
|
87
|
+
title?: string;
|
|
88
|
+
playUrl?: string;
|
|
89
|
+
original?: boolean;
|
|
90
|
+
tt2dsp?: any;
|
|
91
|
+
};
|
|
92
|
+
export type ImageRepost = {
|
|
93
|
+
title: string;
|
|
94
|
+
images?: ImageRepostItem[];
|
|
95
|
+
};
|
|
96
|
+
export type ImageRepostItem = {
|
|
97
|
+
imageURL: {
|
|
98
|
+
urlList: string[];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export type ItemControl = {
|
|
102
|
+
can_repost?: boolean;
|
|
103
|
+
can_share?: boolean;
|
|
104
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VideoSearchResult } from "./videoSearch";
|
|
2
|
+
import { LiveSearchResult } from "./liveSearch";
|
|
3
|
+
import { UserSearchResult } from "./userSearch";
|
|
4
|
+
export type SearchType = "video" | "live" | "user";
|
|
5
|
+
export type SearchResult = {
|
|
6
|
+
type: SearchType;
|
|
7
|
+
data: VideoSearchResult | LiveSearchResult | UserSearchResult;
|
|
8
|
+
};
|
|
9
|
+
export type TiktokSearchResponse = {
|
|
10
|
+
status: "success" | "error";
|
|
11
|
+
message?: string;
|
|
12
|
+
result?: SearchResult[];
|
|
13
|
+
page?: number;
|
|
14
|
+
totalResults?: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type TiktokLiveSearchResponse = {
|
|
2
|
+
status: "success" | "error";
|
|
3
|
+
message?: string;
|
|
4
|
+
result?: LiveSearchResult[];
|
|
5
|
+
page?: number;
|
|
6
|
+
totalResults?: number;
|
|
7
|
+
};
|
|
8
|
+
export type LiveSearchResult = {
|
|
9
|
+
roomInfo: RoomInfo;
|
|
10
|
+
liveInfo: LiveInfo;
|
|
11
|
+
};
|
|
12
|
+
export type RoomInfo = {
|
|
13
|
+
hasCommerceGoods: boolean;
|
|
14
|
+
isBattle: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type LiveInfo = {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
cover: string[];
|
|
20
|
+
squareCover: string[];
|
|
21
|
+
rectangleCover: string[];
|
|
22
|
+
liveTypeThirdParty: boolean;
|
|
23
|
+
hashtag: string;
|
|
24
|
+
startTime: number;
|
|
25
|
+
stats: Stats;
|
|
26
|
+
owner: Owner;
|
|
27
|
+
};
|
|
28
|
+
export type Stats = {
|
|
29
|
+
totalUser: number;
|
|
30
|
+
viewerCount: number;
|
|
31
|
+
likeCount: number;
|
|
32
|
+
};
|
|
33
|
+
export type Owner = {
|
|
34
|
+
uid: string;
|
|
35
|
+
nickname: string;
|
|
36
|
+
username: string;
|
|
37
|
+
signature: string;
|
|
38
|
+
avatarThumb: string[];
|
|
39
|
+
avatarMedium: string[];
|
|
40
|
+
avatarLarge: string[];
|
|
41
|
+
modifyTime: number;
|
|
42
|
+
stats: OwnerStats;
|
|
43
|
+
isVerified: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type OwnerStats = {
|
|
46
|
+
followingCount: number;
|
|
47
|
+
followerCount: number;
|
|
48
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type TiktokUserSearchResponse = {
|
|
2
|
+
status: "success" | "error";
|
|
3
|
+
message?: string;
|
|
4
|
+
result?: Array<{
|
|
5
|
+
uid: string;
|
|
6
|
+
username: string;
|
|
7
|
+
nickname: string;
|
|
8
|
+
signature: string;
|
|
9
|
+
followerCount: number;
|
|
10
|
+
avatarThumb: string;
|
|
11
|
+
isVerified: boolean;
|
|
12
|
+
secUid: string;
|
|
13
|
+
url: string;
|
|
14
|
+
}>;
|
|
15
|
+
page?: number;
|
|
16
|
+
totalResults?: number;
|
|
17
|
+
};
|
|
18
|
+
export type UserSearchResult = {
|
|
19
|
+
uid: string;
|
|
20
|
+
username: string;
|
|
21
|
+
nickname: string;
|
|
22
|
+
signature: string;
|
|
23
|
+
avatarThumb: string;
|
|
24
|
+
followerCount: number;
|
|
25
|
+
isVerified: boolean;
|
|
26
|
+
secUid: string;
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
29
|
+
export interface IUserSearch {
|
|
30
|
+
saveSearch(searchTerm: string): void;
|
|
31
|
+
getLastSearch(): string | null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type TiktokVideoSearchResponse = {
|
|
2
|
+
status: "success" | "error";
|
|
3
|
+
message?: string;
|
|
4
|
+
result?: VideoSearchResult[];
|
|
5
|
+
page?: number;
|
|
6
|
+
totalResults?: number;
|
|
7
|
+
};
|
|
8
|
+
export type VideoSearchResult = {
|
|
9
|
+
id: string;
|
|
10
|
+
desc: string;
|
|
11
|
+
createTime: number;
|
|
12
|
+
author: AuthorVideoSearch;
|
|
13
|
+
stats: StatisticsVideoSearch;
|
|
14
|
+
video: VideoSearch;
|
|
15
|
+
music: MusicVideoSearch;
|
|
16
|
+
};
|
|
17
|
+
export type VideoSearch = {
|
|
18
|
+
id: string;
|
|
19
|
+
ratio: string;
|
|
20
|
+
cover: string;
|
|
21
|
+
originCover: string;
|
|
22
|
+
dynamicCover: string;
|
|
23
|
+
playAddr: string;
|
|
24
|
+
downloadAddr: string;
|
|
25
|
+
format: string;
|
|
26
|
+
};
|
|
27
|
+
export type StatisticsVideoSearch = {
|
|
28
|
+
collectCount: number;
|
|
29
|
+
commentCount: number;
|
|
30
|
+
likeCount: number;
|
|
31
|
+
playCount: number;
|
|
32
|
+
shareCount: number;
|
|
33
|
+
};
|
|
34
|
+
export type AuthorVideoSearch = {
|
|
35
|
+
id: string;
|
|
36
|
+
uniqueId: string;
|
|
37
|
+
nickname: string;
|
|
38
|
+
avatarThumb: string;
|
|
39
|
+
avatarMedium: string;
|
|
40
|
+
avatarLarger: string;
|
|
41
|
+
signature: string;
|
|
42
|
+
verified: boolean;
|
|
43
|
+
secUid: string;
|
|
44
|
+
openFavorite: boolean;
|
|
45
|
+
privateAccount: boolean;
|
|
46
|
+
isADVirtual: boolean;
|
|
47
|
+
tiktokSeller: boolean;
|
|
48
|
+
isEmbedBanned: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type MusicVideoSearch = {
|
|
51
|
+
id: string;
|
|
52
|
+
title: string;
|
|
53
|
+
playUrl: string;
|
|
54
|
+
coverThumb: string;
|
|
55
|
+
coverMedium: string;
|
|
56
|
+
coverLarge: string;
|
|
57
|
+
authorName: string;
|
|
58
|
+
original: boolean;
|
|
59
|
+
album: string;
|
|
60
|
+
duration: number;
|
|
61
|
+
isCopyrighted: boolean;
|
|
62
|
+
};
|
|
@@ -0,0 +1,193 @@
|
|
|
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.MusicalDown = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const cheerio_1 = require("cheerio");
|
|
9
|
+
const api_1 = require("../../constants/api");
|
|
10
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
11
|
+
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
const TIKTOK_URL_REGEX = /https:\/\/(?:m|t|www|vm|vt|lite)?\.?tiktok\.com\/((?:.*\b(?:(?:usr|v|embed|user|video|photo)\/|\?shareId=|\&item_id=)(\d+))|\w+)/;
|
|
14
|
+
const USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0";
|
|
15
|
+
const createProxyAgent = (proxy) => {
|
|
16
|
+
if (!proxy)
|
|
17
|
+
return {};
|
|
18
|
+
const isHttpProxy = proxy.startsWith("http") || proxy.startsWith("https");
|
|
19
|
+
const isSocksProxy = proxy.startsWith("socks");
|
|
20
|
+
if (!isHttpProxy && !isSocksProxy)
|
|
21
|
+
return {};
|
|
22
|
+
return {
|
|
23
|
+
httpsAgent: isHttpProxy
|
|
24
|
+
? new https_proxy_agent_1.HttpsProxyAgent(proxy)
|
|
25
|
+
: new socks_proxy_agent_1.SocksProxyAgent(proxy)
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const validateTikTokUrl = (url) => {
|
|
29
|
+
return TIKTOK_URL_REGEX.test(url);
|
|
30
|
+
};
|
|
31
|
+
const isValidUrl = (url) => {
|
|
32
|
+
try {
|
|
33
|
+
new URL(url);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const extractRequestForm = ($, url) => {
|
|
41
|
+
const input = $("div > input").map((_, el) => $(el));
|
|
42
|
+
return {
|
|
43
|
+
[input.get(0).attr("name") || ""]: input.get(0).attr("value") || url,
|
|
44
|
+
[input.get(1).attr("name") || ""]: input.get(1).attr("value") || "",
|
|
45
|
+
[input.get(2).attr("name") || ""]: input.get(2).attr("value") || ""
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const parseImages = ($) => {
|
|
49
|
+
const images = [];
|
|
50
|
+
$("div.row > div[class='col s12 m3']").each((_, v) => {
|
|
51
|
+
const src = $(v).find("img").attr("src");
|
|
52
|
+
if (src)
|
|
53
|
+
images.push(src);
|
|
54
|
+
});
|
|
55
|
+
return images;
|
|
56
|
+
};
|
|
57
|
+
const parseVideos = ($) => {
|
|
58
|
+
const videos = {};
|
|
59
|
+
const videoContainer = $("div.row > div")
|
|
60
|
+
.map((_, el) => $(el))
|
|
61
|
+
.get(1);
|
|
62
|
+
if (!videoContainer)
|
|
63
|
+
return videos;
|
|
64
|
+
$(videoContainer)
|
|
65
|
+
.find("a")
|
|
66
|
+
.each((_, v) => {
|
|
67
|
+
const href = $(v).attr("href");
|
|
68
|
+
if (!href || href === "#modal2")
|
|
69
|
+
return;
|
|
70
|
+
if (!isValidUrl(href))
|
|
71
|
+
return;
|
|
72
|
+
const dataEvent = $(v).attr("data-event") || "";
|
|
73
|
+
const onclick = $(v).attr("onclick") || "";
|
|
74
|
+
const downloadUrl = href !== undefined ? href : /downloadX\('([^']+)'\)/.exec(onclick)?.[1];
|
|
75
|
+
if (!downloadUrl)
|
|
76
|
+
return;
|
|
77
|
+
if (dataEvent.includes("hd")) {
|
|
78
|
+
videos.videoHD = downloadUrl;
|
|
79
|
+
}
|
|
80
|
+
else if (dataEvent.includes("mp4")) {
|
|
81
|
+
videos.videoSD = downloadUrl;
|
|
82
|
+
}
|
|
83
|
+
else if (dataEvent.includes("watermark")) {
|
|
84
|
+
videos.videoWatermark = downloadUrl;
|
|
85
|
+
}
|
|
86
|
+
else if (href.includes("type=mp3")) {
|
|
87
|
+
videos.music = downloadUrl;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return videos;
|
|
91
|
+
};
|
|
92
|
+
const createImageResponse = (images) => ({
|
|
93
|
+
status: "success",
|
|
94
|
+
result: {
|
|
95
|
+
type: "image",
|
|
96
|
+
images
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const createVideoResponse = ($, videos) => ({
|
|
100
|
+
status: "success",
|
|
101
|
+
result: {
|
|
102
|
+
type: "video",
|
|
103
|
+
author: {
|
|
104
|
+
avatar: $("div.img-area > img").attr("src") || "",
|
|
105
|
+
nickname: $("h2.video-author > b").text()
|
|
106
|
+
},
|
|
107
|
+
desc: $("p.video-desc").text(),
|
|
108
|
+
...videos
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const getRequest = async (url, proxy) => {
|
|
112
|
+
try {
|
|
113
|
+
if (!validateTikTokUrl(url)) {
|
|
114
|
+
return {
|
|
115
|
+
status: "error",
|
|
116
|
+
message: constants_1.ERROR_MESSAGES.INVALID_URL
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const { data, headers } = await (0, axios_1.default)(api_1._musicaldownurl, {
|
|
120
|
+
method: "GET",
|
|
121
|
+
headers: {
|
|
122
|
+
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
123
|
+
"Update-Insecure-Requests": "1",
|
|
124
|
+
"User-Agent": USER_AGENT
|
|
125
|
+
},
|
|
126
|
+
...createProxyAgent(proxy)
|
|
127
|
+
});
|
|
128
|
+
const cookie = headers["set-cookie"]?.[0]?.split(";")[0];
|
|
129
|
+
if (!cookie) {
|
|
130
|
+
return {
|
|
131
|
+
status: "error",
|
|
132
|
+
message: constants_1.ERROR_MESSAGES.NETWORK_ERROR
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const $ = (0, cheerio_1.load)(data);
|
|
136
|
+
const request = extractRequestForm($, url);
|
|
137
|
+
return {
|
|
138
|
+
status: "success",
|
|
139
|
+
request,
|
|
140
|
+
cookie
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
return {
|
|
145
|
+
status: "error",
|
|
146
|
+
message: error instanceof Error ? error.message : constants_1.ERROR_MESSAGES.NETWORK_ERROR
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const MusicalDown = async (url, proxy) => {
|
|
151
|
+
try {
|
|
152
|
+
const request = await getRequest(url, proxy);
|
|
153
|
+
if (request.status !== "success") {
|
|
154
|
+
return {
|
|
155
|
+
status: "error",
|
|
156
|
+
message: request.message
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const { data } = await (0, axios_1.default)(api_1._musicaldownapi, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: {
|
|
162
|
+
cookie: request.cookie,
|
|
163
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
164
|
+
Origin: "https://musidown.com/download",
|
|
165
|
+
Referer: "https://musidown.com/download/en",
|
|
166
|
+
"Upgrade-Insecure-Requests": "1",
|
|
167
|
+
"User-Agent": USER_AGENT
|
|
168
|
+
},
|
|
169
|
+
data: new URLSearchParams(Object.entries(request.request)),
|
|
170
|
+
...createProxyAgent(proxy)
|
|
171
|
+
});
|
|
172
|
+
const $ = (0, cheerio_1.load)(data);
|
|
173
|
+
const images = parseImages($);
|
|
174
|
+
if (images.length > 0) {
|
|
175
|
+
return createImageResponse(images);
|
|
176
|
+
}
|
|
177
|
+
const videos = parseVideos($);
|
|
178
|
+
if (Object.keys(videos).length === 0) {
|
|
179
|
+
return {
|
|
180
|
+
status: "error",
|
|
181
|
+
message: "There is an error. Can't find download link"
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return createVideoResponse($, videos);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
return {
|
|
188
|
+
status: "error",
|
|
189
|
+
message: error instanceof Error ? error.message : constants_1.ERROR_MESSAGES.NETWORK_ERROR
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
exports.MusicalDown = MusicalDown;
|