@pieda/video-dl 1.0.0 → 1.0.1
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/dist/types/_func.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
type TUseYoutube = {
|
|
2
2
|
videoId: string;
|
|
3
3
|
dest: string;
|
|
4
|
+
debug?: boolean;
|
|
4
5
|
};
|
|
5
|
-
export declare const useYoutube: ({ videoId, dest }: TUseYoutube) => Promise<void>;
|
|
6
|
+
export declare const useYoutube: ({ videoId, dest, debug }: TUseYoutube) => Promise<void>;
|
|
6
7
|
export {};
|
package/dist/video-dl.es.js
CHANGED
|
@@ -1,107 +1,110 @@
|
|
|
1
|
-
const
|
|
2
|
-
import(
|
|
3
|
-
}),
|
|
4
|
-
const
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
videoId: i,
|
|
12
|
-
dest: t,
|
|
13
|
-
debug: d = !1
|
|
14
|
-
}) => {
|
|
15
|
-
const n = `https://m.facebook.com/watch/?v=${i}`, s = await o("fs"), c = await o("path"), m = await o("axios"), y = await o("puppeteer"), g = (r, l) => new Promise((w, f) => {
|
|
16
|
-
m.get(r, { responseType: "stream" }).then((u) => {
|
|
17
|
-
const p = u.data, v = s.createWriteStream(l);
|
|
18
|
-
p.pipe(v), v.on("finish", function() {
|
|
19
|
-
v.close(() => {
|
|
20
|
-
w();
|
|
1
|
+
const i = (t) => new Promise((e, c) => {
|
|
2
|
+
import(t).then((o) => e(o.default)).catch(c);
|
|
3
|
+
}), b = async (t, e) => {
|
|
4
|
+
const c = await i("fs"), o = await i("axios");
|
|
5
|
+
return new Promise((a, n) => {
|
|
6
|
+
o.get(t, { responseType: "stream" }).then((r) => {
|
|
7
|
+
const l = r.data, s = c.createWriteStream(e);
|
|
8
|
+
l.pipe(s), s.on("finish", function() {
|
|
9
|
+
s.close(() => {
|
|
10
|
+
a();
|
|
21
11
|
});
|
|
22
12
|
});
|
|
13
|
+
}).catch(n);
|
|
14
|
+
});
|
|
15
|
+
}, v = (t = !1) => ({
|
|
16
|
+
log: (...e) => {
|
|
17
|
+
t && console.log(...e);
|
|
18
|
+
},
|
|
19
|
+
error: (...e) => {
|
|
20
|
+
t && console.error(...e);
|
|
21
|
+
}
|
|
22
|
+
}), k = async ({ videoId: t, dest: e, debug: c = !1 }) => {
|
|
23
|
+
const o = v(c);
|
|
24
|
+
o.log(`Downloading video: ${t} to: ${e}`);
|
|
25
|
+
const a = `https://www.youtube.com/watch?v=${t}`, n = await i("fs"), r = await i("path"), l = await i("@distube/ytdl-core");
|
|
26
|
+
return n.existsSync(r.dirname(e)) || n.mkdirSync(r.dirname(e), { recursive: !0 }, 777), new Promise((s, w) => {
|
|
27
|
+
l(a).pipe(n.createWriteStream(e)).on("finish", () => {
|
|
28
|
+
o.log("Downloading finished."), s();
|
|
23
29
|
});
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
});
|
|
31
|
+
}, S = async ({
|
|
32
|
+
videoId: t,
|
|
33
|
+
dest: e,
|
|
34
|
+
debug: c = !1
|
|
35
|
+
}) => {
|
|
36
|
+
const o = v(c);
|
|
37
|
+
o.log(`Downloading video: ${t} to: ${e}`);
|
|
38
|
+
const a = `https://m.facebook.com/watch/?v=${t}`, n = await i("fs"), r = await i("path"), l = await i("puppeteer");
|
|
39
|
+
n.existsSync(r.dirname(e)) || (n.mkdirSync(r.dirname(e), { recursive: !0 }, 777), o.log(`建立 ${r.dirname(e)}`));
|
|
40
|
+
const s = await l.launch();
|
|
41
|
+
o.log("啟動 puppeteer");
|
|
42
|
+
const w = await s.newPage();
|
|
43
|
+
await w.setUserAgent(
|
|
32
44
|
"'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1'"
|
|
33
|
-
),
|
|
45
|
+
), o.log("開新分頁"), await w.goto(a, {
|
|
34
46
|
waitUntil: "networkidle0"
|
|
35
|
-
}),
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
videoId:
|
|
40
|
-
dest:
|
|
41
|
-
downloadBtnSelector:
|
|
42
|
-
debug:
|
|
47
|
+
}), o.log(`前往 ${a}`), await w.waitForSelector("video"), o.log("找到 video 元素");
|
|
48
|
+
const u = await w.$eval("video", (g) => g.getAttribute("src"));
|
|
49
|
+
o.log(`取得 video url: ${u}`), await s.close(), o.log("關閉 puppeteer"), await b(u, e), o.log(`下載完成 ${u}`);
|
|
50
|
+
}, P = async ({
|
|
51
|
+
videoId: t,
|
|
52
|
+
dest: e,
|
|
53
|
+
downloadBtnSelector: c,
|
|
54
|
+
debug: o = !1
|
|
43
55
|
}) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
var
|
|
48
|
-
const
|
|
56
|
+
const a = v(o);
|
|
57
|
+
a.log(`Downloading video: ${t} to: ${e}`);
|
|
58
|
+
const n = `https://vimeo.com/${t}`, r = await i("fs"), l = await i("path"), s = await i("axios"), w = await i("puppeteer"), u = async (g) => {
|
|
59
|
+
var m;
|
|
60
|
+
const y = await s.get(g, {
|
|
49
61
|
responseType: "json",
|
|
50
62
|
headers: {
|
|
51
63
|
"X-Requested-With": "XMLHttpRequest"
|
|
52
64
|
}
|
|
53
|
-
}),
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
u.pipe(p), p.on("finish", function() {
|
|
59
|
-
p.close(() => {
|
|
60
|
-
l();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
return c.existsSync(m.dirname(t)) || (c.mkdirSync(m.dirname(t), { recursive: !0 }, 777), e(`建立 ${m.dirname(t)}`)), new Promise(async (a, r) => {
|
|
66
|
-
const l = await g.launch({
|
|
65
|
+
}), d = Array.from(((m = y.data) == null ? void 0 : m.files) || []);
|
|
66
|
+
return d[d.length - 1].download_url;
|
|
67
|
+
};
|
|
68
|
+
return r.existsSync(l.dirname(e)) || (r.mkdirSync(l.dirname(e), { recursive: !0 }, 777), a.log(`建立 ${l.dirname(e)}`)), new Promise(async (g, y) => {
|
|
69
|
+
const d = await w.launch({
|
|
67
70
|
headless: !1,
|
|
68
71
|
defaultViewport: {
|
|
69
72
|
width: 1920,
|
|
70
73
|
height: 1080
|
|
71
74
|
}
|
|
72
75
|
});
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
76
|
+
a.log("啟動 puppeteer");
|
|
77
|
+
const p = await d.newPage();
|
|
78
|
+
a.log("開新分頁"), await p.setRequestInterception(!0), p.on("request", async (m) => {
|
|
79
|
+
const h = m.url();
|
|
80
|
+
if (h.indexOf("action=load_download_config") > -1) {
|
|
81
|
+
a.log(`攔截下載請求 ${h}`);
|
|
82
|
+
const $ = await u(h);
|
|
83
|
+
a.log(`正在開始下載 ${$}`), await b($, e), a.log(`下載完成 ${e}`), await d.close(), a.log("關閉 puppeteer"), g();
|
|
81
84
|
return;
|
|
82
85
|
}
|
|
83
|
-
|
|
84
|
-
}), await
|
|
86
|
+
m.continue();
|
|
87
|
+
}), await p.goto(n, {
|
|
85
88
|
waitUntil: "networkidle0"
|
|
86
|
-
}),
|
|
87
|
-
const f =
|
|
88
|
-
await
|
|
89
|
+
}), a.log(`前往 ${n}`);
|
|
90
|
+
const f = c || "#main > div > main > div > div > div > div._1cCXb.sc-kEmuub.bmHlZQ > div._3oHHF.sc-bbkauy.fmFDPY > div > button:nth-child(1)";
|
|
91
|
+
await p.waitForSelector(f), a.log(`找到下載按鈕 ${f}`), await p.click(f), a.log("點擊下載按鈕");
|
|
89
92
|
});
|
|
90
|
-
},
|
|
91
|
-
switch (
|
|
93
|
+
}, x = ({ type: t }) => {
|
|
94
|
+
switch (t) {
|
|
92
95
|
case "youtube":
|
|
93
|
-
return $;
|
|
94
|
-
case "facebook":
|
|
95
96
|
return k;
|
|
96
|
-
case "
|
|
97
|
+
case "facebook":
|
|
97
98
|
return S;
|
|
99
|
+
case "vimeo":
|
|
100
|
+
return P;
|
|
98
101
|
default:
|
|
99
|
-
throw new Error(`Invalid video type: ${
|
|
102
|
+
throw new Error(`Invalid video type: ${t}`);
|
|
100
103
|
}
|
|
101
104
|
};
|
|
102
105
|
export {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
x as useDownloader,
|
|
107
|
+
S as useFacebook,
|
|
108
|
+
P as useVimeo,
|
|
109
|
+
k as useYoutube
|
|
107
110
|
};
|