@pieda/video-dl 1.0.1 → 1.1.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=o=>new Promise((e,c)=>{import(o).then(t=>e(t.default)).catch(c)}),$=async(o,e)=>{const c=await i("fs"),t=await i("axios");return new Promise((a,n)=>{t.get(o,{responseType:"stream"}).then(r=>{const l=r.data,s=c.createWriteStream(e);l.pipe(s),s.on("finish",function(){s.close(()=>{a()})})}).catch(n)})},v=(o=!1)=>({log:(...e)=>{o&&console.log(...e)},error:(...e)=>{o&&console.error(...e)}}),k=async({videoId:o,dest:e,debug:c=!1})=>{const t=v(c);t.log(`Downloading video: ${o} to: ${e}`);const a=`https://www.youtube.com/watch?v=${o}`,n=await i("fs"),r=await i("path"),l=await i("@distube/ytdl-core");return n.existsSync(r.dirname(e))||n.mkdirSync(r.dirname(e),{recursive:!0},777),new Promise((s,u)=>{l(a).pipe(n.createWriteStream(e)).on("finish",()=>{t.log("Downloading finished."),s()})})},S=async({videoId:o,dest:e,debug:c=!1})=>{const t=v(c);t.log(`Downloading video: ${o} to: ${e}`);const a=`https://m.facebook.com/watch/?v=${o}`,n=await i("fs"),r=await i("path"),l=await i("puppeteer");n.existsSync(r.dirname(e))||(n.mkdirSync(r.dirname(e),{recursive:!0},777),t.log(`建立 ${r.dirname(e)}`));const s=await l.launch();t.log("啟動 puppeteer");const u=await s.newPage();await u.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 u.goto(a,{waitUntil:"networkidle0"}),t.log(`前往 ${a}`),await u.waitForSelector("video"),t.log("找到 video 元素");const w=await u.$eval("video",p=>p.getAttribute("src"));t.log(`取得 video url: ${w}`),await s.close(),t.log("關閉 puppeteer"),await $(w,e),t.log(`下載完成 ${w}`)},P=async({videoId:o,dest:e,downloadBtnSelector:c,debug:t=!1})=>{const a=v(t);a.log(`Downloading video: ${o} to: ${e}`);const n=`https://vimeo.com/${o}`,r=await i("fs"),l=await i("path"),s=await i("axios"),u=await i("puppeteer"),w=async p=>{var m;const y=await s.get(p,{responseType:"json",headers:{"X-Requested-With":"XMLHttpRequest"}}),d=Array.from(((m=y.data)==null?void 0:m.files)||[]);return d[d.length-1].download_url};return r.existsSync(l.dirname(e))||(r.mkdirSync(l.dirname(e),{recursive:!0},777),a.log(`建立 ${l.dirname(e)}`)),new Promise(async(p,y)=>{const d=await u.launch({headless:!1,defaultViewport:{width:1920,height:1080}});a.log("啟動 puppeteer");const g=await d.newPage();a.log("開新分頁"),await g.setRequestInterception(!0),g.on("request",async m=>{const h=m.url();if(h.indexOf("action=load_download_config")>-1){a.log(`攔截下載請求 ${h}`);const b=await w(h);a.log(`正在開始下載 ${b}`),await $(b,e),a.log(`下載完成 ${e}`),await d.close(),a.log("關閉 puppeteer"),p();return}m.continue()}),await g.goto(n,{waitUntil:"networkidle0"}),a.log(`前往 ${n}`);const f=c||"#main > div > main > div > div > div > div._1cCXb.sc-kEmuub.bmHlZQ > div._3oHHF.sc-bbkauy.fmFDPY > div > button:nth-child(1)";await g.waitForSelector(f),a.log(`找到下載按鈕 ${f}`),await g.click(f),a.log("點擊下載按鈕")})},U=({type:o})=>{switch(o){case"youtube":return k;case"facebook":return S;case"vimeo":return P;default:throw new Error(`Invalid video type: ${o}`)}};exports.useDownloader=U;exports.useFacebook=S;exports.useVimeo=P;exports.useYoutube=k;
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pieda/video-dl",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "dist/video-dl.cjs",
|
|
7
|
+
"module": "dist/video-dl.js",
|
|
6
8
|
"files": [
|
|
7
9
|
"dist"
|
|
8
10
|
],
|
|
@@ -19,8 +21,9 @@
|
|
|
19
21
|
".": {
|
|
20
22
|
"import": {
|
|
21
23
|
"types": "./dist/types/library.d.ts",
|
|
22
|
-
"default": "./dist/video-dl.
|
|
23
|
-
}
|
|
24
|
+
"default": "./dist/video-dl.js"
|
|
25
|
+
},
|
|
26
|
+
"require": "./dist/video-dl.cjs"
|
|
24
27
|
}
|
|
25
28
|
},
|
|
26
29
|
"scripts": {
|
|
File without changes
|