@pieda/video-dl 1.2.0 → 1.3.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.
@@ -3,5 +3,5 @@ type TUseFacebook = {
3
3
  dest: string;
4
4
  debug?: boolean;
5
5
  };
6
- export declare const useFacebook: ({ videoId, dest, debug, }: TUseFacebook) => Promise<void>;
6
+ export declare const useFacebook: ({ videoId, dest, debug, }: TUseFacebook) => Promise<[Error | null, boolean | null]>;
7
7
  export {};
@@ -4,5 +4,5 @@ type TUseVimeo = {
4
4
  downloadBtnSelector?: string;
5
5
  debug?: boolean;
6
6
  };
7
- export declare const useVimeo: ({ videoId, dest, debug }: TUseVimeo) => Promise<void>;
7
+ export declare const useVimeo: ({ videoId, dest, debug, }: TUseVimeo) => Promise<[Error | null, boolean | null]>;
8
8
  export {};
@@ -3,5 +3,5 @@ type TUseYoutube = {
3
3
  dest: string;
4
4
  debug?: boolean;
5
5
  };
6
- export declare const useYoutube: ({ videoId, dest, debug }: TUseYoutube) => Promise<void>;
6
+ export declare const useYoutube: ({ videoId, dest, debug, }: TUseYoutube) => Promise<[Error | null, boolean | null]>;
7
7
  export {};
package/dist/video-dl.cjs CHANGED
@@ -1 +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;
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;
package/dist/video-dl.js CHANGED
@@ -1,94 +1,117 @@
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();
1
+ const c = (o) => new Promise((e, u) => {
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) => {
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(() => {
10
+ w();
11
11
  });
12
12
  });
13
- }).catch(a);
13
+ }).catch(r);
14
14
  });
15
- }, m = (o = !1) => ({
15
+ }, h = (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
- }), f = async ({ videoId: o, dest: e, debug: c = !1 }) => {
23
- const t = m(c);
22
+ }), f = async ({
23
+ videoId: o,
24
+ dest: e,
25
+ debug: u = !1
26
+ }) => {
27
+ const t = h(u);
24
28
  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
+ 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) => {
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;
37
+ });
38
+ } catch (a) {
39
+ s([a, null]);
40
+ }
30
41
  });
31
- }, v = async ({
42
+ }, y = async ({
32
43
  videoId: o,
33
44
  dest: e,
34
- debug: c = !1
45
+ debug: u = !1
35
46
  }) => {
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);
47
+ try {
48
+ const t = h(u);
49
+ 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();
53
+ t.log("啟動 puppeteer");
54
+ const n = await s.newPage();
55
+ await n.setUserAgent(
56
+ "'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
+ ), t.log("開新分頁"), await n.goto(w, {
58
+ waitUntil: "networkidle0"
59
+ }), 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];
62
+ } catch (t) {
63
+ return [t, null];
64
+ }
65
+ }, $ = async ({
66
+ videoId: o,
67
+ dest: e,
68
+ debug: u = !1
69
+ }) => {
70
+ const t = h(u);
52
71
  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", {
72
+ const w = await c("fs"), r = await c("path"), i = await c("axios"), p = async () => {
73
+ const n = await i.get("https://vimeo.com/_next/viewer", {
55
74
  responseType: "json",
56
75
  headers: {
57
76
  "X-Requested-With": "XMLHttpRequest"
58
77
  }
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`, {
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`, {
63
82
  responseType: "json",
64
83
  headers: {
65
84
  "X-Requested-With": "XMLHttpRequest",
66
- Authorization: `jwt ${w}`
85
+ Authorization: `jwt ${a}`
67
86
  }
68
- }), { download: g = [] } = p.data, d = g[0] || null;
87
+ }), { download: g = [] } = l.data, d = g[0] || null;
69
88
  return (d == null ? void 0 : d.link) || "";
70
89
  };
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();
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) => {
91
+ 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]);
98
+ }
76
99
  });
77
- }, $ = ({ type: o }) => {
100
+ }, v = ({ type: o }) => {
78
101
  switch (o) {
79
102
  case "youtube":
80
103
  return f;
81
104
  case "facebook":
82
- return v;
83
- case "vimeo":
84
105
  return y;
106
+ case "vimeo":
107
+ return $;
85
108
  default:
86
109
  throw new Error(`Invalid video type: ${o}`);
87
110
  }
88
111
  };
89
112
  export {
90
- $ as useDownloader,
91
- v as useFacebook,
92
- y as useVimeo,
113
+ v as useDownloader,
114
+ y as useFacebook,
115
+ $ as useVimeo,
93
116
  f as useYoutube
94
117
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pieda/video-dl",
3
3
  "private": false,
4
- "version": "1.2.0",
4
+ "version": "1.3.1",
5
5
  "type": "module",
6
6
  "main": "dist/video-dl.cjs",
7
7
  "module": "dist/video-dl.js",
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/piedasing/-pieda-video-dl.git"
13
+ "url": "https://github.com/piedasing/video-dl"
14
14
  },
15
15
  "author": "piedasing",
16
16
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "version:patch": "npm version patch"
37
37
  },
38
38
  "dependencies": {
39
- "@distube/ytdl-core": "^4.13.5",
39
+ "@distube/ytdl-core": "^4.15.1",
40
40
  "axios": "^1.7.2",
41
41
  "puppeteer": "^22.13.1"
42
42
  },
@@ -48,7 +48,6 @@
48
48
  "vue-tsc": "^1.4.2"
49
49
  },
50
50
  "peerDependencies": {
51
- "@distube/ytdl-core": "^4.13.5",
52
51
  "axios": "^1.7.2",
53
52
  "puppeteer": "^22.13.1"
54
53
  }