基于Node.js 的抖音去水印视频下载脚本

基于Node.js 的抖音去水印视频下载脚本

新方法

安装request包

1
npm install request -D

新建文件 a.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
const request = require("request");
let postAns = function(url) {
return new Promise(function(resolve, reject) {
let DATA;
const options = {
method: "POST",
url: "http://wexin.qianbaihe.wang/douyin/DouyinUrl",
qs: { url }
};

request(options, function(error, response, body) {
if (error) throw new Error(error);
console.log("无水印地址如下---------------------------------\r\n");
console.log(
`http://wexin.qianbaihe.wang${JSON.parse(body).Model.DownUrl}\r\n`
);
console.log("分割线---------------------------------\r\n");
});
});
};
//readline 获取屏幕文字
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("请输入抖音链接地址:", answer => {
const link = answer;
//运行核心函数
postAns(link);
rl.close();
});

运行

1
node a.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
const http = require("http");
const querystring = require("querystring");
//此函数就是为了生成一个验证码
const generateStr = function(a) {
var c = (function() {
for (var d = 0, f = new Array(256), g = 0; 256 != g; ++g) {
(d = g),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(d = 1 & d ? -306674912 ^ (d >>> 1) : d >>> 1),
(f[g] = d);
}
return "undefined" != typeof Int32Array ? new Int32Array(f) : f;
})(),
b = function(g) {
for (var j, k, h = -1, f = 0, d = g.length; f < d; ) {
(j = g.charCodeAt(f++)),
j < 128
? (h = (h >>> 8) ^ c[255 & (h ^ j)])
: j < 2048
? ((h =
(h >>> 8) ^
c[255 & (h ^ (192 | ((j >> 6) & 31)))]),
(h = (h >>> 8) ^ c[255 & (h ^ (128 | (63 & j)))]))
: j >= 55296 && j < 57344
? ((j = (1023 & j) + 64),
(k = 1023 & g.charCodeAt(f++)),
(h =
(h >>> 8) ^
c[255 & (h ^ (240 | ((j >> 8) & 7)))]),
(h =
(h >>> 8) ^
c[255 & (h ^ (128 | ((j >> 2) & 63)))]),
(h =
(h >>> 8) ^
c[
255 &
(h ^
(128 |
((k >> 6) & 15) |
((3 & j) << 4)))
]),
(h =
(h >>> 8) ^
c[255 & (h ^ (128 | (63 & k)))]))
: ((h =
(h >>> 8) ^
c[255 & (h ^ (224 | ((j >> 12) & 15)))]),
(h =
(h >>> 8) ^
c[255 & (h ^ (128 | ((j >> 6) & 63)))]),
(h =
(h >>> 8) ^
c[255 & (h ^ (128 | (63 & j)))]));
}
return h ^ -1;
};
return b(a) >>> 0;
};
//获取Cookie函数
let getCookies = function() {
return new Promise(function(resolve, reject) {
var options = {
hostname: "douyin.iiilab.com",
port: 80,
path: "/",
method: "GET"
};
var req = http.request(options, function(res) {
res.setEncoding("utf8");

res.on("data", function(chunk) {
let cArr = res.headers["set-cookie"];
let Cookie = "";
Cookie = cArr[0].split(";")[0] + ";" + cArr[1].split(";")[0];
resolve(Cookie);
});
});
req.on("error", function(e) {
console.log("problem with request: " + e.message);
});
req.end();
});
};
// 提交抖音链接 和Cookie 获取数据
let postAns = function(link, Cookies = "") {
return new Promise(function(resolve, reject) {
let DATA;
const r = Math.random()
.toString(10)
.substring(2);
const s = generateStr(link + "@" + r).toString(10);

const postData = querystring.stringify({
link,
r,
s
});
const options = {
hostname: "service2.iiilab.com",
port: 80,
path: "/video/douyin",
method: "POST",
headers: {
"Content-Type":
"application/x-www-form-urlencoded; charset=UTF-8",
Origin: "http://douyin.iiilab.com",
Cookie: Cookies
}
};
var req = http.request(options, function(res) {
res.setEncoding("utf-8");
res.on("data", function(chun) {
// console.log("body分隔线---------------------------------\r\n");
// console.info(chun);
DATA += chun;
resolve(DATA);
});
res.on("end", function() {
// console.log("No more data in response.********");
});
});
req.on("error", function(err) {
console.error(err);
});
req.write(postData);
req.end(function() {});
});
};
//获取cookie 和 请求接口有个 先后顺序 引入 async/await 实行异步
let getTrueUrl = async function(link) {
let Cookies = await getCookies();
let reData = await postAns(link, Cookies);
console.log("无水印地址如下---------------------------------\r\n");
console.info(JSON.parse(reData).data.video + "\r\n");
console.log("分割线---------------------------------\r\n");
};
//readline 获取屏幕文字
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("请输入抖音链接地址:", answer => {
const link = answer;
//运行核心函数
getTrueUrl(link);
rl.close();
});

运行

建议安装node.js最新版,因为我是最新版8.11.1开发的,其他版本不清楚
运行很简单 把上面代码 保存为index.js
直接 运行框 输入

1
node index.js

如下:

这是输入从抖音复制的https开头的链接

这时回车运行就会出来视频无水印的视频下载地址 可以用浏览器打开,右击视频 另存为就可以下载了

# js, node.js

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×