@yt-dlx/yt 0.1.0 → 0.3.1
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 +8 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
# yt-
|
|
1
|
+
# yt-dlx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Instalar paquete:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
bun
|
|
7
|
-
|
|
6
|
+
# bun
|
|
7
|
+
bun add -E @yt-dlx/yt
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
# pnpm
|
|
10
|
+
pnpm add -E @yt-dlx/yt
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
# npm
|
|
13
|
+
npm i -E @yt-dlx/yt
|
|
13
14
|
```
|
|
14
|
-
|
|
15
|
-
This project was created using `bun init` in bun v1.3.14. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export type SubprocessResult = {
|
|
|
29
29
|
};
|
|
30
30
|
export declare function asyncSubprocess(command: string, args: string[], options?: SubprocessOptions): Promise<SubprocessResult>;
|
|
31
31
|
export declare function cleanSubprocessOutput(rawStdout: string): string;
|
|
32
|
+
export declare function spawnStream(command: string, args: string[], signal?: AbortSignal): {
|
|
33
|
+
stream: ReadableStream<any>;
|
|
34
|
+
process: import("node:child_process").ChildProcessWithoutNullStreams;
|
|
35
|
+
};
|
|
32
36
|
export interface DownloadOptions extends SubprocessOptions {
|
|
33
37
|
outputDir?: string;
|
|
34
38
|
outputTemplate?: string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spawn as x}from"node:child_process";class
|
|
2
|
-
Stderr: ${
|
|
1
|
+
import{spawn as x}from"node:child_process";class u extends Error{stdout;stderr;exitCode;constructor(r,t,e){super(r,e);if(this.name="SubprocessError",this.stdout=t.stdout,this.stderr=t.stderr,this.exitCode=t.exitCode,Error.captureStackTrace)Error.captureStackTrace(this,u)}}var O={allowedExitCodes:[0],ignoreExitCode:!1};async function f(r,t,e){let{allowedExitCodes:o,ignoreExitCode:n,cleanOutput:s,signal:a}={...O,...e};return new Promise((m,b)=>{let c=x(r,t,{signal:a}),h=[],g=[];c.stdout.on("data",(i)=>{h.push(i),e?.onStdout?.(i.toString("utf-8"))}),c.stderr.on("data",(i)=>{g.push(i),e?.onStderr?.(i.toString("utf-8"))}),c.on("close",(i)=>{let d=i??0,l=Buffer.concat(h).toString("utf-8"),p=Buffer.concat(g).toString("utf-8");if(s)l=w(l),p=w(p);if(n||o?.includes(d))m({type:"success",stdout:l,exitCode:d});else{let D=new u(`El proceso "${r}" finalizó con código ${d}.
|
|
2
|
+
Stderr: ${p}`,{stdout:l,stderr:p,exitCode:d});m({type:"error",error:D})}}),c.on("error",(i)=>{if(i.name==="AbortError"){let d=new u("Proceso cancelado por el usuario",{stdout:"",stderr:"Aborted",exitCode:-1});return m({type:"error",error:d})}b(i)})})}function w(r){return r.split(`
|
|
3
3
|
`).map((t)=>{if(t.includes("\r")){let e=t.split("\r").filter(Boolean);return e[e.length-1]??""}return t}).filter((t)=>t.trim().length>0).join(`
|
|
4
|
-
`)}class
|
|
4
|
+
`)}import{spawn as F}from"node:child_process";function P(r,t,e){let o=F(r,t,{signal:e});return{stream:new ReadableStream({start(s){o.stdout.on("data",(a)=>{s.enqueue(a)}),o.stdout.on("end",()=>{s.close()}),o.stderr.on("data",(a)=>{console.error("[yt-dlx stderr]:",a.toString("utf-8"))}),o.on("error",(a)=>{s.error(a)})},cancel(){o.kill()}}),process:o}}class y{binaryPath;constructor(r="yt-dlp"){this.binaryPath=r}async download(r,t){let e=[];if(t?.outputDir)e.push("-P",t.outputDir);if(t?.format)e.push("-f",t.format);if(t?.outputTemplate)e.push("-o",t.outputTemplate);if(t?.restrictFilenames){if(e.push("--restrict-filenames"),t.restrictFilenames==="URL")e.push("--restrict-filenames","URL")}if(t?.newLine)e.push("--newline");e.push(r);let o=await f(this.binaryPath,e,{cleanOutput:t?.cleanOutput,signal:t?.signal,onStdout:t?.onStdout,onStderr:t?.onStderr});if(o.type==="error")throw o.error;return{filePath:void 0,rawOutput:o.stdout}}async getFormats(r,t){let e=await f(this.binaryPath,["-J",r],{signal:t});if(e.type==="error")throw e.error;let o=JSON.parse(e.stdout),n=[];for(let s of o.formats){let a={id:s.format_id,ext:s.ext,resolution:s.resolution,height:s.height??void 0,width:s.width??void 0,fps:s.fps??void 0,vcodec:s.vcodec,acodec:s.acodec,filesize:s.filesize??s.filesize_approx??void 0,qualityLabel:s.format_note};n.push(a)}return n}async getFormat(r,t){let e=await this.getFormats(r);if(!e.length)return null;if(t.includes("video"))e=e.filter((n)=>n.vcodec&&n.vcodec!=="none");if(t.includes("audio"))e=e.filter((n)=>n.acodec&&n.acodec!=="none");if(t.includes("best"))return[e[e.length-1]];if(t.includes("worst"))return[e[0]];let o=e.filter((n)=>n.qualityLabel===t||n.id===t||n.resolution===t);return o.length?o:null}}class S{inspector;downloader;constructor(r){if("adapter"in r)this.inspector=r.adapter,this.downloader=r.adapter;else this.inspector=r.inspector,this.downloader=r.downloader}async download(r,t,e){let o=await this.inspector.getFormat(r,t);if(!o)return null;let n=o[o.length-1];return await this.downloader.download(r,{format:n.id,...e})}}export{P as spawnStream,w as cleanSubprocessOutput,f as asyncSubprocess,S as YtEngine,y as YtDlpDownloader,u as SubprocessError};
|