@pieda/video-dl 1.3.1 → 1.4.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.
@@ -2,3 +2,4 @@ export { useDownloader } from './useDownloader';
2
2
  export { useYoutube } from './useYoutube';
3
3
  export { useFacebook } from './useFacebook';
4
4
  export { useVimeo } from './useVimeo';
5
+ export { useInstagram } from './useInstagram';
@@ -1,9 +1,10 @@
1
1
  import { useYoutube } from './useYoutube';
2
2
  import { useFacebook } from './useFacebook';
3
3
  import { useVimeo } from './useVimeo';
4
+ import { useInstagram } from './useInstagram';
4
5
  type TUseDownloader = {
5
- type: 'youtube' | 'facebook' | 'vimeo';
6
+ type: 'youtube' | 'facebook' | 'vimeo' | 'instagram';
6
7
  };
7
- type TUseDownloaderResponse = typeof useYoutube | typeof useFacebook | typeof useVimeo;
8
+ type TUseDownloaderResponse = typeof useYoutube | typeof useFacebook | typeof useVimeo | typeof useInstagram;
8
9
  export declare const useDownloader: ({ type }: TUseDownloader) => TUseDownloaderResponse;
9
10
  export {};
@@ -0,0 +1,7 @@
1
+ type TUseInstagram = {
2
+ videoId: string;
3
+ dest: string;
4
+ debug?: boolean;
5
+ };
6
+ export declare const useInstagram: ({ videoId, dest, debug, }: TUseInstagram) => Promise<[Error | null, boolean | null]>;
7
+ export {};
@@ -1 +1 @@
1
- export { useDownloader, useYoutube, useFacebook, useVimeo } from './composables';
1
+ export { useDownloader, useYoutube, useFacebook, useVimeo, useInstagram } 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((e,u)=>{import(o).then(t=>e(t.default)).catch(u)}),h=async(o,e)=>{const u=await c("fs"),t=await c("axios");return new Promise((w,r)=>{t.get(o,{responseType:"stream"}).then(i=>{const p=i.data,s=u.createWriteStream(e);p.pipe(s),s.on("finish",function(){s.close(()=>{w()})})}).catch(r)})},m=(o=!1)=>({log:(...e)=>{o&&console.log(...e)},error:(...e)=>{o&&console.error(...e)}}),f=async({videoId:o,dest:e,debug:u=!1})=>{const t=m(u);t.log(`Downloading video: ${o} to: ${e}`);const w=`https://www.youtube.com/watch?v=${o}`,r=await c("fs"),i=await c("path"),p=await c("@distube/ytdl-core");return r.existsSync(i.dirname(e))||r.mkdirSync(i.dirname(e),{recursive:!0},777),new Promise((s,n)=>{try{const a=p(w).pipe(r.createWriteStream(e));a.on("finish",()=>{t.log("Downloading finished."),s([null,!0])}),a.on("error",l=>{throw l})}catch(a){s([a,null])}})},y=async({videoId:o,dest:e,debug:u=!1})=>{try{const t=m(u);t.log(`Downloading video: ${o} to: ${e}`);const w=`https://m.facebook.com/watch/?v=${o}`,r=await c("fs"),i=await c("path"),p=await c("puppeteer");r.existsSync(i.dirname(e))||(r.mkdirSync(i.dirname(e),{recursive:!0},777),t.log(`建立 ${i.dirname(e)}`));const s=await p.launch();t.log("啟動 puppeteer");const n=await s.newPage();await n.setUserAgent("'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1'"),t.log("開新分頁"),await n.goto(w,{waitUntil:"networkidle0"}),t.log(`前往 ${w}`),await n.waitForSelector("video"),t.log("找到 video 元素");const a=await n.$eval("video",l=>l.getAttribute("src"));return t.log(`取得 video url: ${a}`),await s.close(),t.log("關閉 puppeteer"),await h(a,e),t.log(`下載完成 ${a}`),[null,!0]}catch(t){return[t,null]}},$=async({videoId:o,dest:e,debug:u=!1})=>{const t=m(u);t.log(`Downloading video: ${o} to: ${e}`);const w=await c("fs"),r=await c("path"),i=await c("axios"),p=async()=>{const n=await i.get("https://vimeo.com/_next/viewer",{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest"}}),{jwt:a}=n.data;return a||""},s=async(n="",a="")=>{const l=await i.get(`https://api.vimeo.com/videos/${n}?&fields=download`,{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest",Authorization:`jwt ${a}`}}),{download:g=[]}=l.data,d=g[0]||null;return(d==null?void 0:d.link)||""};return w.existsSync(r.dirname(e))||(w.mkdirSync(r.dirname(e),{recursive:!0},777),t.log(`建立 ${r.dirname(e)}`)),new Promise(async(n,a)=>{try{const l=await p();t.log(`取得 jwt ${l}`);const g=await s(o,l);t.log(`取得 videoUrl ${g}`),await h(g,e),t.log(`下載完成 ${e}`),n([null,!0])}catch(l){n([l,null])}})},v=({type:o})=>{switch(o){case"youtube":return f;case"facebook":return y;case"vimeo":return $;default:throw new Error(`Invalid video type: ${o}`)}};exports.useDownloader=v;exports.useFacebook=y;exports.useVimeo=$;exports.useYoutube=f;
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;
package/dist/video-dl.js CHANGED
@@ -1,117 +1,142 @@
1
- const c = (o) => new Promise((e, u) => {
2
- import(o).then((t) => e(t.default)).catch(u);
3
- }), m = async (o, e) => {
4
- const u = await c("fs"), t = await c("axios");
5
- return new Promise((w, r) => {
6
- t.get(o, { responseType: "stream" }).then((i) => {
7
- const p = i.data, s = u.createWriteStream(e);
8
- p.pipe(s), s.on("finish", function() {
9
- s.close(() => {
10
- w();
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();
11
11
  });
12
12
  });
13
13
  }).catch(r);
14
14
  });
15
- }, h = (o = !1) => ({
16
- log: (...e) => {
17
- o && console.log(...e);
15
+ }, m = (o = !1) => ({
16
+ log: (...t) => {
17
+ o && console.log(...t);
18
18
  },
19
- error: (...e) => {
20
- o && console.error(...e);
19
+ error: (...t) => {
20
+ o && console.error(...t);
21
21
  }
22
22
  }), f = async ({
23
23
  videoId: o,
24
- dest: e,
25
- debug: u = !1
24
+ dest: t,
25
+ debug: w = !1
26
26
  }) => {
27
- const t = h(u);
28
- t.log(`Downloading video: ${o} to: ${e}`);
29
- const w = `https://www.youtube.com/watch?v=${o}`, r = await c("fs"), i = await c("path"), p = await c("@distube/ytdl-core");
30
- return r.existsSync(i.dirname(e)) || r.mkdirSync(i.dirname(e), { recursive: !0 }, 777), new Promise((s, n) => {
27
+ const e = m(w);
28
+ 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) => {
31
31
  try {
32
- const a = p(w).pipe(r.createWriteStream(e));
33
- a.on("finish", () => {
34
- t.log("Downloading finished."), s([null, !0]);
35
- }), a.on("error", (l) => {
36
- throw l;
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]);
37
36
  });
38
- } catch (a) {
39
- s([a, null]);
37
+ } catch (s) {
38
+ console.log("error"), i([s, null]);
40
39
  }
41
40
  });
42
- }, y = async ({
41
+ }, $ = async ({
43
42
  videoId: o,
44
- dest: e,
45
- debug: u = !1
43
+ dest: t,
44
+ debug: w = !1
46
45
  }) => {
47
46
  try {
48
- const t = h(u);
49
- t.log(`Downloading video: ${o} to: ${e}`);
50
- const w = `https://m.facebook.com/watch/?v=${o}`, r = await c("fs"), i = await c("path"), p = await c("puppeteer");
51
- r.existsSync(i.dirname(e)) || (r.mkdirSync(i.dirname(e), { recursive: !0 }, 777), t.log(`建立 ${i.dirname(e)}`));
52
- const s = await p.launch();
53
- t.log("啟動 puppeteer");
54
- const n = await s.newPage();
55
- await n.setUserAgent(
47
+ const e = m(w);
48
+ 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
+ e.log("啟動 puppeteer");
53
+ const a = await i.newPage();
54
+ await a.setUserAgent(
56
55
  "'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'"
57
- ), t.log("開新分頁"), await n.goto(w, {
56
+ ), e.log("開新分頁"), await a.goto(u, {
58
57
  waitUntil: "networkidle0"
59
- }), t.log(`前往 ${w}`), await n.waitForSelector("video"), t.log("找到 video 元素");
60
- const a = await n.$eval("video", (l) => l.getAttribute("src"));
61
- return t.log(`取得 video url: ${a}`), await s.close(), t.log("關閉 puppeteer"), await m(a, e), t.log(`下載完成 ${a}`), [null, !0];
62
- } catch (t) {
63
- return [t, null];
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
+ } catch (e) {
62
+ return [e, null];
64
63
  }
65
- }, $ = async ({
64
+ }, y = async ({
66
65
  videoId: o,
67
- dest: e,
68
- debug: u = !1
66
+ dest: t,
67
+ debug: w = !1
69
68
  }) => {
70
- const t = h(u);
71
- t.log(`Downloading video: ${o} to: ${e}`);
72
- const w = await c("fs"), r = await c("path"), i = await c("axios"), p = async () => {
73
- const n = await i.get("https://vimeo.com/_next/viewer", {
69
+ const e = m(w);
70
+ 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
73
  responseType: "json",
75
74
  headers: {
76
75
  "X-Requested-With": "XMLHttpRequest"
77
76
  }
78
- }), { jwt: a } = n.data;
79
- return a || "";
80
- }, s = async (n = "", a = "") => {
81
- const l = await i.get(`https://api.vimeo.com/videos/${n}?&fields=download`, {
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`, {
82
81
  responseType: "json",
83
82
  headers: {
84
83
  "X-Requested-With": "XMLHttpRequest",
85
- Authorization: `jwt ${a}`
84
+ Authorization: `jwt ${s}`
86
85
  }
87
- }), { download: g = [] } = l.data, d = g[0] || null;
88
- return (d == null ? void 0 : d.link) || "";
86
+ }), { download: p = [] } = l.data, h = p[0] || null;
87
+ return (h == null ? void 0 : h.link) || "";
89
88
  };
90
- return w.existsSync(r.dirname(e)) || (w.mkdirSync(r.dirname(e), { recursive: !0 }, 777), t.log(`建立 ${r.dirname(e)}`)), new Promise(async (n, a) => {
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) => {
91
90
  try {
92
- const l = await p();
93
- t.log(`取得 jwt ${l}`);
94
- const g = await s(o, l);
95
- t.log(`取得 videoUrl ${g}`), await m(g, e), t.log(`下載完成 ${e}`), n([null, !0]);
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]);
96
95
  } catch (l) {
97
- n([l, null]);
96
+ a([l, null]);
98
97
  }
99
98
  });
100
- }, v = ({ type: o }) => {
99
+ }, v = async ({
100
+ videoId: o,
101
+ dest: t,
102
+ debug: w = !1
103
+ }) => {
104
+ try {
105
+ const e = m(w);
106
+ 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
+ e.log("啟動 puppeteer");
111
+ const a = await i.newPage();
112
+ await a.setUserAgent(
113
+ "'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, {
115
+ // 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
+ } catch (e) {
120
+ return [e, null];
121
+ }
122
+ }, S = ({ type: o }) => {
101
123
  switch (o) {
102
124
  case "youtube":
103
125
  return f;
104
126
  case "facebook":
105
- return y;
106
- case "vimeo":
107
127
  return $;
128
+ case "vimeo":
129
+ return y;
130
+ case "instagram":
131
+ return v;
108
132
  default:
109
133
  throw new Error(`Invalid video type: ${o}`);
110
134
  }
111
135
  };
112
136
  export {
113
- v as useDownloader,
114
- y as useFacebook,
115
- $ as useVimeo,
137
+ S as useDownloader,
138
+ $ as useFacebook,
139
+ v as useInstagram,
140
+ y as useVimeo,
116
141
  f as useYoutube
117
142
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pieda/video-dl",
3
3
  "private": false,
4
- "version": "1.3.1",
4
+ "version": "1.4.0",
5
5
  "type": "module",
6
6
  "main": "dist/video-dl.cjs",
7
7
  "module": "dist/video-dl.js",
@@ -31,6 +31,7 @@
31
31
  "build": "vue-tsc && vite build && tsc --declaration --emitDeclarationOnly",
32
32
  "preview": "vite preview",
33
33
  "prepare": "npm run build",
34
+ "start": "bun demo.ts",
34
35
  "version:major": "npm version major",
35
36
  "version:minor": "npm version minor",
36
37
  "version:patch": "npm version patch"