@pieda/video-dl 1.0.1 → 1.2.0
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/composables/useVimeo.d.ts +1 -1
- package/dist/video-dl.cjs +1 -0
- package/dist/video-dl.js +94 -0
- package/package.json +6 -3
- package/dist/video-dl.es.js +0 -110
|
@@ -4,5 +4,5 @@ type TUseVimeo = {
|
|
|
4
4
|
downloadBtnSelector?: string;
|
|
5
5
|
debug?: boolean;
|
|
6
6
|
};
|
|
7
|
-
export declare const useVimeo: ({ videoId, dest,
|
|
7
|
+
export declare const useVimeo: ({ videoId, dest, debug }: TUseVimeo) => Promise<void>;
|
|
8
8
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=o=>new Promise((e,c)=>{import(o).then(t=>e(t.default)).catch(c)}),h=async(o,e)=>{const c=await s("fs"),t=await s("axios");return new Promise((l,a)=>{t.get(o,{responseType:"stream"}).then(n=>{const u=n.data,r=c.createWriteStream(e);u.pipe(r),r.on("finish",function(){r.close(()=>{l()})})}).catch(a)})},m=(o=!1)=>({log:(...e)=>{o&&console.log(...e)},error:(...e)=>{o&&console.error(...e)}}),f=async({videoId:o,dest:e,debug:c=!1})=>{const t=m(c);t.log(`Downloading video: ${o} to: ${e}`);const l=`https://www.youtube.com/watch?v=${o}`,a=await s("fs"),n=await s("path"),u=await s("@distube/ytdl-core");return a.existsSync(n.dirname(e))||a.mkdirSync(n.dirname(e),{recursive:!0},777),new Promise((r,i)=>{u(l).pipe(a.createWriteStream(e)).on("finish",()=>{t.log("Downloading finished."),r()})})},y=async({videoId:o,dest:e,debug:c=!1})=>{const t=m(c);t.log(`Downloading video: ${o} to: ${e}`);const l=`https://m.facebook.com/watch/?v=${o}`,a=await s("fs"),n=await s("path"),u=await s("puppeteer");a.existsSync(n.dirname(e))||(a.mkdirSync(n.dirname(e),{recursive:!0},777),t.log(`建立 ${n.dirname(e)}`));const r=await u.launch();t.log("啟動 puppeteer");const i=await r.newPage();await i.setUserAgent("'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'"),t.log("開新分頁"),await i.goto(l,{waitUntil:"networkidle0"}),t.log(`前往 ${l}`),await i.waitForSelector("video"),t.log("找到 video 元素");const w=await i.$eval("video",p=>p.getAttribute("src"));t.log(`取得 video url: ${w}`),await r.close(),t.log("關閉 puppeteer"),await h(w,e),t.log(`下載完成 ${w}`)},v=async({videoId:o,dest:e,debug:c=!1})=>{const t=m(c);t.log(`Downloading video: ${o} to: ${e}`);const l=await s("fs"),a=await s("path"),n=await s("axios"),u=async()=>{const i=await n.get("https://vimeo.com/_next/viewer",{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest"}}),{jwt:w}=i.data;return w||""},r=async(i="",w="")=>{const p=await n.get(`https://api.vimeo.com/videos/${i}?&fields=download`,{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest",Authorization:`jwt ${w}`}}),{download:g=[]}=p.data,d=g[0]||null;return(d==null?void 0:d.link)||""};return l.existsSync(a.dirname(e))||(l.mkdirSync(a.dirname(e),{recursive:!0},777),t.log(`建立 ${a.dirname(e)}`)),new Promise(async(i,w)=>{const p=await u();t.log(`取得 jwt ${p}`);const g=await r(o,p);t.log(`取得 videoUrl ${g}`),await h(g,e),t.log(`下載完成 ${e}`),i()})},$=({type:o})=>{switch(o){case"youtube":return f;case"facebook":return y;case"vimeo":return v;default:throw new Error(`Invalid video type: ${o}`)}};exports.useDownloader=$;exports.useFacebook=y;exports.useVimeo=v;exports.useYoutube=f;
|
package/dist/video-dl.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const s = (o) => new Promise((e, c) => {
|
|
2
|
+
import(o).then((t) => e(t.default)).catch(c);
|
|
3
|
+
}), h = async (o, e) => {
|
|
4
|
+
const c = await s("fs"), t = await s("axios");
|
|
5
|
+
return new Promise((l, a) => {
|
|
6
|
+
t.get(o, { responseType: "stream" }).then((n) => {
|
|
7
|
+
const u = n.data, r = c.createWriteStream(e);
|
|
8
|
+
u.pipe(r), r.on("finish", function() {
|
|
9
|
+
r.close(() => {
|
|
10
|
+
l();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}).catch(a);
|
|
14
|
+
});
|
|
15
|
+
}, m = (o = !1) => ({
|
|
16
|
+
log: (...e) => {
|
|
17
|
+
o && console.log(...e);
|
|
18
|
+
},
|
|
19
|
+
error: (...e) => {
|
|
20
|
+
o && console.error(...e);
|
|
21
|
+
}
|
|
22
|
+
}), f = async ({ videoId: o, dest: e, debug: c = !1 }) => {
|
|
23
|
+
const t = m(c);
|
|
24
|
+
t.log(`Downloading video: ${o} to: ${e}`);
|
|
25
|
+
const l = `https://www.youtube.com/watch?v=${o}`, a = await s("fs"), n = await s("path"), u = await s("@distube/ytdl-core");
|
|
26
|
+
return a.existsSync(n.dirname(e)) || a.mkdirSync(n.dirname(e), { recursive: !0 }, 777), new Promise((r, i) => {
|
|
27
|
+
u(l).pipe(a.createWriteStream(e)).on("finish", () => {
|
|
28
|
+
t.log("Downloading finished."), r();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}, v = async ({
|
|
32
|
+
videoId: o,
|
|
33
|
+
dest: e,
|
|
34
|
+
debug: c = !1
|
|
35
|
+
}) => {
|
|
36
|
+
const t = m(c);
|
|
37
|
+
t.log(`Downloading video: ${o} to: ${e}`);
|
|
38
|
+
const l = `https://m.facebook.com/watch/?v=${o}`, a = await s("fs"), n = await s("path"), u = await s("puppeteer");
|
|
39
|
+
a.existsSync(n.dirname(e)) || (a.mkdirSync(n.dirname(e), { recursive: !0 }, 777), t.log(`建立 ${n.dirname(e)}`));
|
|
40
|
+
const r = await u.launch();
|
|
41
|
+
t.log("啟動 puppeteer");
|
|
42
|
+
const i = await r.newPage();
|
|
43
|
+
await i.setUserAgent(
|
|
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'"
|
|
45
|
+
), t.log("開新分頁"), await i.goto(l, {
|
|
46
|
+
waitUntil: "networkidle0"
|
|
47
|
+
}), t.log(`前往 ${l}`), await i.waitForSelector("video"), t.log("找到 video 元素");
|
|
48
|
+
const w = await i.$eval("video", (p) => p.getAttribute("src"));
|
|
49
|
+
t.log(`取得 video url: ${w}`), await r.close(), t.log("關閉 puppeteer"), await h(w, e), t.log(`下載完成 ${w}`);
|
|
50
|
+
}, y = async ({ videoId: o, dest: e, debug: c = !1 }) => {
|
|
51
|
+
const t = m(c);
|
|
52
|
+
t.log(`Downloading video: ${o} to: ${e}`);
|
|
53
|
+
const l = await s("fs"), a = await s("path"), n = await s("axios"), u = async () => {
|
|
54
|
+
const i = await n.get("https://vimeo.com/_next/viewer", {
|
|
55
|
+
responseType: "json",
|
|
56
|
+
headers: {
|
|
57
|
+
"X-Requested-With": "XMLHttpRequest"
|
|
58
|
+
}
|
|
59
|
+
}), { jwt: w } = i.data;
|
|
60
|
+
return w || "";
|
|
61
|
+
}, r = async (i = "", w = "") => {
|
|
62
|
+
const p = await n.get(`https://api.vimeo.com/videos/${i}?&fields=download`, {
|
|
63
|
+
responseType: "json",
|
|
64
|
+
headers: {
|
|
65
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
66
|
+
Authorization: `jwt ${w}`
|
|
67
|
+
}
|
|
68
|
+
}), { download: g = [] } = p.data, d = g[0] || null;
|
|
69
|
+
return (d == null ? void 0 : d.link) || "";
|
|
70
|
+
};
|
|
71
|
+
return l.existsSync(a.dirname(e)) || (l.mkdirSync(a.dirname(e), { recursive: !0 }, 777), t.log(`建立 ${a.dirname(e)}`)), new Promise(async (i, w) => {
|
|
72
|
+
const p = await u();
|
|
73
|
+
t.log(`取得 jwt ${p}`);
|
|
74
|
+
const g = await r(o, p);
|
|
75
|
+
t.log(`取得 videoUrl ${g}`), await h(g, e), t.log(`下載完成 ${e}`), i();
|
|
76
|
+
});
|
|
77
|
+
}, $ = ({ type: o }) => {
|
|
78
|
+
switch (o) {
|
|
79
|
+
case "youtube":
|
|
80
|
+
return f;
|
|
81
|
+
case "facebook":
|
|
82
|
+
return v;
|
|
83
|
+
case "vimeo":
|
|
84
|
+
return y;
|
|
85
|
+
default:
|
|
86
|
+
throw new Error(`Invalid video type: ${o}`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
$ as useDownloader,
|
|
91
|
+
v as useFacebook,
|
|
92
|
+
y as useVimeo,
|
|
93
|
+
f as useYoutube
|
|
94
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pieda/video-dl",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "dist/video-dl.cjs",
|
|
7
|
+
"module": "dist/video-dl.js",
|
|
6
8
|
"files": [
|
|
7
9
|
"dist"
|
|
8
10
|
],
|
|
@@ -19,8 +21,9 @@
|
|
|
19
21
|
".": {
|
|
20
22
|
"import": {
|
|
21
23
|
"types": "./dist/types/library.d.ts",
|
|
22
|
-
"default": "./dist/video-dl.
|
|
23
|
-
}
|
|
24
|
+
"default": "./dist/video-dl.js"
|
|
25
|
+
},
|
|
26
|
+
"require": "./dist/video-dl.cjs"
|
|
24
27
|
}
|
|
25
28
|
},
|
|
26
29
|
"scripts": {
|
package/dist/video-dl.es.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
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();
|
|
11
|
-
});
|
|
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();
|
|
29
|
-
});
|
|
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(
|
|
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'"
|
|
45
|
-
), o.log("開新分頁"), await w.goto(a, {
|
|
46
|
-
waitUntil: "networkidle0"
|
|
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
|
|
55
|
-
}) => {
|
|
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, {
|
|
61
|
-
responseType: "json",
|
|
62
|
-
headers: {
|
|
63
|
-
"X-Requested-With": "XMLHttpRequest"
|
|
64
|
-
}
|
|
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({
|
|
70
|
-
headless: !1,
|
|
71
|
-
defaultViewport: {
|
|
72
|
-
width: 1920,
|
|
73
|
-
height: 1080
|
|
74
|
-
}
|
|
75
|
-
});
|
|
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();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
m.continue();
|
|
87
|
-
}), await p.goto(n, {
|
|
88
|
-
waitUntil: "networkidle0"
|
|
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("點擊下載按鈕");
|
|
92
|
-
});
|
|
93
|
-
}, x = ({ type: t }) => {
|
|
94
|
-
switch (t) {
|
|
95
|
-
case "youtube":
|
|
96
|
-
return k;
|
|
97
|
-
case "facebook":
|
|
98
|
-
return S;
|
|
99
|
-
case "vimeo":
|
|
100
|
-
return P;
|
|
101
|
-
default:
|
|
102
|
-
throw new Error(`Invalid video type: ${t}`);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
export {
|
|
106
|
-
x as useDownloader,
|
|
107
|
-
S as useFacebook,
|
|
108
|
-
P as useVimeo,
|
|
109
|
-
k as useYoutube
|
|
110
|
-
};
|