-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdown tiktok china.js
162 lines (149 loc) · 5.55 KB
/
down tiktok china.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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": "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);
console.log(e);
}
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;
while (hasMore == 1) {
var moredata = await getid(sec_user_id, max_cursor);
hasMore = moredata['has_more'];
max_cursor = moredata['max_cursor'];
for (var i in moredata['aweme_list']) {
if (moredata['aweme_list'][i]['video']['play_addr']['url_list'][0].startsWith("https"))
result.push(moredata['aweme_list'][i]['video']['play_addr']['url_list'][0]);
else
result.push(moredata['aweme_list'][i]['video']['play_addr']['url_list'][0].replace("http", "https"));
console.clear();
console.log("Number of videos: " + result.length);
}
}
saveToFile(result.join('\n'));
}
run();
//===================== https://www.youtube.com/watch?v=oNZLFlW94h0
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": "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);
console.log(e);
}
return res;
}
var download=async function(url, aweme_id, desc){
var file_name = aweme_id + "-" + desc + ".mp4";
var data=await fetch(url, {
"headers": {
"accept": "*/*",
"accept-language": "vi,en-US;q=0.9,en;q=0.8",
"range": "bytes=0-",
"sec-ch-ua": "\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"MicrosoftEdge\";v=\"108\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "video",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
},
"referrer": "https://www.douyin.com/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "omit"
});
data=await data.blob();
var a = document.createElement("a");
a.href = window.URL.createObjectURL(data);
a.download = file_name;
a.click();
}
var waitforme=function(millisec) {
return new Promise(resolve => {
setTimeout(() => { resolve('') }, millisec);
})
}
var run=async function(){
var result=[];
var hasMore=1;
var sec_user_id=location.pathname.replace("/user/","");
var max_cursor=0;
var download_from=prompt("Enter id video(Enter 0 if want to download allvideo):","");
if(download_from==null || download_from=="") {
alert("Please, Enter id of video!");
return;
}
while(hasMore==1){
var moredata=await getid(sec_user_id,max_cursor);
hasMore=moredata['has_more'];
max_cursor=moredata['max_cursor'];
for(var i in moredata['aweme_list']){
if(moredata['aweme_list'][i]['aweme_id'] == download_from){
hasMore=0;
break;
}
if(moredata['aweme_list'][i]['video']['play_addr']['url_list'][0].startsWith("https"))
result.push([moredata['aweme_list'][i]['video']['play_addr']['url_list'][0],moredata['aweme_list'][i]['aweme_id'],moredata['aweme_list'][i]['desc']]);
else
result.push([moredata['aweme_list'][i]['video']['play_addr']['url_list'][0].replace("http","https"),moredata['aweme_list'][i]['aweme_id'],moredata['aweme_list'][i]['desc']]);
console.clear();
console.log("Number of videos: "+result.length);
}
}
for(var i=result.length-1;i>=0;i--){
await waitforme(1000);
try{download(result[i][0],result[i][1],result[i][2]);}catch{}
}
}
run();