@pieda/video-dl 1.3.1 → 1.3.2

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