@pieda/video-dl 1.5.1 → 1.5.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.
@@ -2,6 +2,7 @@ type TUseFacebook = {
2
2
  videoId: string;
3
3
  dest: string;
4
4
  debug?: boolean;
5
+ headless?: boolean;
5
6
  };
6
- export declare const useFacebook: ({ videoId, dest, debug, }: TUseFacebook) => Promise<[Error | null, boolean | null]>;
7
+ export declare const useFacebook: ({ videoId, dest, debug, headless, }: TUseFacebook) => Promise<[Error | null, boolean | null]>;
7
8
  export {};
@@ -2,6 +2,7 @@ type TUseInstagram = {
2
2
  videoId: string;
3
3
  dest: string;
4
4
  debug?: boolean;
5
+ headless?: boolean;
5
6
  };
6
- export declare const useInstagram: ({ videoId, dest, debug, }: TUseInstagram) => Promise<[Error | null, boolean | null]>;
7
+ export declare const useInstagram: ({ videoId, dest, debug, headless, }: TUseInstagram) => Promise<[Error | null, boolean | null]>;
7
8
  export {};
@@ -2,6 +2,7 @@ type TUseTiktok = {
2
2
  videoLink: string;
3
3
  dest: string;
4
4
  debug?: boolean;
5
+ headless?: boolean;
5
6
  };
6
- export declare const useTiktok: ({ videoLink, dest, debug, }: TUseTiktok) => Promise<[Error | null, boolean | null]>;
7
+ export declare const useTiktok: ({ videoLink, dest, debug, headless, }: TUseTiktok) => Promise<[Error | null, boolean | null]>;
7
8
  export {};
