@pieda/video-dl 1.1.0 → 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 -1
- package/dist/video-dl.js +66 -82
- package/package.json +1 -1
|
@@ -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 {};
|
package/dist/video-dl.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
CHANGED
|
@@ -1,110 +1,94 @@
|
|
|
1
|
-
const
|
|
2
|
-
import(
|
|
3
|
-
}),
|
|
4
|
-
const c = await
|
|
5
|
-
return new Promise((
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
11
|
});
|
|
12
12
|
});
|
|
13
|
-
}).catch(
|
|
13
|
+
}).catch(a);
|
|
14
14
|
});
|
|
15
|
-
},
|
|
15
|
+
}, m = (o = !1) => ({
|
|
16
16
|
log: (...e) => {
|
|
17
|
-
|
|
17
|
+
o && console.log(...e);
|
|
18
18
|
},
|
|
19
19
|
error: (...e) => {
|
|
20
|
-
|
|
20
|
+
o && console.error(...e);
|
|
21
21
|
}
|
|
22
|
-
}),
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
l
|
|
28
|
-
|
|
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
29
|
});
|
|
30
30
|
});
|
|
31
|
-
},
|
|
32
|
-
videoId:
|
|
31
|
+
}, v = async ({
|
|
32
|
+
videoId: o,
|
|
33
33
|
dest: e,
|
|
34
34
|
debug: c = !1
|
|
35
35
|
}) => {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
await
|
|
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
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
|
-
),
|
|
45
|
+
), t.log("開新分頁"), await i.goto(l, {
|
|
46
46
|
waitUntil: "networkidle0"
|
|
47
|
-
}),
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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, {
|
|
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", {
|
|
61
55
|
responseType: "json",
|
|
62
56
|
headers: {
|
|
63
57
|
"X-Requested-With": "XMLHttpRequest"
|
|
64
58
|
}
|
|
65
|
-
}),
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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;
|
|
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}`
|
|
85
67
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
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();
|
|
92
76
|
});
|
|
93
|
-
},
|
|
94
|
-
switch (
|
|
77
|
+
}, $ = ({ type: o }) => {
|
|
78
|
+
switch (o) {
|
|
95
79
|
case "youtube":
|
|
96
|
-
return
|
|
80
|
+
return f;
|
|
97
81
|
case "facebook":
|
|
98
|
-
return
|
|
82
|
+
return v;
|
|
99
83
|
case "vimeo":
|
|
100
|
-
return
|
|
84
|
+
return y;
|
|
101
85
|
default:
|
|
102
|
-
throw new Error(`Invalid video type: ${
|
|
86
|
+
throw new Error(`Invalid video type: ${o}`);
|
|
103
87
|
}
|
|
104
88
|
};
|
|
105
89
|
export {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
90
|
+
$ as useDownloader,
|
|
91
|
+
v as useFacebook,
|
|
92
|
+
y as useVimeo,
|
|
93
|
+
f as useYoutube
|
|
110
94
|
};
|