@pieda/video-dl 1.10.0 → 1.10.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.
package/dist/video-dl.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=(e=!1)=>({log:(...o)=>{e&&console.log(...o)},error:(...o)=>{e&&console.error(...o)}}),s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));function j(e,o=0){return(s[e[o+0]]+s[e[o+1]]+s[e[o+2]]+s[e[o+3]]+"-"+s[e[o+4]]+s[e[o+5]]+"-"+s[e[o+6]]+s[e[o+7]]+"-"+s[e[o+8]]+s[e[o+9]]+"-"+s[e[o+10]]+s[e[o+11]]+s[e[o+12]]+s[e[o+13]]+s[e[o+14]]+s[e[o+15]]).toLowerCase()}let k;const I=new Uint8Array(16);function W(){if(!k){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");k=crypto.getRandomValues.bind(crypto)}return k(I)}const _=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),D={randomUUID:_};function K(e,o,n){var t;e=e||{};const r=e.random??((t=e.rng)==null?void 0:t.call(e))??W();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,o){if(n=n||0,n<0||n+16>o.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let a=0;a<16;++a)o[n+a]=r[a];return o}return j(r)}function C(e,o,n){return D.randomUUID&&!o&&!e?D.randomUUID():K(e,o,n)}const w=e=>new Promise((o,n)=>{import(e).then(r=>o(r.default)).catch(n)}),x=async(e,o,n)=>{const r=await w("fs"),t=await w("axios");return console.log(`Downloading ${e} to ${o}`),new Promise((a,c)=>{t.get(e,{responseType:"stream",headers:n}).then(i=>{const u=i.data,g=r.createWriteStream(o);u.pipe(g),g.on("finish",function(){g.close(()=>{a()})})}).catch(c)})},U=async({debug:e=!1,ytdlpPath:o,videoUrl:n,dest:r,tempDir:t,ffmpegConfig:a})=>{const c=y(e);c.log(`Downloading video: ${n} to: ${r}`);const i=await w("fs"),u=await w("path"),{exec:g,execSync:h}=await w("child_process"),l=u.join(t,C()),d=()=>new Promise((p,S)=>{const m=`${o} -f mergeall --audio-multistreams --video-multistreams ${n} --downloader ffmpeg -o "${l}/%(id)s.%(ext)s" --merge-output-format mp4`;c.log(`[yt-dlp] 執行命令: ${m}`),g(m,($,v,f)=>{if(c.log(`[yt-dlp] stdout: ${v}`),$){S($);return}p()})});return i.existsSync(u.dirname(r))||(i.mkdirSync(u.dirname(r),{recursive:!0},777),c.log(`建立 ${u.dirname(r)}`)),new Promise(async(p,S)=>{try{await d();let m=!1;const $=i.readdirSync(l);for(const v of $){const f=u.join(l,v),V=`${a.ffmpegProbePath} -v error -show_entries stream=codec_type -of csv=p=0 "${f}"`,b=h(V).toString("utf-8"),R=b.includes("video"),E=b.includes("audio");if(R&&E){m=!0,i.copyFileSync(f,r);break}}if(!m)throw new Error("無法下載影音正常的影片");c.log(`下載完成 ${r}`),p([null,!0])}catch(m){c.error(`下載失敗: ${m.message}`),p([m,null])}})},P=async({debug:e=!1,ytdlpPath:o,videoId:n,dest:r,tempDir:t,ffmpegConfig:a})=>{y(e).log(`Downloading video: ${n} to: ${r}`);const i=`https://www.youtube.com/watch?v=${n}`;return U({debug:e,ytdlpPath:o,videoUrl:i,dest:r,tempDir:t,ffmpegConfig:a})},A=async({videoId:e,dest:o,debug:n=!1,headless:r=!0})=>{try{const t=y(n);t.log(`Downloading video: ${e} to: ${o}`);const a=`https://m.facebook.com/watch/?v=${e}`,c=await w("fs"),i=await w("path"),u=await w("puppeteer");c.existsSync(i.dirname(o))||(c.mkdirSync(i.dirname(o),{recursive:!0},777),t.log(`建立 ${i.dirname(o)}`));const g={};r||(g.headless=!1);const h=await u.launch(g);t.log("啟動 puppeteer");const l=await h.newPage();await l.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("開新分頁"),t.log(`前往 ${a}`),await Promise.race([l.goto(a,{waitUntil:"networkidle0"}),l.waitForSelector("video")]),t.log("找到 video 元素");const d=await l.$eval("video",p=>p.getAttribute("src"));return t.log(`取得 video url: ${d}`),await h.close(),t.log("關閉 puppeteer"),await x(d,o),t.log(`下載完成 ${d}`),[null,!0]}catch(t){return[t,null]}},F=async({debug:e=!1,ytdlpPath:o,videoId:n,dest:r,tempDir:t,ffmpegConfig:a})=>{y(e).log(`Downloading video: ${n} to: ${r}`);const i=`https://vimeo.com/${n}`;return U({debug:e,ytdlpPath:o,videoUrl:i,dest:r,tempDir:t,ffmpegConfig:a})},M=async({debug:e=!1,ytdlpPath:o,videoId:n,dest:r,tempDir:t,ffmpegConfig:a})=>{y(e).log(`Downloading video: ${n} to: ${r}`);const i=`https://www.instagram.com/reel/${n}/`;return U({debug:e,ytdlpPath:o,videoUrl:i,dest:r,tempDir:t,ffmpegConfig:a})},T=async({videoLink:e,dest:o,debug:n=!1,headless:r=!0})=>{try{const t=y(n);t.log(`Downloading video: ${e} to: ${o}`);const a=e,c=await w("fs"),i=await w("path"),u=await w("puppeteer");c.existsSync(i.dirname(o))||(c.mkdirSync(i.dirname(o),{recursive:!0},777),t.log(`建立 ${i.dirname(o)}`));const g={};r||(g.headless=!1);const h=await u.launch(g);t.log("啟動 puppeteer");const l=await h.newPage();t.log("開新分頁"),t.log(`前往 ${a}`),await Promise.race([l.goto(a,{waitUntil:"networkidle0"}),l.waitForSelector("video")]),t.log("找到 video 元素");const d=await l.$eval('video source[src^="https://www.tiktok.com/aweme/v1/play/"]',p=>p.getAttribute("src"));return t.log(`取得 video url: ${d}`),await h.close(),t.log("關閉 puppeteer"),await x(d,o,{"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/"}),t.log(`下載完成 ${d}`),[null,!0]}catch(t){return[t,null]}},H=({type:e})=>{switch(e){case"youtube":case"yt-short":return P;case"facebook":case"fb-reel":return A;case"vimeo":return F;case"instagram":case"ig":case"ig-reel":return M;case"tiktok":case"tiktok-reel":return T;default:throw new Error(`Invalid video type: ${e}`)}};exports.useDownloader=H;exports.useFacebook=A;exports.useInstagram=M;exports.useTiktok=T;exports.useVimeo=F;exports.useYoutube=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=(e=!1)=>({log:(...o)=>{e&&console.log(...o)},error:(...o)=>{e&&console.error(...o)}});var s=[];for(var S=0;S<256;++S)s.push((S+256).toString(16).slice(1));function E(e,o=0){return(s[e[o+0]]+s[e[o+1]]+s[e[o+2]]+s[e[o+3]]+"-"+s[e[o+4]]+s[e[o+5]]+"-"+s[e[o+6]]+s[e[o+7]]+"-"+s[e[o+8]]+s[e[o+9]]+"-"+s[e[o+10]]+s[e[o+11]]+s[e[o+12]]+s[e[o+13]]+s[e[o+14]]+s[e[o+15]]).toLowerCase()}var $,I=new Uint8Array(16);function K(){if(!$&&($=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!$))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return $(I)}var _=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const D={randomUUID:_};function C(e,o,n){if(D.randomUUID&&!o&&!e)return D.randomUUID();e=e||{};var r=e.random||(e.rng||K)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,o){n=n||0;for(var t=0;t<16;++t)o[n+t]=r[t];return o}return E(r)}const w=e=>new Promise((o,n)=>{import(e).then(r=>o(r.default)).catch(n)}),P=async(e,o,n)=>{const r=await w("fs"),t=await w("axios");return console.log(`Downloading ${e} to ${o}`),new Promise((c,i)=>{t.get(e,{responseType:"stream",headers:n}).then(a=>{const u=a.data,g=r.createWriteStream(o);u.pipe(g),g.on("finish",function(){g.close(()=>{c()})})}).catch(i)})},U=async({debug:e=!1,ytdlpPath:o,videoUrl:n,dest:r,tempDir:t,ffmpegConfig:c})=>{const i=h(e);i.log(`Downloading video: ${n} to: ${r}`);const a=await w("fs"),u=await w("path"),{exec:g,execSync:y}=await w("child_process"),l=u.join(t,C()),p=()=>new Promise((d,b)=>{const m=`${o} -f mergeall --audio-multistreams --video-multistreams ${n} --downloader ffmpeg -o "${l}/%(id)s.%(ext)s" --merge-output-format mp4`;i.log(`[yt-dlp] 執行命令: ${m}`),g(m,(v,f,k)=>{if(i.log(`[yt-dlp] stdout: ${f}`),v){b(v);return}d()})});return a.existsSync(u.dirname(r))||(a.mkdirSync(u.dirname(r),{recursive:!0},777),i.log(`建立 ${u.dirname(r)}`)),new Promise(async(d,b)=>{try{await p();let m=!1;const v=a.readdirSync(l);for(const f of v){const k=u.join(l,f),j=`${c.ffmpegProbePath} -v error -show_entries stream=codec_type -of csv=p=0 "${k}"`,x=y(j).toString("utf-8"),R=x.includes("video"),W=x.includes("audio");if(R&&W){m=!0,a.copyFileSync(k,r);break}}if(!m)throw new Error("無法下載影音正常的影片");i.log(`下載完成 ${r}`),d([null,!0])}catch(m){i.error(`下載失敗: ${m.message}`),d([m,null])}})},A=async({debug:e=!1,ytdlpPath:o,videoId:n,dest:r,tempDir:t,ffmpegConfig:c})=>{h(e).log(`Downloading video: ${n} to: ${r}`);const a=`https://www.youtube.com/watch?v=${n}`;return U({debug:e,ytdlpPath:o,videoUrl:a,dest:r,tempDir:t,ffmpegConfig:c})},F=async({videoId:e,dest:o,debug:n=!1,headless:r=!0})=>{try{const t=h(n);t.log(`Downloading video: ${e} to: ${o}`);const c=`https://m.facebook.com/watch/?v=${e}`,i=await w("fs"),a=await w("path"),u=await w("puppeteer");i.existsSync(a.dirname(o))||(i.mkdirSync(a.dirname(o),{recursive:!0},777),t.log(`建立 ${a.dirname(o)}`));const g={};r||(g.headless=!1);const y=await u.launch(g);t.log("啟動 puppeteer");const l=await y.newPage();await l.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("開新分頁"),t.log(`前往 ${c}`),await Promise.race([l.goto(c,{waitUntil:"networkidle0"}),l.waitForSelector("video")]),t.log("找到 video 元素");const p=await l.$eval("video",d=>d.getAttribute("src"));return t.log(`取得 video url: ${p}`),await y.close(),t.log("關閉 puppeteer"),await P(p,o),t.log(`下載完成 ${p}`),[null,!0]}catch(t){return[t,null]}},M=async({debug:e=!1,ytdlpPath:o,videoId:n,dest:r,tempDir:t,ffmpegConfig:c})=>{h(e).log(`Downloading video: ${n} to: ${r}`);const a=`https://vimeo.com/${n}`;return U({debug:e,ytdlpPath:o,videoUrl:a,dest:r,tempDir:t,ffmpegConfig:c})},T=async({debug:e=!1,ytdlpPath:o,videoId:n,dest:r,tempDir:t,ffmpegConfig:c})=>{h(e).log(`Downloading video: ${n} to: ${r}`);const a=`https://www.instagram.com/reel/${n}/`;return U({debug:e,ytdlpPath:o,videoUrl:a,dest:r,tempDir:t,ffmpegConfig:c})},V=async({videoLink:e,dest:o,debug:n=!1,headless:r=!0})=>{try{const t=h(n);t.log(`Downloading video: ${e} to: ${o}`);const c=e,i=await w("fs"),a=await w("path"),u=await w("puppeteer");i.existsSync(a.dirname(o))||(i.mkdirSync(a.dirname(o),{recursive:!0},777),t.log(`建立 ${a.dirname(o)}`));const g={};r||(g.headless=!1);const y=await u.launch(g);t.log("啟動 puppeteer");const l=await y.newPage();t.log("開新分頁"),t.log(`前往 ${c}`),await Promise.race([l.goto(c,{waitUntil:"networkidle0"}),l.waitForSelector("video")]),t.log("找到 video 元素");const p=await l.$eval('video source[src^="https://www.tiktok.com/aweme/v1/play/"]',d=>d.getAttribute("src"));return t.log(`取得 video url: ${p}`),await y.close(),t.log("關閉 puppeteer"),await P(p,o,{"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/"}),t.log(`下載完成 ${p}`),[null,!0]}catch(t){return[t,null]}},H=({type:e})=>{switch(e){case"youtube":case"yt-short":return A;case"facebook":case"fb-reel":return F;case"vimeo":return M;case"instagram":case"ig":case"ig-reel":return T;case"tiktok":case"tiktok-reel":return V;default:throw new Error(`Invalid video type: ${e}`)}};exports.useDownloader=H;exports.useFacebook=F;exports.useInstagram=T;exports.useTiktok=V;exports.useVimeo=M;exports.useYoutube=A;
package/dist/video-dl.js CHANGED
@@ -1,244 +1,239 @@
1
- const y = (e = !1) => ({
1
+ const h = (e = !1) => ({
2
2
  log: (...o) => {
3
3
  e && console.log(...o);
4
4
  },
5
5
  error: (...o) => {
6
6
  e && console.error(...o);
7
7
  }
8
- }), s = [];
9
- for (let e = 0; e < 256; ++e)
10
- s.push((e + 256).toString(16).slice(1));
11
- function M(e, o = 0) {
12
- return (s[e[o + 0]] + s[e[o + 1]] + s[e[o + 2]] + s[e[o + 3]] + "-" + s[e[o + 4]] + s[e[o + 5]] + "-" + s[e[o + 6]] + s[e[o + 7]] + "-" + s[e[o + 8]] + s[e[o + 9]] + "-" + s[e[o + 10]] + s[e[o + 11]] + s[e[o + 12]] + s[e[o + 13]] + s[e[o + 14]] + s[e[o + 15]]).toLowerCase();
8
+ });
9
+ var c = [];
10
+ for (var U = 0; U < 256; ++U)
11
+ c.push((U + 256).toString(16).slice(1));
12
+ function V(e, o = 0) {
13
+ return (c[e[o + 0]] + c[e[o + 1]] + c[e[o + 2]] + c[e[o + 3]] + "-" + c[e[o + 4]] + c[e[o + 5]] + "-" + c[e[o + 6]] + c[e[o + 7]] + "-" + c[e[o + 8]] + c[e[o + 9]] + "-" + c[e[o + 10]] + c[e[o + 11]] + c[e[o + 12]] + c[e[o + 13]] + c[e[o + 14]] + c[e[o + 15]]).toLowerCase();
13
14
  }
14
- let k;
15
- const R = new Uint8Array(16);
16
- function V() {
17
- if (!k) {
18
- if (typeof crypto > "u" || !crypto.getRandomValues)
19
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
20
- k = crypto.getRandomValues.bind(crypto);
21
- }
22
- return k(R);
15
+ var v, T = new Uint8Array(16);
16
+ function R() {
17
+ if (!v && (v = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
18
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
19
+ return v(T);
23
20
  }
24
- const E = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), x = { randomUUID: E };
25
- function T(e, o, r) {
26
- var t;
21
+ var W = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
22
+ const P = {
23
+ randomUUID: W
24
+ };
25
+ function j(e, o, n) {
26
+ if (P.randomUUID && !o && !e)
27
+ return P.randomUUID();
27
28
  e = e || {};
28
- const n = e.random ?? ((t = e.rng) == null ? void 0 : t.call(e)) ?? V();
29
- if (n.length < 16)
30
- throw new Error("Random bytes length must be >= 16");
31
- if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, o) {
32
- if (r = r || 0, r < 0 || r + 16 > o.length)
33
- throw new RangeError(`UUID byte range ${r}:${r + 15} is out of buffer bounds`);
34
- for (let a = 0; a < 16; ++a)
35
- o[r + a] = n[a];
29
+ var r = e.random || (e.rng || R)();
30
+ if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, o) {
31
+ n = n || 0;
32
+ for (var t = 0; t < 16; ++t)
33
+ o[n + t] = r[t];
36
34
  return o;
37
35
  }
38
- return M(n);
36
+ return V(r);
39
37
  }
40
- function W(e, o, r) {
41
- return x.randomUUID && !o && !e ? x.randomUUID() : T(e, o, r);
42
- }
43
- const w = (e) => new Promise((o, r) => {
44
- import(e).then((n) => o(n.default)).catch(r);
45
- }), D = async (e, o, r) => {
46
- const n = await w("fs"), t = await w("axios");
47
- return console.log(`Downloading ${e} to ${o}`), new Promise((a, c) => {
38
+ const w = (e) => new Promise((o, n) => {
39
+ import(e).then((r) => o(r.default)).catch(n);
40
+ }), b = async (e, o, n) => {
41
+ const r = await w("fs"), t = await w("axios");
42
+ return console.log(`Downloading ${e} to ${o}`), new Promise((s, i) => {
48
43
  t.get(e, {
49
44
  responseType: "stream",
50
- headers: r
51
- }).then((i) => {
52
- const u = i.data, g = n.createWriteStream(o);
45
+ headers: n
46
+ }).then((a) => {
47
+ const u = a.data, g = r.createWriteStream(o);
53
48
  u.pipe(g), g.on("finish", function() {
54
49
  g.close(() => {
55
- a();
50
+ s();
56
51
  });
57
52
  });
58
- }).catch(c);
53
+ }).catch(i);
59
54
  });
60
- }, U = async ({
55
+ }, S = async ({
61
56
  debug: e = !1,
62
57
  ytdlpPath: o,
63
- videoUrl: r,
64
- dest: n,
58
+ videoUrl: n,
59
+ dest: r,
65
60
  tempDir: t,
66
- ffmpegConfig: a
61
+ ffmpegConfig: s
67
62
  }) => {
68
- const c = y(e);
69
- c.log(`Downloading video: ${r} to: ${n}`);
70
- const i = await w("fs"), u = await w("path"), { exec: g, execSync: h } = await w("child_process"), l = u.join(t, W()), d = () => new Promise((p, S) => {
71
- const m = `${o} -f mergeall --audio-multistreams --video-multistreams ${r} --downloader ffmpeg -o "${l}/%(id)s.%(ext)s" --merge-output-format mp4`;
72
- c.log(`[yt-dlp] 執行命令: ${m}`), g(m, ($, v, f) => {
73
- if (c.log(`[yt-dlp] stdout: ${v}`), $) {
74
- S($);
63
+ const i = h(e);
64
+ i.log(`Downloading video: ${n} to: ${r}`);
65
+ const a = await w("fs"), u = await w("path"), { exec: g, execSync: y } = await w("child_process"), l = u.join(t, j()), p = () => new Promise((d, x) => {
66
+ const m = `${o} -f mergeall --audio-multistreams --video-multistreams ${n} --downloader ffmpeg -o "${l}/%(id)s.%(ext)s" --merge-output-format mp4`;
67
+ i.log(`[yt-dlp] 執行命令: ${m}`), g(m, ($, f, k) => {
68
+ if (i.log(`[yt-dlp] stdout: ${f}`), $) {
69
+ x($);
75
70
  return;
76
71
  }
77
- p();
72
+ d();
78
73
  });
79
74
  });
80
- return i.existsSync(u.dirname(n)) || (i.mkdirSync(u.dirname(n), { recursive: !0 }, 777), c.log(`建立 ${u.dirname(n)}`)), new Promise(async (p, S) => {
75
+ return a.existsSync(u.dirname(r)) || (a.mkdirSync(u.dirname(r), { recursive: !0 }, 777), i.log(`建立 ${u.dirname(r)}`)), new Promise(async (d, x) => {
81
76
  try {
82
- await d();
77
+ await p();
83
78
  let m = !1;
84
- const $ = i.readdirSync(l);
85
- for (const v of $) {
86
- const f = u.join(l, v), P = `${a.ffmpegProbePath} -v error -show_entries stream=codec_type -of csv=p=0 "${f}"`, b = h(P).toString("utf-8"), A = b.includes("video"), F = b.includes("audio");
87
- if (A && F) {
88
- m = !0, i.copyFileSync(f, n);
79
+ const $ = a.readdirSync(l);
80
+ for (const f of $) {
81
+ const k = u.join(l, f), A = `${s.ffmpegProbePath} -v error -show_entries stream=codec_type -of csv=p=0 "${k}"`, D = y(A).toString("utf-8"), F = D.includes("video"), M = D.includes("audio");
82
+ if (F && M) {
83
+ m = !0, a.copyFileSync(k, r);
89
84
  break;
90
85
  }
91
86
  }
92
87
  if (!m)
93
88
  throw new Error("無法下載影音正常的影片");
94
- c.log(`下載完成 ${n}`), p([null, !0]);
89
+ i.log(`下載完成 ${r}`), d([null, !0]);
95
90
  } catch (m) {
96
- c.error(`下載失敗: ${m.message}`), p([m, null]);
91
+ i.error(`下載失敗: ${m.message}`), d([m, null]);
97
92
  }
98
93
  });
99
- }, _ = async ({
94
+ }, E = async ({
100
95
  debug: e = !1,
101
96
  ytdlpPath: o,
102
- videoId: r,
103
- dest: n,
97
+ videoId: n,
98
+ dest: r,
104
99
  tempDir: t,
105
- ffmpegConfig: a
100
+ ffmpegConfig: s
106
101
  }) => {
107
- y(e).log(`Downloading video: ${r} to: ${n}`);
108
- const i = `https://www.youtube.com/watch?v=${r}`;
109
- return U({
102
+ h(e).log(`Downloading video: ${n} to: ${r}`);
103
+ const a = `https://www.youtube.com/watch?v=${n}`;
104
+ return S({
110
105
  debug: e,
111
106
  ytdlpPath: o,
112
- videoUrl: i,
113
- dest: n,
107
+ videoUrl: a,
108
+ dest: r,
114
109
  tempDir: t,
115
- ffmpegConfig: a
110
+ ffmpegConfig: s
116
111
  });
117
- }, j = async ({
112
+ }, K = async ({
118
113
  videoId: e,
119
114
  dest: o,
120
- debug: r = !1,
121
- headless: n = !0
115
+ debug: n = !1,
116
+ headless: r = !0
122
117
  }) => {
123
118
  try {
124
- const t = y(r);
119
+ const t = h(n);
125
120
  t.log(`Downloading video: ${e} to: ${o}`);
126
- const a = `https://m.facebook.com/watch/?v=${e}`, c = await w("fs"), i = await w("path"), u = await w("puppeteer");
127
- c.existsSync(i.dirname(o)) || (c.mkdirSync(i.dirname(o), { recursive: !0 }, 777), t.log(`建立 ${i.dirname(o)}`));
121
+ const s = `https://m.facebook.com/watch/?v=${e}`, i = await w("fs"), a = await w("path"), u = await w("puppeteer");
122
+ i.existsSync(a.dirname(o)) || (i.mkdirSync(a.dirname(o), { recursive: !0 }, 777), t.log(`建立 ${a.dirname(o)}`));
128
123
  const g = {};
129
- n || (g.headless = !1);
130
- const h = await u.launch(g);
124
+ r || (g.headless = !1);
125
+ const y = await u.launch(g);
131
126
  t.log("啟動 puppeteer");
132
- const l = await h.newPage();
127
+ const l = await y.newPage();
133
128
  await l.setUserAgent(
134
129
  "'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'"
135
- ), t.log("開新分頁"), t.log(`前往 ${a}`), await Promise.race([
136
- l.goto(a, {
130
+ ), t.log("開新分頁"), t.log(`前往 ${s}`), await Promise.race([
131
+ l.goto(s, {
137
132
  waitUntil: "networkidle0"
138
133
  }),
139
134
  l.waitForSelector("video")
140
135
  ]), t.log("找到 video 元素");
141
- const d = await l.$eval("video", (p) => p.getAttribute("src"));
142
- return t.log(`取得 video url: ${d}`), await h.close(), t.log("關閉 puppeteer"), await D(d, o), t.log(`下載完成 ${d}`), [null, !0];
136
+ const p = await l.$eval("video", (d) => d.getAttribute("src"));
137
+ return t.log(`取得 video url: ${p}`), await y.close(), t.log("關閉 puppeteer"), await b(p, o), t.log(`下載完成 ${p}`), [null, !0];
143
138
  } catch (t) {
144
139
  return [t, null];
145
140
  }
146
- }, I = async ({
141
+ }, _ = async ({
147
142
  debug: e = !1,
148
143
  ytdlpPath: o,
149
- videoId: r,
150
- dest: n,
144
+ videoId: n,
145
+ dest: r,
151
146
  tempDir: t,
152
- ffmpegConfig: a
147
+ ffmpegConfig: s
153
148
  }) => {
154
- y(e).log(`Downloading video: ${r} to: ${n}`);
155
- const i = `https://vimeo.com/${r}`;
156
- return U({
149
+ h(e).log(`Downloading video: ${n} to: ${r}`);
150
+ const a = `https://vimeo.com/${n}`;
151
+ return S({
157
152
  debug: e,
158
153
  ytdlpPath: o,
159
- videoUrl: i,
160
- dest: n,
154
+ videoUrl: a,
155
+ dest: r,
161
156
  tempDir: t,
162
- ffmpegConfig: a
157
+ ffmpegConfig: s
163
158
  });
164
- }, K = async ({
159
+ }, C = async ({
165
160
  debug: e = !1,
166
161
  ytdlpPath: o,
167
- videoId: r,
168
- dest: n,
162
+ videoId: n,
163
+ dest: r,
169
164
  tempDir: t,
170
- ffmpegConfig: a
165
+ ffmpegConfig: s
171
166
  }) => {
172
- y(e).log(`Downloading video: ${r} to: ${n}`);
173
- const i = `https://www.instagram.com/reel/${r}/`;
174
- return U({
167
+ h(e).log(`Downloading video: ${n} to: ${r}`);
168
+ const a = `https://www.instagram.com/reel/${n}/`;
169
+ return S({
175
170
  debug: e,
176
171
  ytdlpPath: o,
177
- videoUrl: i,
178
- dest: n,
172
+ videoUrl: a,
173
+ dest: r,
179
174
  tempDir: t,
180
- ffmpegConfig: a
175
+ ffmpegConfig: s
181
176
  });
182
- }, C = async ({
177
+ }, H = async ({
183
178
  videoLink: e,
184
179
  dest: o,
185
- debug: r = !1,
186
- headless: n = !0
180
+ debug: n = !1,
181
+ headless: r = !0
187
182
  }) => {
188
183
  try {
189
- const t = y(r);
184
+ const t = h(n);
190
185
  t.log(`Downloading video: ${e} to: ${o}`);
191
- const a = e, c = await w("fs"), i = await w("path"), u = await w("puppeteer");
192
- c.existsSync(i.dirname(o)) || (c.mkdirSync(i.dirname(o), { recursive: !0 }, 777), t.log(`建立 ${i.dirname(o)}`));
186
+ const s = e, i = await w("fs"), a = await w("path"), u = await w("puppeteer");
187
+ i.existsSync(a.dirname(o)) || (i.mkdirSync(a.dirname(o), { recursive: !0 }, 777), t.log(`建立 ${a.dirname(o)}`));
193
188
  const g = {};
194
- n || (g.headless = !1);
195
- const h = await u.launch(g);
189
+ r || (g.headless = !1);
190
+ const y = await u.launch(g);
196
191
  t.log("啟動 puppeteer");
197
- const l = await h.newPage();
198
- t.log("開新分頁"), t.log(`前往 ${a}`), await Promise.race([
199
- l.goto(a, {
192
+ const l = await y.newPage();
193
+ t.log("開新分頁"), t.log(`前往 ${s}`), await Promise.race([
194
+ l.goto(s, {
200
195
  waitUntil: "networkidle0"
201
196
  }),
202
197
  l.waitForSelector("video")
203
198
  ]), t.log("找到 video 元素");
204
- const d = await l.$eval(
199
+ const p = await l.$eval(
205
200
  'video source[src^="https://www.tiktok.com/aweme/v1/play/"]',
206
- (p) => p.getAttribute("src")
201
+ (d) => d.getAttribute("src")
207
202
  );
208
- return t.log(`取得 video url: ${d}`), await h.close(), t.log("關閉 puppeteer"), await D(d, o, {
203
+ return t.log(`取得 video url: ${p}`), await y.close(), t.log("關閉 puppeteer"), await b(p, o, {
209
204
  "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",
210
205
  Referer: "https://www.tiktok.com/"
211
206
  // 設定 Referer
212
- }), t.log(`下載完成 ${d}`), [null, !0];
207
+ }), t.log(`下載完成 ${p}`), [null, !0];
213
208
  } catch (t) {
214
209
  return [t, null];
215
210
  }
216
- }, H = ({ type: e }) => {
211
+ }, I = ({ type: e }) => {
217
212
  switch (e) {
218
213
  case "youtube":
219
214
  case "yt-short":
220
- return _;
215
+ return E;
221
216
  case "facebook":
222
217
  case "fb-reel":
223
- return j;
218
+ return K;
224
219
  case "vimeo":
225
- return I;
220
+ return _;
226
221
  case "instagram":
227
222
  case "ig":
228
223
  case "ig-reel":
229
- return K;
224
+ return C;
230
225
  case "tiktok":
231
226
  case "tiktok-reel":
232
- return C;
227
+ return H;
233
228
  default:
234
229
  throw new Error(`Invalid video type: ${e}`);
235
230
  }
236
231
  };
237
232
  export {
238
- H as useDownloader,
239
- j as useFacebook,
240
- K as useInstagram,
241
- C as useTiktok,
242
- I as useVimeo,
243
- _ as useYoutube
233
+ I as useDownloader,
234
+ K as useFacebook,
235
+ C as useInstagram,
236
+ H as useTiktok,
237
+ _ as useVimeo,
238
+ E as useYoutube
244
239
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pieda/video-dl",
3
3
  "private": false,
4
- "version": "1.10.0",
4
+ "version": "1.10.2",
5
5
  "type": "module",
6
6
  "main": "dist/video-dl.cjs",
7
7
  "module": "dist/video-dl.js",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "axios": "^1.10.0",
41
41
  "puppeteer": "^22.13.1",
42
- "uuid": "^13.0.0",
42
+ "uuid": "^10.0.0",
43
43
  "youtubei.js": "^14.0.0"
44
44
  },
45
45
  "devDependencies": {