@yt-kit/core 1.0.1 → 1.0.3

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/index.d.ts CHANGED
@@ -1,17 +1,157 @@
1
- export { CacheManager } from './cache/CacheManager';
2
- export { Configuration } from './config/Configuration';
3
- export { downloadAudio, downloadVideo } from './tasks/download/download';
4
- export { findFormatId } from './yt-dlp/findFormatId';
5
- export { getFromDisk } from './cache/getFromDisk';
6
- export { saveInDisk } from './cache/saveInDisk';
7
- export { formYoutubeUrl } from './lib/ytUtils';
8
- export { getBetterFormat, getWorstFormat } from './lib/compareFormats';
9
- export { resolveFilenamePattern } from './lib/resolveFilenamePattern';
10
- export { expandPattern } from './lib/expandPattern';
11
- export { resolvePath } from './lib/resolvePath';
12
- export type * from './types/videoTypes';
13
- export type * from './types/childProcessTypes';
14
- export type * from './types/configTypes';
15
- export type * from './types/cacheTypes';
16
- export type { Pattern, PatternData } from './lib/expandPattern';
17
- export { STANDARD_RESOLUTIONS } from './lib/constants';
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export type CacheKey = "formats:" | (string & {});
4
+ export interface CachedData {
5
+ content: string;
6
+ timestamp: number;
7
+ }
8
+ export interface ValueToCache {
9
+ content: string;
10
+ }
11
+ export interface CacheConfig {
12
+ method: CacheMethod;
13
+ cacheLocation?: string;
14
+ }
15
+ export type CacheMethod = "memory" | "disk" | "hybrid";
16
+ export declare class CacheManager {
17
+ private store;
18
+ private defaultTtl;
19
+ get(key: CacheKey, json?: boolean): Promise<CachedData | null>;
20
+ set(key: CacheKey, value: ValueToCache): Promise<void>;
21
+ delete(key: string): void;
22
+ }
23
+ export declare const cache: CacheManager;
24
+ export type ConfigKey = keyof ConfigMap;
25
+ export type ConfigValue<T extends ConfigKey> = ConfigMap[T];
26
+ export type ConfigMap = {
27
+ "cache": CacheConfig;
28
+ };
29
+ export declare class Configuration {
30
+ private store;
31
+ get<K extends ConfigKey>(key: K): ConfigValue<K> | null;
32
+ set<K extends ConfigKey>(key: K, value: ConfigValue<K>): void;
33
+ delete<K extends ConfigKey>(key: K): void;
34
+ }
35
+ export declare const config: Configuration;
36
+ export interface DownloadOptions {
37
+ id: string;
38
+ outputPath?: string;
39
+ filename?: string;
40
+ }
41
+ export interface DownloadResult {
42
+ path: string;
43
+ duration: number;
44
+ }
45
+ export declare function downloadVideo(ytId: string, options: DownloadOptions): Promise<DownloadResult | undefined>;
46
+ export declare function downloadAudio(ytId: string, options: DownloadOptions): Promise<DownloadResult | undefined>;
47
+ export declare const STANDARD_RESOLUTIONS: readonly [
48
+ 18,
49
+ 144,
50
+ 240,
51
+ 360,
52
+ 480,
53
+ 720,
54
+ 1080,
55
+ 1440,
56
+ 2160
57
+ ];
58
+ declare const COMMANDS: {
59
+ readonly "yt-dlp": "yt-dlp";
60
+ };
61
+ declare const PATTERNS: {
62
+ readonly ID: "%(id)s";
63
+ readonly YT_ID: "%(ytId)s";
64
+ };
65
+ export type Height = typeof STANDARD_RESOLUTIONS[number];
66
+ export type Resolution = `${Height}p`;
67
+ export type FormatsToFind = Resolution | "best-video" | "worst-video" | "best-audio" | "worst-audio";
68
+ export type MediaType = "audio" | "video";
69
+ export type YtDlpFormat = {
70
+ format_id: string;
71
+ format_note: string;
72
+ ext: EXT;
73
+ protocol: Protocol;
74
+ acodec: Acodec;
75
+ vcodec: string;
76
+ url: string;
77
+ width: number | null;
78
+ height: number | null;
79
+ fps: number | null;
80
+ rows?: number;
81
+ columns?: number;
82
+ fragments?: Fragment[];
83
+ audio_ext: AudioEXT;
84
+ video_ext: VideoEXT;
85
+ vbr: number | null;
86
+ abr: number | null;
87
+ tbr: number | null;
88
+ resolution: string;
89
+ aspect_ratio: number | null;
90
+ filesize_approx: number | null;
91
+ http_headers: HTTPHeaders;
92
+ format: string;
93
+ asr?: number | null;
94
+ filesize?: number | null;
95
+ source_preference?: number;
96
+ audio_channels?: number | null;
97
+ quality?: number;
98
+ has_drm?: boolean;
99
+ language?: null | string;
100
+ language_preference?: number;
101
+ preference?: null;
102
+ dynamic_range?: DynamicRange | null;
103
+ container?: Container;
104
+ available_at?: number;
105
+ downloader_options?: DownloaderOptions;
106
+ };
107
+ export type Acodec = "none" | "mp4a.40.5" | "opus" | "mp4a.40.2";
108
+ export type AudioEXT = "none" | "m4a" | "webm";
109
+ export type Container = "m4a_dash" | "webm_dash" | "mp4_dash";
110
+ export type DownloaderOptions = {
111
+ http_chunk_size: number;
112
+ };
113
+ export type DynamicRange = "SDR";
114
+ export type EXT = "mhtml" | "m4a" | "webm" | "mp4";
115
+ export type Fragment = {
116
+ url: string;
117
+ duration: number;
118
+ };
119
+ export type HTTPHeaders = {
120
+ "User-Agent": string;
121
+ Accept: Accept;
122
+ "Accept-Language": AcceptLanguage;
123
+ "Sec-Fetch-Mode": SECFetchMode;
124
+ };
125
+ export type Accept = "text/html,application/xhtml+xml,application/xmlq=0.9,*/*q=0.8";
126
+ export type AcceptLanguage = "en-us,enq=0.5";
127
+ export type SECFetchMode = "navigate";
128
+ export type Protocol = "mhtml" | "https";
129
+ export type VideoEXT = "none" | "mp4" | "webm";
130
+ export declare function findFormatId(ytId: string, formatToFind: FormatsToFind): Promise<{
131
+ foundSpecific: string | boolean;
132
+ formatId: string | undefined;
133
+ desiredFormat: YtDlpFormat | undefined;
134
+ }>;
135
+ export declare function getFromDisk(key: CacheKey, json?: boolean): Promise<CachedData | undefined>;
136
+ export declare function saveInDisk(key: CacheKey, value: CachedData): Promise<void>;
137
+ export declare function formYoutubeUrl(ytId: string): string;
138
+ export interface CompareOptions {
139
+ type: MediaType;
140
+ compareResolution: boolean;
141
+ }
142
+ export declare function getBetterFormat(a: YtDlpFormat | undefined, b: YtDlpFormat | undefined, { type, compareResolution }: CompareOptions): YtDlpFormat | undefined;
143
+ export declare function getWorstFormat(a: YtDlpFormat | undefined, b: YtDlpFormat | undefined, { type, compareResolution }: CompareOptions): YtDlpFormat | undefined;
144
+ export interface ResolverProps {
145
+ filename: string;
146
+ id: string;
147
+ ytId: string;
148
+ }
149
+ export declare function resolveFilenamePattern({ filename, id, ytId }: ResolverProps): string;
150
+ export type Pattern = typeof PATTERNS[keyof typeof PATTERNS];
151
+ export type PatternData = string;
152
+ export declare function expandPattern(pattern: string, patternMap: Map<Pattern, PatternData>): string;
153
+ export declare function resolvePath(path: string): string;
154
+ export type CommandKey = keyof typeof COMMANDS;
155
+ export type Command = typeof COMMANDS[keyof typeof COMMANDS];
156
+
157
+ export {};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- class A{store=new Map;get(t){let e=this.store.get(t);if(!e)return null;return e}set(t,e){this.store.set(t,e)}delete(t){this.store.delete(t)}}var l=new A;var V={day:86400000,hrs:3600000,min:60000,sec:1000,nano:0.001};function _(t,e){if(!V[e])return t;return t*V[e]}function Y(t){if(typeof t!=="string")return!1;return!0}import{readFile as W}from"node:fs/promises";import{homedir as J}from"node:os";function c(t){return t.replace("~",J())}async function h(t,e=!1){let r=l.get("cache")?.cacheLocation;if(!r)return;let o=c(r),s;try{s=await W(o,"utf8")}catch(a){console.error(`Error leyendo la caché en el almacenamiento para ${t} :`,a)}if(e&&s)try{s=JSON.parse(s)}catch(a){console.error(`Error convirtiendo la caché de ${t} a JSON:`,a)}if(!s)return;return{content:e?s.content:s,timestamp:Date.now()}}import{rm as L}from"node:fs/promises";async function q(t){let e=l.get("cache")?.cacheLocation;if(!e)return;let r=c(e);try{await L(r)}catch(o){console.error(`Error borrando la caché de ${t} en el almacenamiento:`,o)}}import{mkdir as Q,writeFile as G}from"node:fs/promises";import{dirname as H}from"node:path";async function C(t,e){let r=l.get("cache")?.cacheLocation;if(!r)return;let o=c(r),s=H(o);try{Q(s,{recursive:!0}),await G(o,JSON.stringify(e),"utf8")}catch(a){console.error(`Error cacheando ${t} en el almacenamiento:`,a)}}class E{store=new Map;defaultTtl=_(10,"day");async get(t,e=!1){if(!Y(t))throw Error("CacheKey inválida",{cause:t});let r=l.get("cache")?.method??"memory",o=null;if(r==="memory")o=this.store.get(t);if(r==="disk")o=await h(t,e);if(r==="hybrid"){if(o=this.store.get(t),!o)o=await h(t)}if(!o)return null;if(Date.now()-o.timestamp>this.defaultTtl){if(r!=="disk")this.delete(t);if(r==="disk")q(t);return null}return o}async set(t,e){if(!Y(t))throw Error("CacheKey inválida",{cause:t});let r=l.get("cache")?.method??"memory",o={...e,timestamp:Date.now()};if(r==="memory")this.store.set(t,o);if(r==="disk")await C(t,o);if(r==="hybrid")this.store.set(t,o),await C(t,o)}delete(t){this.store.delete(t)}}var T=new E;var X=[18,144,240,360,480,720,1080,1440,2160],v={"yt-dlp":"yt-dlp"},U="%(ytId)s.%(ext)s",M={ID:"%(id)s",YT_ID:"%(ytId)s"};function d(t){return`https://youtube.com/watch?v=${t}`}import{spawn as I}from"node:child_process";import{stdout as Z,stderr as j}from"node:process";function O(t,e){(t==="data"?Z:j).write(e)}function D(t,e,r){let o=v[t];return new Promise((s,a)=>{let p=I(o,e),u="",m="";p.stdout.on("data",(i)=>{u+=i;let f=i.toString();if(r)O("data",f)}),p.stderr.on("data",(i)=>{m+=i;let f=i.toString();if(r)O("err",f)}),p.on("close",(i)=>{if(i===0)s(u.toString());else a(Error(m.toString()))}),p.on("error",(i)=>{a(i)})})}function N(t,e){let r=t;for(let[o,s]of e)r=r.replaceAll(o,s);return r}function B(t){return t.replaceAll("/","⁄")}function P({filename:t,id:e,ytId:r}){let o=new Map([[M.ID,e],[M.YT_ID,r]]),s=N(t,o);return B(s)}class S{async download(t,e,r){let o=this.buildYtDlpArgs(t,e,r);return await D("yt-dlp",o,!0),{duration:-1,path:"unknown"}}buildYtDlpArgs(t,e,r){let{id:o,type:s}=r,a=s==="video",p=r.outputPath,u=P({filename:r.filename,id:r.id,ytId:e}),m="aac";return["-f",o,...a?[]:["-x","--audio-format","aac"],"-o",u,"-P",p,t]}}async function b(t,e){if(!t||!e.id)return;let r=d(t),o=$("video",e);return new S().download(r,t,o)}async function k(t,e){if(!t||!e.id)return;let r=d(t),o=$("audio",e);return new S().download(r,t,o)}function $(t,e){return{id:e.id,type:t,outputPath:e.outputPath??".",filename:e.filename??U}}function z({a:t,b:e,compareResolution:r,type:o}){let s=o==="video"&&r&&t.quality!==null&&e.quality!==null,a=o==="video"&&r&&t.height!==null&&e.height!==null,p=o==="video"&&t.fps!==null&&e.fps!==null,u=o==="audio"&&t.asr!==null&&e.asr!==null,m=t.tbr!==null&&e.tbr!==null,i=0,f=0;if(s){if((t.quality??0)>(e.quality??0))i+=3;else if((t.quality??0)<(e.quality??0))f+=3}if(a){if((t.height??0)>(e.height??0))i+=3;else if((t.height??0)<(e.height??0))f+=3}if(p){if((t.fps??0)>(e.fps??0))i+=2;else if((t.fps??0)<(e.fps??0))f+=2}if(u){if((t.asr??0)>(e.asr??0))i+=2;else if((t.asr??0)<(e.asr??0))f+=2}if(m){if((t.tbr??0)>(e.tbr??0))i+=1;else if((t.tbr??0)<(e.tbr??0))f+=1}return{aScore:i,bScore:f}}function g(t,e,{type:r,compareResolution:o}){if(!t||!e)return;let{aScore:s,bScore:a}=z({a:t,b:e,type:r,compareResolution:o});return s>a?t:e}function x(t,e,{type:r,compareResolution:o}){if(!t||!e)return;let{aScore:s,bScore:a}=z({a:t,b:e,type:r,compareResolution:o});return s>a?e:t}async function tt(t,e){let r=d(t),o=`formats-${t}`,s=Boolean(e.match(/\d/)),a=s?!1:"N/A",p=["--print","%(formats)j",r],m=(await T.get(o))?.content??"";if(!m){let n;try{n=await D("yt-dlp",p)}catch(R){throw console.error("Error consiguiendo el ID del formato"),R}if(typeof n!=="string")throw Error("La salida del proceso es de tipo inválido (se esperaba string)");m=n,T.set(o,{content:m})}let i=[];try{i=JSON.parse(m)}catch(n){throw console.error("Error convirtiendo la salida de yt-dlp a JSON"),n}if(!Array.isArray(i))throw Error("Se esperaba un array");let f=void 0,K=void 0,w=void 0,F=void 0,y=void 0;for(let n of i){let R=n.resolution==="audio only";if(s&&n.format_note===e){a=!0,y=g(y,n,{compareResolution:!1,type:"video"})??n;continue}if(R)w=g(w,n,{compareResolution:!1,type:"audio"})??n,F=x(F,n,{compareResolution:!1,type:"audio"})??n;else f=g(f,n,{compareResolution:!0,type:"video"})??n,K=x(K,n,{compareResolution:!0,type:"video"})??n}if(!s)y={"best-video":f,"worst-video":K,"best-audio":w,"worst-audio":F}[e];return{foundSpecific:a,formatId:y?.format_id,desiredFormat:y}}export{C as saveInDisk,c as resolvePath,P as resolveFilenamePattern,x as getWorstFormat,h as getFromDisk,g as getBetterFormat,d as formYoutubeUrl,tt as findFormatId,N as expandPattern,b as downloadVideo,k as downloadAudio,X as STANDARD_RESOLUTIONS,A as Configuration,E as CacheManager};
1
+ class A{store=new Map;get(t){let e=this.store.get(t);if(!e)return null;return e}set(t,e){this.store.set(t,e)}delete(t){this.store.delete(t)}}var l=new A;var V={day:86400000,hrs:3600000,min:60000,sec:1000,nano:0.001};function _(t,e){if(!V[e])return t;return t*V[e]}function Y(t){if(typeof t!=="string")return!1;return!0}import{readFile as W}from"node:fs/promises";import{homedir as J}from"node:os";function c(t){return t.replace("~",J())}async function T(t,e=!1){let r=l.get("cache")?.cacheLocation;if(!r)return;let o=c(r),s;try{s=await W(o,"utf8")}catch(a){console.error(`Error leyendo la caché en el almacenamiento para ${t} :`,a)}if(e&&s)try{s=JSON.parse(s)}catch(a){console.error(`Error convirtiendo la caché de ${t} a JSON:`,a)}if(!s)return;return{content:e?s.content:s,timestamp:Date.now()}}import{rm as L}from"node:fs/promises";async function q(t){let e=l.get("cache")?.cacheLocation;if(!e)return;let r=c(e);try{await L(r)}catch(o){console.error(`Error borrando la caché de ${t} en el almacenamiento:`,o)}}import{mkdir as Q,writeFile as G}from"node:fs/promises";import{dirname as H}from"node:path";async function C(t,e){let r=l.get("cache")?.cacheLocation;if(!r)return;let o=c(r),s=H(o);try{Q(s,{recursive:!0}),await G(o,JSON.stringify(e),"utf8")}catch(a){console.error(`Error cacheando ${t} en el almacenamiento:`,a)}}class E{store=new Map;defaultTtl=_(10,"day");async get(t,e=!1){if(!Y(t))throw Error("CacheKey inválida",{cause:t});let r=l.get("cache")?.method??"memory",o=null;if(r==="memory")o=this.store.get(t);if(r==="disk")o=await T(t,e);if(r==="hybrid"){if(o=this.store.get(t),!o)o=await T(t)}if(!o)return null;if(Date.now()-o.timestamp>this.defaultTtl){if(r!=="disk")this.delete(t);if(r==="disk")q(t);return null}return o}async set(t,e){if(!Y(t))throw Error("CacheKey inválida",{cause:t});let r=l.get("cache")?.method??"memory",o={...e,timestamp:Date.now()};if(r==="memory")this.store.set(t,o);if(r==="disk")await C(t,o);if(r==="hybrid")this.store.set(t,o),await C(t,o)}delete(t){this.store.delete(t)}}var g=new E;var X=[18,144,240,360,480,720,1080,1440,2160],v={"yt-dlp":"yt-dlp"},U="%(ytId)s.%(ext)s",M={ID:"%(id)s",YT_ID:"%(ytId)s"};function d(t){return`https://youtube.com/watch?v=${t}`}import{spawn as I}from"node:child_process";import{stdout as Z,stderr as j}from"node:process";function O(t,e){(t==="data"?Z:j).write(e)}function D(t,e,r){let o=v[t];return new Promise((s,a)=>{let p=I(o,e),u="",m="";p.stdout.on("data",(i)=>{u+=i;let f=i.toString();if(r)O("data",f)}),p.stderr.on("data",(i)=>{m+=i;let f=i.toString();if(r)O("err",f)}),p.on("close",(i)=>{if(i===0)s(u.toString());else a(Error(m.toString()))}),p.on("error",(i)=>{a(i)})})}function N(t,e){let r=t;for(let[o,s]of e)r=r.replaceAll(o,s);return r}function B(t){return t.replaceAll("/","⁄")}function P({filename:t,id:e,ytId:r}){let o=new Map([[M.ID,e],[M.YT_ID,r]]),s=N(t,o);return B(s)}class S{async download(t,e,r){let o=this.buildYtDlpArgs(t,e,r);return await D("yt-dlp",o,!0),{duration:-1,path:"unknown"}}buildYtDlpArgs(t,e,r){let{id:o,type:s}=r,a=s==="video",p=r.outputPath,u=P({filename:r.filename,id:r.id,ytId:e}),m="aac";return["-f",o,...a?[]:["-x","--audio-format","aac"],"-o",u,"-P",p,t]}}async function b(t,e){if(!t||!e.id)return;let r=d(t),o=$("video",e);return new S().download(r,t,o)}async function k(t,e){if(!t||!e.id)return;let r=d(t),o=$("audio",e);return new S().download(r,t,o)}function $(t,e){return{id:e.id,type:t,outputPath:e.outputPath??".",filename:e.filename??U}}function z({a:t,b:e,compareResolution:r,type:o}){let s=o==="video"&&r&&t.quality!==null&&e.quality!==null,a=o==="video"&&r&&t.height!==null&&e.height!==null,p=o==="video"&&t.fps!==null&&e.fps!==null,u=o==="audio"&&t.asr!==null&&e.asr!==null,m=t.tbr!==null&&e.tbr!==null,i=0,f=0;if(s){if((t.quality??0)>(e.quality??0))i+=3;else if((t.quality??0)<(e.quality??0))f+=3}if(a){if((t.height??0)>(e.height??0))i+=3;else if((t.height??0)<(e.height??0))f+=3}if(p){if((t.fps??0)>(e.fps??0))i+=2;else if((t.fps??0)<(e.fps??0))f+=2}if(u){if((t.asr??0)>(e.asr??0))i+=2;else if((t.asr??0)<(e.asr??0))f+=2}if(m){if((t.tbr??0)>(e.tbr??0))i+=1;else if((t.tbr??0)<(e.tbr??0))f+=1}return{aScore:i,bScore:f}}function h(t,e,{type:r,compareResolution:o}){if(!t||!e)return;let{aScore:s,bScore:a}=z({a:t,b:e,type:r,compareResolution:o});return s>a?t:e}function x(t,e,{type:r,compareResolution:o}){if(!t||!e)return;let{aScore:s,bScore:a}=z({a:t,b:e,type:r,compareResolution:o});return s>a?e:t}async function tt(t,e){let r=d(t),o=`formats-${t}`,s=Boolean(e.match(/\d/)),a=s?!1:"N/A",p=["--print","%(formats)j",r],m=(await g.get(o))?.content??"";if(!m){let n;try{n=await D("yt-dlp",p)}catch(R){throw console.error("Error consiguiendo el ID del formato"),R}if(typeof n!=="string")throw Error("La salida del proceso es de tipo inválido (se esperaba string)");m=n,g.set(o,{content:m})}let i=[];try{i=JSON.parse(m)}catch(n){throw console.error("Error convirtiendo la salida de yt-dlp a JSON"),n}if(!Array.isArray(i))throw Error("Se esperaba un array");let f=void 0,K=void 0,w=void 0,F=void 0,y=void 0;for(let n of i){let R=n.resolution==="audio only";if(s&&n.format_note===e){a=!0,y=h(y,n,{compareResolution:!1,type:"video"})??n;continue}if(R)w=h(w,n,{compareResolution:!1,type:"audio"})??n,F=x(F,n,{compareResolution:!1,type:"audio"})??n;else f=h(f,n,{compareResolution:!0,type:"video"})??n,K=x(K,n,{compareResolution:!0,type:"video"})??n}if(!s)y={"best-video":f,"worst-video":K,"best-audio":w,"worst-audio":F}[e];return{foundSpecific:a,formatId:y?.format_id,desiredFormat:y}}export{C as saveInDisk,c as resolvePath,P as resolveFilenamePattern,x as getWorstFormat,T as getFromDisk,h as getBetterFormat,d as formYoutubeUrl,tt as findFormatId,N as expandPattern,b as downloadVideo,k as downloadAudio,l as config,g as cache,X as STANDARD_RESOLUTIONS,A as Configuration,E as CacheManager};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yt-kit/core",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,21 +21,21 @@
21
21
  "homepage": "https://github.com/ubiufboeuf/yt-kit#readme",
