-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (33 loc) · 1.15 KB
/
index.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
const axios = require("axios");
const fs = require("fs");
const download = require("download");
const outputDir = "output/";
const link = process.argv[2];
fs.rmSync(outputDir, { recursive: true, force: true });
fs.mkdirSync(outputDir);
axios.get(link).then((data) => {
fs.writeFileSync(outputDir + "master.m3u8", data.data);
const playListsPath = data.data
.match(/[^"]*\.m3u8/g)
.map((str) => str.replace("\n", ""));
for (const path of playListsPath) {
const pathName = path.replace(/[^/]*\.m3u8/g, "");
fs.mkdirSync(outputDir + pathName, {
recursive: true,
});
axios.get(link.replace(/[^/]*\.m3u8/g, "") + path).then(async (data) => {
fs.writeFileSync(outputDir + path, data.data);
const filesPaths = data.data
.match(/^[a-zA-Z0-9]*\.[a-zA-Z0-9]*$/gm)
.map((str) => str.replace("\n", ""));
for (const file of filesPaths) {
console.log(link.replace(/[^/]*\.m3u8/g, "") + pathName + file);
console.log(outputDir + pathName + file);
await download(
link.replace(/[^/]*\.m3u8/g, "") + pathName + file,
outputDir + pathName
);
}
});
}
});