@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 CHANGED
@@ -1,15 +1,14 @@
1
- # yt-kit
1
+ # yt-dlx
2
2
 
3
- To install dependencies:
3
+ Instalar paquete:
4
4
 
5
5
  ```bash
6
- bun install
7
- ```
6
+ # bun
7
+ bun add -E @yt-dlx/yt
8
8
 
9
- To run:
9
+ # pnpm
10
+ pnpm add -E @yt-dlx/yt
10
11
 
11
- ```bash
12
- bun run index.ts
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 d 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,d)}}var O={allowedExitCodes:[0],ignoreExitCode:!1};async function p(r,t,e){let{allowedExitCodes:s,ignoreExitCode:o,cleanOutput:n,signal:f}={...O,...e};return new Promise((m,b)=>{let u=x(r,t,{signal:f}),w=[],y=[];u.stdout.on("data",(i)=>{w.push(i),e?.onStdout?.(i.toString("utf-8"))}),u.stderr.on("data",(i)=>{y.push(i),e?.onStderr?.(i.toString("utf-8"))}),u.on("close",(i)=>{let a=i??0,l=Buffer.concat(w).toString("utf-8"),c=Buffer.concat(y).toString("utf-8");if(n)l=h(l),c=h(c);if(o||s?.includes(a))m({type:"success",stdout:l,exitCode:a});else{let D=new d(`El proceso "${r}" finalizó con código ${a}.
2
- Stderr: ${c}`,{stdout:l,stderr:c,exitCode:a});m({type:"error",error:D})}}),u.on("error",(i)=>{if(i.name==="AbortError"){let a=new d("Proceso cancelado por el usuario",{stdout:"",stderr:"Aborted",exitCode:-1});return m({type:"error",error:a})}b(i)})})}function h(r){return r.split(`
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 g{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 s=await p(this.binaryPath,e,{cleanOutput:t?.cleanOutput,signal:t?.signal,onStdout:t?.onStdout,onStderr:t?.onStderr});if(s.type==="error")throw s.error;return{filePath:void 0,rawOutput:s.stdout}}async getFormats(r,t){let e=await p(this.binaryPath,["-J",r],{signal:t});if(e.type==="error")throw e.error;let s=JSON.parse(e.stdout),o=[];for(let n of s.formats){let f={id:n.format_id,ext:n.ext,resolution:n.resolution,height:n.height??void 0,width:n.width??void 0,fps:n.fps??void 0,vcodec:n.vcodec,acodec:n.acodec,filesize:n.filesize??n.filesize_approx??void 0,qualityLabel:n.format_note};o.push(f)}return o}async getFormat(r,t){let e=await this.getFormats(r);if(!e.length)return null;if(t.includes("video"))e=e.filter((o)=>o.vcodec&&o.vcodec!=="none");if(t.includes("audio"))e=e.filter((o)=>o.acodec&&o.acodec!=="none");if(t.includes("best"))return[e[e.length-1]];if(t.includes("worst"))return[e[0]];let s=e.filter((o)=>o.qualityLabel===t||o.id===t||o.resolution===t);return s.length?s: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 s=await this.inspector.getFormat(r,t);if(!s)return null;let o=s[s.length-1];return await this.downloader.download(r,{format:o.id,...e})}}export{h as cleanSubprocessOutput,p as asyncSubprocess,S as YtEngine,g as YtDlpDownloader,d as SubprocessError};
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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yt-dlx/yt",
3
3
  "description": "YouTube Media Extractor & Downloader",
4
- "version": "0.1.0",
4
+ "version": "0.3.1",
5
5
  "module": "entry.ts",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",