@pieda/video-dl 1.6.0 → 1.7.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/video-dl.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=o=>new Promise((t,g)=>{import(o).then(i=>t(i.default)).catch(g)}),h=async(o,t,g)=>{const i=await c("fs"),e=await c("axios");return console.log(`Downloading ${o} to ${t}`),new Promise((n,l)=>{e.get(o,{responseType:"stream",headers:g}).then(s=>{const p=s.data,r=i.createWriteStream(t);p.pipe(r),r.on("finish",function(){r.close(()=>{n()})})}).catch(l)})},m=(o=!1)=>({log:(...t)=>{o&&console.log(...t)},error:(...t)=>{o&&console.error(...t)}}),f=async({videoId:o,dest:t,debug:g=!1})=>{const i=m(g);i.log(`Downloading video: ${o} to: ${t}`);const e=`https://www.youtube.com/watch?v=${o}`,n=await c("fs"),l=await c("path"),s=await c("@distube/ytdl-core");return n.existsSync(l.dirname(t))||n.mkdirSync(l.dirname(t),{recursive:!0},777),new Promise((p,r)=>{try{s(e).on("error",a=>{i.error(a),p([a,null])}).pipe(n.createWriteStream(t)).on("finish",()=>{i.log("Downloading finished."),p([null,!0])})}catch(u){console.log("error"),p([u,null])}})},$=async({videoId:o,dest:t,debug:g=!1,headless:i=!0})=>{try{const e=m(g);e.log(`Downloading video: ${o} to: ${t}`);const n=`https://m.facebook.com/watch/?v=${o}`,l=await c("fs"),s=await c("path"),p=await c("puppeteer");l.existsSync(s.dirname(t))||(l.mkdirSync(s.dirname(t),{recursive:!0},777),e.log(`建立 ${s.dirname(t)}`));const r={};i||(r.headless=!1);const u=await p.launch(r);e.log("啟動 puppeteer");const a=await u.newPage();await a.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'"),e.log("開新分頁"),await a.goto(n,{waitUntil:"networkidle0"}),e.log(`前往 ${n}`),await a.waitForSelector("video"),e.log("找到 video 元素");const w=await a.$eval("video",d=>d.getAttribute("src"));return e.log(`取得 video url: ${w}`),await u.close(),e.log("關閉 puppeteer"),await h(w,t),e.log(`下載完成 ${w}`),[null,!0]}catch(e){return[e,null]}},y=async({videoId:o,dest:t,debug:g=!1})=>{const i=m(g);i.log(`Downloading video: ${o} to: ${t}`);const e=await c("fs"),n=await c("path"),l=await c("axios"),s=async()=>{const r=await l.get("https://vimeo.com/_next/viewer",{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest"}}),{jwt:u}=r.data;return u||""},p=async(r="",u="")=>{const a=await l.get(`https://api.vimeo.com/videos/${r}?&fields=download`,{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest",Authorization:`jwt ${u}`}}),{download:w=[]}=a.data,d=w[0]||null;return(d==null?void 0:d.link)||""};return e.existsSync(n.dirname(t))||(e.mkdirSync(n.dirname(t),{recursive:!0},777),i.log(`建立 ${n.dirname(t)}`)),new Promise(async(r,u)=>{try{const a=await s();i.log(`取得 jwt ${a}`);const w=await p(o,a);i.log(`取得 videoUrl ${w}`),await h(w,t),i.log(`下載完成 ${t}`),r([null,!0])}catch(a){r([a,null])}})},v=async({videoId:o,dest:t,debug:g=!1,headless:i=!0})=>{try{const e=m(g);e.log(`Downloading video: ${o} to: ${t}`);const n=`https://www.instagram.com/reel/${o}/`,l=await c("fs"),s=await c("path"),p=await c("puppeteer");l.existsSync(s.dirname(t))||(l.mkdirSync(s.dirname(t),{recursive:!0},777),e.log(`建立 ${s.dirname(t)}`));const r={};i||(r.headless=!1);const u=await p.launch(r);e.log("啟動 puppeteer");const a=await u.newPage();await a.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'"),e.log("開新分頁"),await a.goto(n,{}),e.log(`前往 ${n}`),await a.waitForSelector("video"),e.log("找到 video 元素");const w=await a.$eval("video",d=>d.getAttribute("src"));return e.log(`取得 video url: ${w}`),await u.close(),e.log("關閉 puppeteer"),await h(w,t),e.log(`下載完成 ${w}`),[null,!0]}catch(e){return[e,null]}},k=async({videoLink:o,dest:t,debug:g=!1,headless:i=!0})=>{try{const e=m(g);e.log(`Downloading video: ${o} to: ${t}`);const n=o,l=await c("fs"),s=await c("path"),p=await c("puppeteer");l.existsSync(s.dirname(t))||(l.mkdirSync(s.dirname(t),{recursive:!0},777),e.log(`建立 ${s.dirname(t)}`));const r={};i||(r.headless=!1);const u=await p.launch(r);e.log("啟動 puppeteer");const a=await u.newPage();e.log("開新分頁"),await a.goto(n,{}),e.log(`前往 ${n}`),await a.waitForSelector("video"),e.log("找到 video 元素");const w=await a.$eval('video source[src^="https://www.tiktok.com/aweme/v1/play/"]',d=>d.getAttribute("src"));return e.log(`取得 video url: ${w}`),await u.close(),e.log("關閉 puppeteer"),await h(w,t,{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",Referer:"https://www.tiktok.com/"}),e.log(`下載完成 ${w}`),[null,!0]}catch(e){return[e,null]}},S=({type:o})=>{switch(o){case"youtube":case"yt-short":return f;case"facebook":case"fb-reel":return $;case"vimeo":return y;case"instagram":case"ig":case"ig-reel":return v;case"tiktok":case"tiktok-reel":return k;default:throw new Error(`Invalid video type: ${o}`)}};exports.useDownloader=S;exports.useFacebook=$;exports.useInstagram=v;exports.useTiktok=k;exports.useVimeo=y;exports.useYoutube=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=o=>new Promise((t,u)=>{import(o).then(i=>t(i.default)).catch(u)}),m=async(o,t,u)=>{const i=await l("fs"),e=await l("axios");return console.log(`Downloading ${o} to ${t}`),new Promise((n,w)=>{e.get(o,{responseType:"stream",headers:u}).then(s=>{const p=s.data,a=i.createWriteStream(t);p.pipe(a),a.on("finish",function(){a.close(()=>{n()})})}).catch(w)})},f=(o=!1)=>({log:(...t)=>{o&&console.log(...t)},error:(...t)=>{o&&console.error(...t)}}),h=async({videoId:o,dest:t,debug:u=!1})=>{f(u).log(`Downloading video: ${o} to: ${t}`);const e=await l("fs"),n=await l("path"),w=await l("youtubei.js");e.existsSync(n.dirname(t))||e.mkdirSync(n.dirname(t),{recursive:!0},777);const s=await w.create({cache:!1,generate_session_locally:!0});try{const p=await s.download(o,{type:"video+audio",quality:"best",format:"mp4",client:"WEB"}),a=e.createWriteStream(t);for await(const g of b(p))a.write(g);return[null,!0]}catch(p){return console.log("error",p),[p,null]}};async function*b(o){const t=o.getReader();try{for(;;){const{done:u,value:i}=await t.read();if(u)return;yield i}}finally{t.releaseLock()}}const y=async({videoId:o,dest:t,debug:u=!1,headless:i=!0})=>{try{const e=f(u);e.log(`Downloading video: ${o} to: ${t}`);const n=`https://m.facebook.com/watch/?v=${o}`,w=await l("fs"),s=await l("path"),p=await l("puppeteer");w.existsSync(s.dirname(t))||(w.mkdirSync(s.dirname(t),{recursive:!0},777),e.log(`建立 ${s.dirname(t)}`));const a={};i||(a.headless=!1);const g=await p.launch(a);e.log("啟動 puppeteer");const r=await g.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'"),e.log("開新分頁"),e.log(`前往 ${n}`),await Promise.race([r.goto(n,{waitUntil:"networkidle0"}),r.waitForSelector("video")]),e.log("找到 video 元素");const c=await r.$eval("video",d=>d.getAttribute("src"));return e.log(`取得 video url: ${c}`),await g.close(),e.log("關閉 puppeteer"),await m(c,t),e.log(`下載完成 ${c}`),[null,!0]}catch(e){return[e,null]}},v=async({videoId:o,dest:t,debug:u=!1})=>{const i=f(u);i.log(`Downloading video: ${o} to: ${t}`);const e=await l("fs"),n=await l("path"),w=await l("axios"),s=async()=>{const a=await w.get("https://vimeo.com/_next/viewer",{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest"}}),{jwt:g}=a.data;return g||""},p=async(a="",g="")=>{const r=await w.get(`https://api.vimeo.com/videos/${a}?&fields=download`,{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest",Authorization:`jwt ${g}`}}),{download:c=[]}=r.data,d=c[0]||null;return(d==null?void 0:d.link)||""};return e.existsSync(n.dirname(t))||(e.mkdirSync(n.dirname(t),{recursive:!0},777),i.log(`建立 ${n.dirname(t)}`)),new Promise(async(a,g)=>{try{const r=await s();i.log(`取得 jwt ${r}`);const c=await p(o,r);i.log(`取得 videoUrl ${c}`),await m(c,t),i.log(`下載完成 ${t}`),a([null,!0])}catch(r){a([r,null])}})},$=async({videoId:o,dest:t,debug:u=!1,headless:i=!0})=>{try{const e=f(u);e.log(`Downloading video: ${o} to: ${t}`);const n=`https://www.instagram.com/reel/${o}/`,w=await l("fs"),s=await l("path"),p=await l("puppeteer");w.existsSync(s.dirname(t))||(w.mkdirSync(s.dirname(t),{recursive:!0},777),e.log(`建立 ${s.dirname(t)}`));const a={};i||(a.headless=!1);const g=await p.launch(a);e.log("啟動 puppeteer");const r=await g.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'"),e.log("開新分頁"),e.log(`前往 ${n}`),await Promise.race([r.goto(n,{waitUntil:"networkidle0"}),r.waitForSelector("video")]),e.log("找到 video 元素");const c=await r.$eval("video",d=>d.getAttribute("src"));return e.log(`取得 video url: ${c}`),await g.close(),e.log("關閉 puppeteer"),await m(c,t),e.log(`下載完成 ${c}`),[null,!0]}catch(e){return[e,null]}},k=async({videoLink:o,dest:t,debug:u=!1,headless:i=!0})=>{try{const e=f(u);e.log(`Downloading video: ${o} to: ${t}`);const n=o,w=await l("fs"),s=await l("path"),p=await l("puppeteer");w.existsSync(s.dirname(t))||(w.mkdirSync(s.dirname(t),{recursive:!0},777),e.log(`建立 ${s.dirname(t)}`));const a={};i||(a.headless=!1);const g=await p.launch(a);e.log("啟動 puppeteer");const r=await g.newPage();e.log("開新分頁"),e.log(`前往 ${n}`),await Promise.race([r.goto(n,{waitUntil:"networkidle0"}),r.waitForSelector("video")]),e.log("找到 video 元素");const c=await r.$eval('video source[src^="https://www.tiktok.com/aweme/v1/play/"]',d=>d.getAttribute("src"));return e.log(`取得 video url: ${c}`),await g.close(),e.log("關閉 puppeteer"),await m(c,t,{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",Referer:"https://www.tiktok.com/"}),e.log(`下載完成 ${c}`),[null,!0]}catch(e){return[e,null]}},S=({type:o})=>{switch(o){case"youtube":case"yt-short":return h;case"facebook":case"fb-reel":return y;case"vimeo":return v;case"instagram":case"ig":case"ig-reel":return $;case"tiktok":case"tiktok-reel":return k;default:throw new Error(`Invalid video type: ${o}`)}};exports.useDownloader=S;exports.useFacebook=y;exports.useInstagram=$;exports.useTiktok=k;exports.useVimeo=v;exports.useYoutube=h;
package/dist/video-dl.js CHANGED
@@ -1,190 +1,219 @@
1
- const c = (o) => new Promise((t, g) => {
2
- import(o).then((i) => t(i.default)).catch(g);
3
- }), m = async (o, t, g) => {
4
- const i = await c("fs"), e = await c("axios");
5
- return console.log(`Downloading ${o} to ${t}`), new Promise((n, l) => {
1
+ const l = (o) => new Promise((t, u) => {
2
+ import(o).then((i) => t(i.default)).catch(u);
3
+ }), m = async (o, t, u) => {
4
+ const i = await l("fs"), e = await l("axios");
5
+ return console.log(`Downloading ${o} to ${t}`), new Promise((n, w) => {
6
6
  e.get(o, {
7
7
  responseType: "stream",
8
- headers: g
8
+ headers: u
9
9
  }).then((s) => {
10
- const p = s.data, r = i.createWriteStream(t);
11
- p.pipe(r), r.on("finish", function() {
12
- r.close(() => {
10
+ const p = s.data, a = i.createWriteStream(t);
11
+ p.pipe(a), a.on("finish", function() {
12
+ a.close(() => {
13
13
  n();
14
14
  });
15
15
  });
16
- }).catch(l);
16
+ }).catch(w);
17
17
  });
18
- }, d = (o = !1) => ({
18
+ }, f = (o = !1) => ({
19
19
  log: (...t) => {
20
20
  o && console.log(...t);
21
21
  },
22
22
  error: (...t) => {
23
23
  o && console.error(...t);
24
24
  }
25
- }), f = async ({
25
+ }), h = async ({
26
26
  videoId: o,
27
27
  dest: t,
28
- debug: g = !1
28
+ debug: u = !1
29
29
  }) => {
30
- const i = d(g);
31
- i.log(`Downloading video: ${o} to: ${t}`);
32
- const e = `https://www.youtube.com/watch?v=${o}`, n = await c("fs"), l = await c("path"), s = await c("@distube/ytdl-core");
33
- return n.existsSync(l.dirname(t)) || n.mkdirSync(l.dirname(t), { recursive: !0 }, 777), new Promise((p, r) => {
34
- try {
35
- s(e).on("error", (a) => {
36
- i.error(a), p([a, null]);
37
- }).pipe(n.createWriteStream(t)).on("finish", () => {
38
- i.log("Downloading finished."), p([null, !0]);
39
- });
40
- } catch (w) {
41
- console.log("error"), p([w, null]);
42
- }
30
+ f(u).log(`Downloading video: ${o} to: ${t}`);
31
+ const e = await l("fs"), n = await l("path"), w = await l("youtubei.js");
32
+ e.existsSync(n.dirname(t)) || e.mkdirSync(n.dirname(t), { recursive: !0 }, 777);
33
+ const s = await w.create({
34
+ cache: !1,
35
+ generate_session_locally: !0
43
36
  });
44
- }, $ = async ({
37
+ try {
38
+ const p = await s.download(o, {
39
+ type: "video+audio",
40
+ quality: "best",
41
+ format: "mp4",
42
+ client: "WEB"
43
+ }), a = e.createWriteStream(t);
44
+ for await (const g of y(p))
45
+ a.write(g);
46
+ return [null, !0];
47
+ } catch (p) {
48
+ return console.log("error", p), [p, null];
49
+ }
50
+ };
51
+ async function* y(o) {
52
+ const t = o.getReader();
53
+ try {
54
+ for (; ; ) {
55
+ const { done: u, value: i } = await t.read();
56
+ if (u)
57
+ return;
58
+ yield i;
59
+ }
60
+ } finally {
61
+ t.releaseLock();
62
+ }
63
+ }
64
+ const $ = async ({
45
65
  videoId: o,
46
66
  dest: t,
47
- debug: g = !1,
67
+ debug: u = !1,
48
68
  headless: i = !0
49
69
  }) => {
50
70
  try {
51
- const e = d(g);
71
+ const e = f(u);
52
72
  e.log(`Downloading video: ${o} to: ${t}`);
53
- const n = `https://m.facebook.com/watch/?v=${o}`, l = await c("fs"), s = await c("path"), p = await c("puppeteer");
54
- l.existsSync(s.dirname(t)) || (l.mkdirSync(s.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${s.dirname(t)}`));
55
- const r = {};
56
- i || (r.headless = !1);
57
- const w = await p.launch(r);
73
+ const n = `https://m.facebook.com/watch/?v=${o}`, w = await l("fs"), s = await l("path"), p = await l("puppeteer");
74
+ w.existsSync(s.dirname(t)) || (w.mkdirSync(s.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${s.dirname(t)}`));
75
+ const a = {};
76
+ i || (a.headless = !1);
77
+ const g = await p.launch(a);
58
78
  e.log("啟動 puppeteer");
59
- const a = await w.newPage();
60
- await a.setUserAgent(
79
+ const r = await g.newPage();
80
+ await r.setUserAgent(
61
81
  "'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'"
62
- ), e.log("開新分頁"), await a.goto(n, {
63
- waitUntil: "networkidle0"
64
- }), e.log(`前往 ${n}`), await a.waitForSelector("video"), e.log("找到 video 元素");
65
- const u = await a.$eval("video", (h) => h.getAttribute("src"));
66
- return e.log(`取得 video url: ${u}`), await w.close(), e.log("關閉 puppeteer"), await m(u, t), e.log(`下載完成 ${u}`), [null, !0];
82
+ ), e.log("開新分頁"), e.log(`前往 ${n}`), await Promise.race([
83
+ r.goto(n, {
84
+ waitUntil: "networkidle0"
85
+ }),
86
+ r.waitForSelector("video")
87
+ ]), e.log("找到 video 元素");
88
+ const c = await r.$eval("video", (d) => d.getAttribute("src"));
89
+ return e.log(`取得 video url: ${c}`), await g.close(), e.log("關閉 puppeteer"), await m(c, t), e.log(`下載完成 ${c}`), [null, !0];
67
90
  } catch (e) {
68
91
  return [e, null];
69
92
  }
70
- }, y = async ({
93
+ }, v = async ({
71
94
  videoId: o,
72
95
  dest: t,
73
- debug: g = !1
96
+ debug: u = !1
74
97
  }) => {
75
- const i = d(g);
98
+ const i = f(u);
76
99
  i.log(`Downloading video: ${o} to: ${t}`);
77
- const e = await c("fs"), n = await c("path"), l = await c("axios"), s = async () => {
78
- const r = await l.get("https://vimeo.com/_next/viewer", {
100
+ const e = await l("fs"), n = await l("path"), w = await l("axios"), s = async () => {
101
+ const a = await w.get("https://vimeo.com/_next/viewer", {
79
102
  responseType: "json",
80
103
  headers: {
81
104
  "X-Requested-With": "XMLHttpRequest"
82
105
  }
83
- }), { jwt: w } = r.data;
84
- return w || "";
85
- }, p = async (r = "", w = "") => {
86
- const a = await l.get(`https://api.vimeo.com/videos/${r}?&fields=download`, {
106
+ }), { jwt: g } = a.data;
107
+ return g || "";
108
+ }, p = async (a = "", g = "") => {
109
+ const r = await w.get(`https://api.vimeo.com/videos/${a}?&fields=download`, {
87
110
  responseType: "json",
88
111
  headers: {
89
112
  "X-Requested-With": "XMLHttpRequest",
90
- Authorization: `jwt ${w}`
113
+ Authorization: `jwt ${g}`
91
114
  }
92
- }), { download: u = [] } = a.data, h = u[0] || null;
93
- return (h == null ? void 0 : h.link) || "";
115
+ }), { download: c = [] } = r.data, d = c[0] || null;
116
+ return (d == null ? void 0 : d.link) || "";
94
117
  };
95
- return e.existsSync(n.dirname(t)) || (e.mkdirSync(n.dirname(t), { recursive: !0 }, 777), i.log(`建立 ${n.dirname(t)}`)), new Promise(async (r, w) => {
118
+ return e.existsSync(n.dirname(t)) || (e.mkdirSync(n.dirname(t), { recursive: !0 }, 777), i.log(`建立 ${n.dirname(t)}`)), new Promise(async (a, g) => {
96
119
  try {
97
- const a = await s();
98
- i.log(`取得 jwt ${a}`);
99
- const u = await p(o, a);
100
- i.log(`取得 videoUrl ${u}`), await m(u, t), i.log(`下載完成 ${t}`), r([null, !0]);
101
- } catch (a) {
102
- r([a, null]);
120
+ const r = await s();
121
+ i.log(`取得 jwt ${r}`);
122
+ const c = await p(o, r);
123
+ i.log(`取得 videoUrl ${c}`), await m(c, t), i.log(`下載完成 ${t}`), a([null, !0]);
124
+ } catch (r) {
125
+ a([r, null]);
103
126
  }
104
127
  });
105
- }, v = async ({
128
+ }, k = async ({
106
129
  videoId: o,
107
130
  dest: t,
108
- debug: g = !1,
131
+ debug: u = !1,
109
132
  headless: i = !0
110
133
  }) => {
111
134
  try {
112
- const e = d(g);
135
+ const e = f(u);
113
136
  e.log(`Downloading video: ${o} to: ${t}`);
114
- const n = `https://www.instagram.com/reel/${o}/`, l = await c("fs"), s = await c("path"), p = await c("puppeteer");
115
- l.existsSync(s.dirname(t)) || (l.mkdirSync(s.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${s.dirname(t)}`));
116
- const r = {};
117
- i || (r.headless = !1);
118
- const w = await p.launch(r);
137
+ const n = `https://www.instagram.com/reel/${o}/`, w = await l("fs"), s = await l("path"), p = await l("puppeteer");
138
+ w.existsSync(s.dirname(t)) || (w.mkdirSync(s.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${s.dirname(t)}`));
139
+ const a = {};
140
+ i || (a.headless = !1);
141
+ const g = await p.launch(a);
119
142
  e.log("啟動 puppeteer");
120
- const a = await w.newPage();
121
- await a.setUserAgent(
143
+ const r = await g.newPage();
144
+ await r.setUserAgent(
122
145
  "'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'"
123
- ), e.log("開新分頁"), await a.goto(n, {
124
- // waitUntil: 'networkidle0',
125
- }), e.log(`前往 ${n}`), await a.waitForSelector("video"), e.log("找到 video 元素");
126
- const u = await a.$eval("video", (h) => h.getAttribute("src"));
127
- return e.log(`取得 video url: ${u}`), await w.close(), e.log("關閉 puppeteer"), await m(u, t), e.log(`下載完成 ${u}`), [null, !0];
146
+ ), e.log("開新分頁"), e.log(`前往 ${n}`), await Promise.race([
147
+ r.goto(n, {
148
+ waitUntil: "networkidle0"
149
+ }),
150
+ r.waitForSelector("video")
151
+ ]), e.log("找到 video 元素");
152
+ const c = await r.$eval("video", (d) => d.getAttribute("src"));
153
+ return e.log(`取得 video url: ${c}`), await g.close(), e.log("關閉 puppeteer"), await m(c, t), e.log(`下載完成 ${c}`), [null, !0];
128
154
  } catch (e) {
129
155
  return [e, null];
130
156
  }
131
- }, k = async ({
157
+ }, S = async ({
132
158
  videoLink: o,
133
159
  dest: t,
134
- debug: g = !1,
160
+ debug: u = !1,
135
161
  headless: i = !0
136
162
  }) => {
137
163
  try {
138
- const e = d(g);
164
+ const e = f(u);
139
165
  e.log(`Downloading video: ${o} to: ${t}`);
140
- const n = o, l = await c("fs"), s = await c("path"), p = await c("puppeteer");
141
- l.existsSync(s.dirname(t)) || (l.mkdirSync(s.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${s.dirname(t)}`));
142
- const r = {};
143
- i || (r.headless = !1);
144
- const w = await p.launch(r);
166
+ const n = o, w = await l("fs"), s = await l("path"), p = await l("puppeteer");
167
+ w.existsSync(s.dirname(t)) || (w.mkdirSync(s.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${s.dirname(t)}`));
168
+ const a = {};
169
+ i || (a.headless = !1);
170
+ const g = await p.launch(a);
145
171
  e.log("啟動 puppeteer");
146
- const a = await w.newPage();
147
- e.log("開新分頁"), await a.goto(n, {
148
- // waitUntil: 'networkidle0',
149
- }), e.log(`前往 ${n}`), await a.waitForSelector("video"), e.log("找到 video 元素");
150
- const u = await a.$eval(
172
+ const r = await g.newPage();
173
+ e.log("開新分頁"), e.log(`前往 ${n}`), await Promise.race([
174
+ r.goto(n, {
175
+ waitUntil: "networkidle0"
176
+ }),
177
+ r.waitForSelector("video")
178
+ ]), e.log("找到 video 元素");
179
+ const c = await r.$eval(
151
180
  'video source[src^="https://www.tiktok.com/aweme/v1/play/"]',
152
- (h) => h.getAttribute("src")
181
+ (d) => d.getAttribute("src")
153
182
  );
154
- return e.log(`取得 video url: ${u}`), await w.close(), e.log("關閉 puppeteer"), await m(u, t, {
183
+ return e.log(`取得 video url: ${c}`), await g.close(), e.log("關閉 puppeteer"), await m(c, t, {
155
184
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
156
185
  Referer: "https://www.tiktok.com/"
157
186
  // 設定 Referer
158
- }), e.log(`下載完成 ${u}`), [null, !0];
187
+ }), e.log(`下載完成 ${c}`), [null, !0];
159
188
  } catch (e) {
160
189
  return [e, null];
161
190
  }
162
- }, S = ({ type: o }) => {
191
+ }, b = ({ type: o }) => {
163
192
  switch (o) {
164
193
  case "youtube":
165
194
  case "yt-short":
166
- return f;
195
+ return h;
167
196
  case "facebook":
168
197
  case "fb-reel":
169
198
  return $;
170
199
  case "vimeo":
171
- return y;
200
+ return v;
172
201
  case "instagram":
173
202
  case "ig":
174
203
  case "ig-reel":
175
- return v;
204
+ return k;
176
205
  case "tiktok":
177
206
  case "tiktok-reel":
178
- return k;
207
+ return S;
179
208
  default:
180
209
  throw new Error(`Invalid video type: ${o}`);
181
210
  }
182
211
  };
183
212
  export {
184
- S as useDownloader,
213
+ b as useDownloader,
185
214
  $ as useFacebook,
186
- v as useInstagram,
187
- k as useTiktok,
188
- y as useVimeo,
189
- f as useYoutube
215
+ k as useInstagram,
216
+ S as useTiktok,
217
+ v as useVimeo,
218
+ h as useYoutube
190
219
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pieda/video-dl",
3
3
  "private": false,
4
- "version": "1.6.0",
4
+ "version": "1.7.0",
5
5
  "type": "module",
6
6
  "main": "dist/video-dl.cjs",
7
7
  "module": "dist/video-dl.js",
@@ -37,9 +37,9 @@
37
37
  "version:patch": "npm version patch"
38
38
  },
39
39
  "dependencies": {
40
- "@distube/ytdl-core": "^4.16.8",
41
- "axios": "^1.7.2",
42
- "puppeteer": "^22.13.1"
40
+ "axios": "^1.10.0",
41
+ "puppeteer": "^22.13.1",
42
+ "youtubei.js": "^14.0.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "fs": "^0.0.1-security",
@@ -49,8 +49,8 @@
49
49
  "vue-tsc": "^1.4.2"
50
50
  },
51
51
  "peerDependencies": {
52
- "@distube/ytdl-core": "^4.16.8",
53
- "axios": "^1.7.2",
54
- "puppeteer": "^22.13.1"
52
+ "axios": "^1.10.0",
53
+ "puppeteer": "^22.13.1",
54
+ "youtubei.js": "^14.0.0"
55
55
  }
56
56
  }