22
22
  "scripts": {
23
23
  "start": "bun pruebas.ts",
24
- "build": "bun build.ts && tsc -p tsconfig.build.json --emitDeclarationOnly",
24
+ "build": "bun build.ts && dts-bundle-generator --no-check -o dist/index.d.ts src/index.ts",
25
25
  "prepublishOnly": "bun run build"
26
26
  },
27
27
  "dependencies": {
28
28
  "typescript": "5"
29
29
  },
30
30
  "devDependencies": {
31
- "eslint": "9.39.1",
32
31
  "@eslint/js": "9.39.1",
33
32
  "@stylistic/eslint-plugin": "5.6.1",
33
+ "@types/bun": "latest",
34
+ "dts-bundle-generator": "9.5.1",
35
+ "eslint": "9.39.1",
34
36
  "globals": "16.5.0",
35
37
  "jiti": "2.6.1",
36
- "typescript-eslint": "8.48.1",
37
- "@types/bun": "latest",
38
- "@types/node": "24.3.0"
38
+ "typescript-eslint": "8.48.1"
39
39
  },
40
40
  "files": [
41
41
  "dist"
@@ -1,9 +0,0 @@
1
- import type { CachedData, CacheKey, ValueToCache } from '../types/cacheTypes';
2
- export declare class CacheManager {
3
- private store;
4
- private defaultTtl;
5
- get(key: CacheKey, json?: boolean): Promise<CachedData | null>;
6
- set(key: CacheKey, value: ValueToCache): Promise<void>;
7
- delete(key: string): void;
8
- }
9
- export declare const cache: CacheManager;
@@ -1,2 +0,0 @@
1
- import type { CachedData, CacheKey } from '../types/cacheTypes';
2
- export declare function getFromDisk(key: CacheKey, json?: boolean): Promise<CachedData | undefined>;
@@ -1,2 +0,0 @@
1
- import type { CacheKey } from '../types/cacheTypes';
2
- export declare function removeFromDisk(key: CacheKey): Promise<void>;
@@ -1,2 +0,0 @@
1
- import type { CachedData, CacheKey } from '../types/cacheTypes';
2
- export declare function saveInDisk(key: CacheKey, value: CachedData): Promise<void>;
@@ -1,8 +0,0 @@
1
- import type { ConfigKey, ConfigValue } from '../types/configTypes';
2
- export declare class Configuration {
3
- private store;
4
- get<K extends ConfigKey>(key: K): ConfigValue<K> | null;
5
- set<K extends ConfigKey>(key: K, value: ConfigValue<K>): void;
6
- delete<K extends ConfigKey>(key: K): void;
7
- }
8
- export declare const config: Configuration;
@@ -1,18 +0,0 @@
1
- export interface Downloader {
2
- download(url: string, ytId: string, options: DownloadTasksOptions): Promise<DownloadResult>;
3
- }
4
- export interface DownloadOptions {
5
- id: string;
6
- outputPath?: string;
7
- filename?: string;
8
- }
9
- export interface DownloadTasksOptions {
10
- id: string;
11
- type: 'video' | 'audio';
12
- outputPath: string;
13
- filename: string;
14
- }
15
- export interface DownloadResult {
16
- path: string;
17
- duration: number;
18
- }
@@ -1,9 +0,0 @@
1
- import type { MediaType } from '../types/videoTypes';
2
- import type { YtDlpFormat } from '../types/ytDlpFormatTypes';
3
- interface CompareOptions {
4
- type: MediaType;
5
- compareResolution: boolean;
6
- }
7
- export declare function getBetterFormat(a: YtDlpFormat | undefined, b: YtDlpFormat | undefined, { type, compareResolution }: CompareOptions): YtDlpFormat | undefined;
8
- export declare function getWorstFormat(a: YtDlpFormat | undefined, b: YtDlpFormat | undefined, { type, compareResolution }: CompareOptions): YtDlpFormat | undefined;
9
- export {};
@@ -1,9 +0,0 @@
1
- export declare const STANDARD_RESOLUTIONS: readonly [18, 144, 240, 360, 480, 720, 1080, 1440, 2160];
2
- export declare const COMMANDS: {
3
- readonly 'yt-dlp': "yt-dlp";
4
- };
5
- export declare const DEFAULT_FILENAME = "%(ytId)s.%(ext)s";
6
- export declare const PATTERNS: {
7
- readonly ID: "%(id)s";
8
- readonly YT_ID: "%(ytId)s";
9
- };
@@ -1,4 +0,0 @@
1
- import type { PATTERNS } from './constants';
2
- export type Pattern = typeof PATTERNS[keyof typeof PATTERNS];
3
- export type PatternData = string;
4
- export declare function expandPattern(pattern: string, patternMap: Map<Pattern, PatternData>): string;
@@ -1 +0,0 @@
1
- export declare function streamLog(type: 'data' | 'err', data: any): void;
@@ -1,7 +0,0 @@
1
- interface ResolverProps {
2
- filename: string;
3
- id: string;
4
- ytId: string;
5
- }
6
- export declare function resolveFilenamePattern({ filename, id, ytId }: ResolverProps): string;
7
- export {};
@@ -1 +0,0 @@
1
- export declare function resolvePath(path: string): string;
@@ -1 +0,0 @@
1
- export declare function sanitizeFilename(raw: string): string;
@@ -1,2 +0,0 @@
1
- import type { CommandKey } from '../types/childProcessTypes';
2
- export declare function spawnAsync(command: CommandKey, args: string[], showOutput?: boolean): Promise<unknown>;
@@ -1,17 +0,0 @@
1
- type TimeUnit = 'day' | 'hrs' | 'min' | 'sec' | 'nano';
2
- type Miliseconds = number;
3
- /**
4
- * Recibe una cantidad `amount` y una unidad `unit`, y devuelve esa cantidad en milisegundos.
5
- *
6
- * Si la unidad no es válida, devuelve la cantidad sin convertir.
7
- *
8
- * ```js
9
- * convertTime(10, 'day') // 864000000ms
10
- * convertTime(4, 'lemon') // 4ms
11
- * ```
12
- *
13
- * @returns Devuelve en milisegundos la cantidad de unidad especificada
14
- */
15
- export declare function timeToMs(amount: number, unit: TimeUnit): Miliseconds;
16
- export declare function msToTime(ms: number, unit: TimeUnit): number;
17
- export {};
@@ -1 +0,0 @@
1
- export declare function formYoutubeUrl(ytId: string): string;
@@ -1,3 +0,0 @@
1
- import type { DownloadOptions } from '../../interfaces/Downloader';
2
- export declare function downloadVideo(ytId: string, options: DownloadOptions): Promise<import("../../interfaces/Downloader").DownloadResult | undefined>;
3
- export declare function downloadAudio(ytId: string, options: DownloadOptions): Promise<import("../../interfaces/Downloader").DownloadResult | undefined>;
@@ -1,13 +0,0 @@
1
- export type CacheKey = 'formats:' | (string & {});
2
- export interface CachedData {
3
- content: string;
4
- timestamp: number;
5
- }
6
- export interface ValueToCache {
7
- content: string;
8
- }
9
- export interface CacheConfig {
10
- method: CacheMethod;
11
- cacheLocation?: string;
12
- }
13
- export type CacheMethod = 'memory' | 'disk' | 'hybrid';
@@ -1,3 +0,0 @@
1
- import type { COMMANDS } from '../lib/constants';
2
- export type CommandKey = keyof typeof COMMANDS;
3
- export type Command = typeof COMMANDS[keyof typeof COMMANDS];
@@ -1,6 +0,0 @@
1
- import type { CacheConfig } from './cacheTypes';
2
- export type ConfigKey = keyof ConfigMap;
3
- export type ConfigValue<T extends ConfigKey> = ConfigMap[T];
4
- export type ConfigMap = {
5
- 'cache': CacheConfig;
6
- };
@@ -1 +0,0 @@
1
- export type DownloadType = 'video' | 'audio';
@@ -1,5 +0,0 @@
1
- import type { STANDARD_RESOLUTIONS } from '../lib/constants';
2
- export type Height = typeof STANDARD_RESOLUTIONS[number];
3
- export type Resolution = `${Height}p`;
4
- export type FormatsToFind = Resolution | 'best-video' | 'worst-video' | 'best-audio' | 'worst-audio';
5
- export type MediaType = 'audio' | 'video';
@@ -1,61 +0,0 @@
1
- export type YtDlpFormat = {
2
- format_id: string;
3
- format_note: string;
4
- ext: EXT;
5
- protocol: Protocol;
6
- acodec: Acodec;
7
- vcodec: string;
8
- url: string;
9
- width: number | null;
10
- height: number | null;
11
- fps: number | null;
12
- rows?: number;
13
- columns?: number;
14
- fragments?: Fragment[];
15
- audio_ext: AudioEXT;
16
- video_ext: VideoEXT;
17
- vbr: number | null;
18
- abr: number | null;
19
- tbr: number | null;
20
- resolution: string;
21
- aspect_ratio: number | null;
22
- filesize_approx: number | null;
23
- http_headers: HTTPHeaders;
24
- format: string;
25
- asr?: number | null;
26
- filesize?: number | null;
27
- source_preference?: number;
28
- audio_channels?: number | null;
29
- quality?: number;
30
- has_drm?: boolean;
31
- language?: null | string;
32
- language_preference?: number;
33
- preference?: null;
34
- dynamic_range?: DynamicRange | null;
35
- container?: Container;
36
- available_at?: number;
37
- downloader_options?: DownloaderOptions;
38
- };
39
- export type Acodec = 'none' | 'mp4a.40.5' | 'opus' | 'mp4a.40.2';
40
- export type AudioEXT = 'none' | 'm4a' | 'webm';
41
- export type Container = 'm4a_dash' | 'webm_dash' | 'mp4_dash';
42
- export type DownloaderOptions = {
43
- http_chunk_size: number;
44
- };
45
- export type DynamicRange = 'SDR';
46
- export type EXT = 'mhtml' | 'm4a' | 'webm' | 'mp4';
47
- export type Fragment = {
48
- url: string;
49
- duration: number;
50
- };
51
- export type HTTPHeaders = {
52
- 'User-Agent': string;
53
- Accept: Accept;
54
- 'Accept-Language': AcceptLanguage;
55
- 'Sec-Fetch-Mode': SECFetchMode;
56
- };
57
- export type Accept = 'text/html,application/xhtml+xml,application/xmlq=0.9,*/*q=0.8';
58
- export type AcceptLanguage = 'en-us,enq=0.5';
59
- export type SECFetchMode = 'navigate';
60
- export type Protocol = 'mhtml' | 'https';
61
- export type VideoEXT = 'none' | 'mp4' | 'webm';
@@ -1,2 +0,0 @@
1
- import type { CacheKey } from '../types/cacheTypes';
2
- export declare function isValidCacheKey(key: CacheKey): boolean;
@@ -1,7 +0,0 @@
1
- import type { FormatsToFind } from '../types/videoTypes';
2
- import type { YtDlpFormat } from '../types/ytDlpFormatTypes';
3
- export declare function findFormatId(ytId: string, formatToFind: FormatsToFind): Promise<{
4
- foundSpecific: string | boolean;
5
- formatId: string | undefined;
6
- desiredFormat: YtDlpFormat | undefined;
7
- }>;
@@ -1,5 +0,0 @@
1
- import type { Downloader, DownloadTasksOptions, DownloadResult } from '../interfaces/Downloader';
2
- export declare class YtDlpDownloader implements Downloader {
3
- download(url: string, ytId: string, options: DownloadTasksOptions): Promise<DownloadResult>;
4
- private buildYtDlpArgs;
5
- }