-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathdouyin_downloadAllVideoUser.js
98 lines (92 loc) · 3.29 KB
/
douyin_downloadAllVideoUser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
export default {
icon: "https://www.douyin.com/favicon.ico",
name: {
en: "Douyin - Download all user videos",
vi: "Douyin - Tải tất cả video người dùng",
},
description: {
en: "Download all videos in douyin user profile.",
vi: "Tải tất cả video trong trang cá nhân của người dùng douyin.",
},
whiteList: ["https://www.douyin.com/user/*"],
contentScript: {
// https://github.com/diepvantien/douyin-dowload-all-video
onClick: () => {
alert("Mở console (F12) để xem tiến trình tải video.");
var getid = async function (sec_user_id, max_cursor) {
var res = await fetch(
"https://www.douyin.com/aweme/v1/web/aweme/post/?device_platform=webapp&aid=6383&channel=channel_pc_web&sec_user_id=" +
sec_user_id +
"&max_cursor=" +
max_cursor,
{
headers: {
accept: "application/json, text/plain, */*",
"accept-language": "vi",
"sec-ch-ua":
'"Not?A_Brand";v="8", "Chromium";v="108", "Microsoft Edge";v="108"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
},
referrer: location.href,
// "https://www.douyin.com/user/MS4wLjABAAAA5A-hCBCTdv102baOvaoZqg7nCIW_Bn_YBA0Aiz9uYPY",
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "GET",
mode: "cors",
credentials: "include",
}
);
try {
res = await res.json();
} catch (e) {
res = await getid(sec_user_id, max_cursor);
}
return res;
};
var saveToFile = function (text) {
var blob = new Blob([text], { type: "text/plain" });
var a = document.createElement("a");
a.href = window.URL.createObjectURL(blob);
a.download = "douyin-video-links.txt";
a.click();
};
var run = async function () {
var result = [];
var hasMore = 1;
var sec_user_id = location.pathname.replace("/user/", "");
var max_cursor = 0;
console.log('Đang chuẩn bị tải video của "' + sec_user_id + '" ...');
while (hasMore == 1) {
var moredata = await getid(sec_user_id, max_cursor);
console.log(moredata);
hasMore = moredata["has_more"];
max_cursor = moredata["max_cursor"];
for (var item of moredata["aweme_list"] || []) {
try {
let url = item.video.play_addr.url_list[0];
if (url.startsWith("https")) {
result.push(url);
} else {
result.push(url.replace("http", "https"));
}
// console.clear();
console.log("Number of videos: " + result.length);
} catch (e) {
console.log("ERROR: ", e);
}
}
console.log(hasMore);
}
saveToFile(result.join("\n"));
alert(
"Link videos sẽ được lưu vào file .txt, thêm file này vào idm để tải hàng loạt."
);
};
run();
},
},
};