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