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