package/dist/video-dl.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=o=>new Promise((t,w)=>{import(o).then(e=>t(e.default)).catch(w)}),d=async(o,t,w)=>{const e=await s("fs"),l=await s("axios");return console.log(`Downloading ${o} to ${t}`),new Promise((n,r)=>{l.get(o,{responseType:"stream",headers:w}).then(g=>{const c=g.data,a=e.createWriteStream(t);c.pipe(a),a.on("finish",function(){a.close(()=>{n()})})}).catch(r)})},p=(o=!1)=>({log:(...t)=>{o&&console.log(...t)},error:(...t)=>{o&&console.error(...t)}}),f=async({videoId:o,dest:t,debug:w=!1})=>{const e=p(w);e.log(`Downloading video: ${o} to: ${t}`);const l=`https://www.youtube.com/watch?v=${o}`,n=await s("fs"),r=await s("path"),g=await s("@distube/ytdl-core");return n.existsSync(r.dirname(t))||n.mkdirSync(r.dirname(t),{recursive:!0},777),new Promise((c,a)=>{try{g(l).on("error",u=>{e.error(u),c([u,null])}).pipe(n.createWriteStream(t)).on("finish",()=>{e.log("Downloading finished."),c([null,!0])})}catch(i){console.log("error"),c([i,null])}})},$=async({videoId:o,dest:t,debug:w=!1})=>{try{const e=p(w);e.log(`Downloading video: ${o} to: ${t}`);const l=`https://m.facebook.com/watch/?v=${o}`,n=await s("fs"),r=await s("path"),g=await s("puppeteer");n.existsSync(r.dirname(t))||(n.mkdirSync(r.dirname(t),{recursive:!0},777),e.log(`建立 ${r.dirname(t)}`));const c=await g.launch();e.log("啟動 puppeteer");const a=await c.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(l,{waitUntil:"networkidle0"}),e.log(`前往 ${l}`),await a.waitForSelector("video"),e.log("找到 video 元素");const i=await a.$eval("video",u=>u.getAttribute("src"));return e.log(`取得 video url: ${i}`),await c.close(),e.log("關閉 puppeteer"),await d(i,t),e.log(`下載完成 ${i}`),[null,!0]}catch(e){return[e,null]}},y=async({videoId:o,dest:t,debug:w=!1})=>{const e=p(w);e.log(`Downloading video: ${o} to: ${t}`);const l=await s("fs"),n=await s("path"),r=await s("axios"),g=async()=>{const a=await r.get("https://vimeo.com/_next/viewer",{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest"}}),{jwt:i}=a.data;return i||""},c=async(a="",i="")=>{const u=await r.get(`https://api.vimeo.com/videos/${a}?&fields=download`,{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest",Authorization:`jwt ${i}`}}),{download:m=[]}=u.data,h=m[0]||null;return(h==null?void 0:h.link)||""};return l.existsSync(n.dirname(t))||(l.mkdirSync(n.dirname(t),{recursive:!0},777),e.log(`建立 ${n.dirname(t)}`)),new Promise(async(a,i)=>{try{const u=await g();e.log(`取得 jwt ${u}`);const m=await c(o,u);e.log(`取得 videoUrl ${m}`),await d(m,t),e.log(`下載完成 ${t}`),a([null,!0])}catch(u){a([u,null])}})},v=async({videoId:o,dest:t,debug:w=!1})=>{try{const e=p(w);e.log(`Downloading video: ${o} to: ${t}`);const l=`https://www.instagram.com/share/${o}/`,n=await s("fs"),r=await s("path"),g=await s("puppeteer");n.existsSync(r.dirname(t))||(n.mkdirSync(r.dirname(t),{recursive:!0},777),e.log(`建立 ${r.dirname(t)}`));const c=await g.launch();e.log("啟動 puppeteer");const a=await c.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(l,{}),e.log(`前往 ${l}`),await a.waitForSelector("video"),e.log("找到 video 元素");const i=await a.$eval("video",u=>u.getAttribute("src"));return e.log(`取得 video url: ${i}`),await c.close(),e.log("關閉 puppeteer"),await d(i,t),e.log(`下載完成 ${i}`),[null,!0]}catch(e){return[e,null]}},k=async({videoLink:o,dest:t,debug:w=!1})=>{try{const e=p(w);e.log(`Downloading video: ${o} to: ${t}`);const l=o,n=await s("fs"),r=await s("path"),g=await s("puppeteer");n.existsSync(r.dirname(t))||(n.mkdirSync(r.dirname(t),{recursive:!0},777),e.log(`建立 ${r.dirname(t)}`));const c=await g.launch();e.log("啟動 puppeteer");const a=await c.newPage();e.log("開新分頁"),await a.goto(l,{}),e.log(`前往 ${l}`),await a.waitForSelector("video"),e.log("找到 video 元素");const i=await a.$eval('video source[src^="https://www.tiktok.com/aweme/v1/play/"]',u=>u.getAttribute("src"));return e.log(`取得 video url: ${i}`),await c.close(),e.log("關閉 puppeteer"),await d(i,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(`下載完成 ${i}`),[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 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;
package/dist/video-dl.js CHANGED
@@ -1,21 +1,21 @@
1
- const s = (o) => new Promise((t, u) => {
2
- import(o).then((e) => t(e.default)).catch(u);
3
- }), m = async (o, t, u) => {
4
- const e = await s("fs"), l = await s("axios");
5
- return console.log(`Downloading ${o} to ${t}`), new Promise((n, r) => {
6
- l.get(o, {
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) => {
6
+ e.get(o, {
7
7
  responseType: "stream",
8
- headers: u
9
- }).then((g) => {
10
- const c = g.data, a = e.createWriteStream(t);
11
- c.pipe(a), a.on("finish", function() {
12
- a.close(() => {
8
+ headers: g
9
+ }).then((s) => {
10
+ const p = s.data, r = i.createWriteStream(t);
11
+ p.pipe(r), r.on("finish", function() {
12
+ r.close(() => {
13
13
  n();
14
14
  });
15
15
  });
16
- }).catch(r);
16
+ }).catch(l);
17
17
  });
18
- }, p = (o = !1) => ({
18
+ }, d = (o = !1) => ({
19
19
  log: (...t) => {
20
20
  o && console.log(...t);
21
21
  },
@@ -25,128 +25,137 @@ const s = (o) => new Promise((t, u) => {
25
25
  }), f = async ({
26
26
  videoId: o,
27
27
  dest: t,
28
- debug: u = !1
28
+ debug: g = !1
29
29
  }) => {
30
- const e = p(u);
31
- e.log(`Downloading video: ${o} to: ${t}`);
32
- const l = `https://www.youtube.com/watch?v=${o}`, n = await s("fs"), r = await s("path"), g = await s("@distube/ytdl-core");
33
- return n.existsSync(r.dirname(t)) || n.mkdirSync(r.dirname(t), { recursive: !0 }, 777), new Promise((c, a) => {
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
34
  try {
35
- g(l).on("error", (w) => {
36
- e.error(w), c([w, null]);
35
+ s(e).on("error", (a) => {
36
+ i.error(a), p([a, null]);
37
37
  }).pipe(n.createWriteStream(t)).on("finish", () => {
38
- e.log("Downloading finished."), c([null, !0]);
38
+ i.log("Downloading finished."), p([null, !0]);
39
39
  });
40
- } catch (i) {
41
- console.log("error"), c([i, null]);
40
+ } catch (w) {
41
+ console.log("error"), p([w, null]);
42
42
  }
43
43
  });
44
44
  }, $ = async ({
45
45
  videoId: o,
46
46
  dest: t,
47
- debug: u = !1
47
+ debug: g = !1,
48
+ headless: i = !0
48
49
  }) => {
49
50
  try {
50
- const e = p(u);
51
+ const e = d(g);
51
52
  e.log(`Downloading video: ${o} to: ${t}`);
52
- const l = `https://m.facebook.com/watch/?v=${o}`, n = await s("fs"), r = await s("path"), g = await s("puppeteer");
53
- n.existsSync(r.dirname(t)) || (n.mkdirSync(r.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${r.dirname(t)}`));
54
- const c = await g.launch();
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);
55
58
  e.log("啟動 puppeteer");
56
- const a = await c.newPage();
59
+ const a = await w.newPage();
57
60
  await a.setUserAgent(
58
61
  "'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'"
59
- ), e.log("開新分頁"), await a.goto(l, {
62
+ ), e.log("開新分頁"), await a.goto(n, {
60
63
  waitUntil: "networkidle0"
61
- }), e.log(`前往 ${l}`), await a.waitForSelector("video"), e.log("找到 video 元素");
62
- const i = await a.$eval("video", (w) => w.getAttribute("src"));
63
- return e.log(`取得 video url: ${i}`), await c.close(), e.log("關閉 puppeteer"), await m(i, t), e.log(`下載完成 ${i}`), [null, !0];
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];
64
67
  } catch (e) {
65
68
  return [e, null];
66
69
  }
67
70
  }, y = async ({
68
71
  videoId: o,
69
72
  dest: t,
70
- debug: u = !1
73
+ debug: g = !1
71
74
  }) => {
72
- const e = p(u);
73
- e.log(`Downloading video: ${o} to: ${t}`);
74
- const l = await s("fs"), n = await s("path"), r = await s("axios"), g = async () => {
75
- const a = await r.get("https://vimeo.com/_next/viewer", {
75
+ const i = d(g);
76
+ 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", {
76
79
  responseType: "json",
77
80
  headers: {
78
81
  "X-Requested-With": "XMLHttpRequest"
79
82
  }
80
- }), { jwt: i } = a.data;
81
- return i || "";
82
- }, c = async (a = "", i = "") => {
83
- const w = await r.get(`https://api.vimeo.com/videos/${a}?&fields=download`, {
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`, {
84
87
  responseType: "json",
85
88
  headers: {
86
89
  "X-Requested-With": "XMLHttpRequest",
87
- Authorization: `jwt ${i}`
90
+ Authorization: `jwt ${w}`
88
91
  }
89
- }), { download: h = [] } = w.data, d = h[0] || null;
90
- return (d == null ? void 0 : d.link) || "";
92
+ }), { download: u = [] } = a.data, h = u[0] || null;
93
+ return (h == null ? void 0 : h.link) || "";
91
94
  };
92
- return l.existsSync(n.dirname(t)) || (l.mkdirSync(n.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${n.dirname(t)}`)), new Promise(async (a, i) => {
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) => {
93
96
  try {
94
- const w = await g();
95
- e.log(`取得 jwt ${w}`);
96
- const h = await c(o, w);
97
- e.log(`取得 videoUrl ${h}`), await m(h, t), e.log(`下載完成 ${t}`), a([null, !0]);
98
- } catch (w) {
99
- a([w, null]);
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]);
100
103
  }
101
104
  });
102
105
  }, v = async ({
103
106
  videoId: o,
104
107
  dest: t,
105
- debug: u = !1
108
+ debug: g = !1,
109
+ headless: i = !0
106
110
  }) => {
107
111
  try {
108
- const e = p(u);
112
+ const e = d(g);
109
113
  e.log(`Downloading video: ${o} to: ${t}`);
110
- const l = `https://www.instagram.com/share/${o}/`, n = await s("fs"), r = await s("path"), g = await s("puppeteer");
111
- n.existsSync(r.dirname(t)) || (n.mkdirSync(r.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${r.dirname(t)}`));
112
- const c = await g.launch();
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);
113
119
  e.log("啟動 puppeteer");
114
- const a = await c.newPage();
120
+ const a = await w.newPage();
115
121
  await a.setUserAgent(
116
122
  "'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'"
117
- ), e.log("開新分頁"), await a.goto(l, {
123
+ ), e.log("開新分頁"), await a.goto(n, {
118
124
  // waitUntil: 'networkidle0',
119
- }), e.log(`前往 ${l}`), await a.waitForSelector("video"), e.log("找到 video 元素");
120
- const i = await a.$eval("video", (w) => w.getAttribute("src"));
121
- return e.log(`取得 video url: ${i}`), await c.close(), e.log("關閉 puppeteer"), await m(i, t), e.log(`下載完成 ${i}`), [null, !0];
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];
122
128
  } catch (e) {
123
129
  return [e, null];
124
130
  }
125
131
  }, k = async ({
126
132
  videoLink: o,
127
133
  dest: t,
128
- debug: u = !1
134
+ debug: g = !1,
135
+ headless: i = !0
129
136
  }) => {
130
137
  try {
131
- const e = p(u);
138
+ const e = d(g);
132
139
  e.log(`Downloading video: ${o} to: ${t}`);
133
- const l = o, n = await s("fs"), r = await s("path"), g = await s("puppeteer");
134
- n.existsSync(r.dirname(t)) || (n.mkdirSync(r.dirname(t), { recursive: !0 }, 777), e.log(`建立 ${r.dirname(t)}`));
135
- const c = await g.launch();
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);
136
145
  e.log("啟動 puppeteer");
137
- const a = await c.newPage();
138
- e.log("開新分頁"), await a.goto(l, {
146
+ const a = await w.newPage();
147
+ e.log("開新分頁"), await a.goto(n, {
139
148
  // waitUntil: 'networkidle0',
140
- }), e.log(`前往 ${l}`), await a.waitForSelector("video"), e.log("找到 video 元素");
141
- const i = await a.$eval(
149
+ }), e.log(`前往 ${n}`), await a.waitForSelector("video"), e.log("找到 video 元素");
150
+ const u = await a.$eval(
142
151
  'video source[src^="https://www.tiktok.com/aweme/v1/play/"]',
143
- (w) => w.getAttribute("src")
152
+ (h) => h.getAttribute("src")
144
153
  );
145
- return e.log(`取得 video url: ${i}`), await c.close(), e.log("關閉 puppeteer"), await m(i, t, {
154
+ return e.log(`取得 video url: ${u}`), await w.close(), e.log("關閉 puppeteer"), await m(u, t, {
146
155
  "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",
147
156
  Referer: "https://www.tiktok.com/"
148
157
  // 設定 Referer
149
- }), e.log(`下載完成 ${i}`), [null, !0];
158
+ }), e.log(`下載完成 ${u}`), [null, !0];
150
159
  } catch (e) {
151
160
  return [e, null];
152
161
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pieda/video-dl",
3
3
  "private": false,
4
- "version": "1.5.1",
4
+ "version": "1.5.2",
5
5
  "type": "module",
6
6
  "main": "dist/video-dl.cjs",
7
7
  "module": "dist/video-dl.js",