@yt-kit/core 0.2.4 → 0.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.
- package/README.md +22 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/interfaces/Downloader.d.ts +8 -1
- package/dist/lib/constants.d.ts +4 -3
- package/dist/lib/constants.js +4 -4
- package/dist/lib/expandPattern.d.ts +4 -0
- package/dist/lib/expandPattern.js +7 -0
- package/dist/lib/logger.d.ts +1 -0
- package/dist/lib/logger.js +8 -0
- package/dist/lib/logs.d.ts +1 -0
- package/dist/lib/logs.js +8 -0
- package/dist/lib/resolveFilename.d.ts +7 -0
- package/dist/lib/resolveFilename.js +11 -0
- package/dist/lib/sanitizeFilename.d.ts +1 -0
- package/dist/lib/sanitizeFilename.js +6 -0
- package/dist/lib/spawnAsync.d.ts +1 -1
- package/dist/lib/spawnAsync.js +8 -7
- package/dist/tasks/download/download.d.ts +3 -0
- package/dist/tasks/download/download.js +28 -0
- package/dist/types/childProcessTypes.d.ts +3 -0
- package/dist/types/childProcessTypes.js +1 -0
- package/dist/types/downloadTypes.d.ts +1 -0
- package/dist/types/downloadTypes.js +1 -0
- package/dist/types/downloaderTaskTypes.d.ts +1 -0
- package/dist/types/downloaderTaskTypes.js +1 -0
- package/dist/yt-dlp-downloader/YtDlpDownloader.d.ts +2 -2
- package/dist/yt-dlp-downloader/YtDlpDownloader.js +11 -15
- package/package.json +1 -1
- package/dist/tasks/download/downloadVideo.d.ts +0 -1
- package/dist/tasks/download/downloadVideo.js +0 -9
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# YT-KIT (core)
|
|
2
|
+
|
|
3
|
+
Kit de herramientas para manejar multimedia orientada a videos.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
# Con npm
|
|
9
|
+
npm install @yt-kit/core
|
|
10
|
+
|
|
11
|
+
# Con pnpm
|
|
12
|
+
pnpm add -E @yt-kit/core
|
|
13
|
+
|
|
14
|
+
# Con bun
|
|
15
|
+
bun add -E @yt-kit/core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Sobre la estructura de carpetas
|
|
19
|
+
|
|
20
|
+
El archivo `pruebas.ts` es un archivo para probar el funcionamiento del proyecto antes de lanzar una nueva versión.
|
|
21
|
+
|
|
22
|
+
`src/index.ts` es el archivo principal para las builds, no para desarrollo. En todo caso, el archivo "principal" sería `pruebas.ts`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './tasks/download/
|
|
1
|
+
export * from './tasks/download/download';
|
|
2
2
|
export * from './types/videoTypes';
|
|
3
|
-
export * from './types/
|
|
3
|
+
export * from './types/childProcessTypes';
|
|
4
4
|
export { STANDARD_RESOLUTIONS } from './lib/constants';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Funcionalidades del programa
|
|
2
|
-
export * from './tasks/download/
|
|
2
|
+
export * from './tasks/download/download';
|
|
3
3
|
// Tipos
|
|
4
4
|
export * from './types/videoTypes';
|
|
5
|
-
export * from './types/
|
|
5
|
+
export * from './types/childProcessTypes';
|
|
6
6
|
// Constantes públicas (seguras de exportar)
|
|
7
7
|
export { STANDARD_RESOLUTIONS } from './lib/constants';
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
export interface Downloader {
|
|
2
|
-
download(url: string, options:
|
|
2
|
+
download(url: string, ytId: string, options: DownloadTasksOptions): Promise<DownloadResult>;
|
|
3
3
|
}
|
|
4
4
|
export interface DownloadOptions {
|
|
5
|
+
id: string;
|
|
6
|
+
outputPath?: string;
|
|
7
|
+
filename?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface DownloadTasksOptions {
|
|
5
10
|
id: string;
|
|
6
11
|
type: 'video' | 'audio';
|
|
12
|
+
outputPath: string;
|
|
13
|
+
filename: string;
|
|
7
14
|
}
|
|
8
15
|
export interface DownloadResult {
|
|
9
16
|
path: string;
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export declare const STANDARD_RESOLUTIONS: readonly [18, 144, 240, 360, 480, 720
|
|
|
2
2
|
export declare const COMMANDS: {
|
|
3
3
|
readonly 'yt-dlp': "yt-dlp-linux";
|
|
4
4
|
};
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
readonly
|
|
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";
|
|
8
9
|
};
|
package/dist/lib/constants.js
CHANGED
|
@@ -2,8 +2,8 @@ export const STANDARD_RESOLUTIONS = [18, 144, 240, 360, 480, 720, 1080, 1440, 21
|
|
|
2
2
|
export const COMMANDS = {
|
|
3
3
|
'yt-dlp': 'yt-dlp-linux'
|
|
4
4
|
};
|
|
5
|
-
const
|
|
6
|
-
export const
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export const DEFAULT_FILENAME = '%(ytId)s.%(ext)s';
|
|
6
|
+
export const PATTERNS = {
|
|
7
|
+
ID: '%(id)s',
|
|
8
|
+
YT_ID: '%(ytId)s'
|
|
9
9
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function streamLog(type: 'data' | 'err', data: any): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function streamLog(type: 'data' | 'err', data: any): void;
|
package/dist/lib/logs.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PATTERNS } from './constants';
|
|
2
|
+
import { expandPattern } from './expandPattern';
|
|
3
|
+
import { sanitizeFilename } from './sanitizeFilename';
|
|
4
|
+
export function resolveFilename({ filename, id, ytId }) {
|
|
5
|
+
const map = new Map([
|
|
6
|
+
[PATTERNS.ID, id],
|
|
7
|
+
[PATTERNS.YT_ID, ytId]
|
|
8
|
+
]);
|
|
9
|
+
const raw = expandPattern(filename, map);
|
|
10
|
+
return sanitizeFilename(raw);
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sanitizeFilename(raw: string): string;
|
package/dist/lib/spawnAsync.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CommandKey } from '../types/
|
|
1
|
+
import type { CommandKey } from '../types/childProcessTypes';
|
|
2
2
|
export declare function spawnAsync(command: CommandKey, args: string[], showOutput?: boolean): Promise<unknown>;
|
package/dist/lib/spawnAsync.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { COMMANDS } from '../lib/constants';
|
|
3
|
+
import { streamLog } from './logger';
|
|
3
4
|
export function spawnAsync(command, args, showOutput) {
|
|
4
5
|
const _command = COMMANDS[command];
|
|
5
6
|
return new Promise((resolve, reject) => {
|
|
6
|
-
const
|
|
7
|
+
const spawnProcess = spawn(_command, args);
|
|
7
8
|
let stdout = '';
|
|
8
9
|
let stderr = '';
|
|
9
|
-
|
|
10
|
+
spawnProcess.stdout.on('data', (chunk) => {
|
|
10
11
|
stdout += chunk;
|
|
11
12
|
const chunkStr = chunk.toString();
|
|
12
13
|
if (showOutput)
|
|
13
|
-
|
|
14
|
+
streamLog('data', chunkStr);
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
+
spawnProcess.stderr.on('data', (chunk) => {
|
|
16
17
|
stderr += chunk;
|
|
17
18
|
const chunkStr = chunk.toString();
|
|
18
19
|
if (showOutput)
|
|
19
|
-
|
|
20
|
+
streamLog('err', chunkStr);
|
|
20
21
|
});
|
|
21
|
-
|
|
22
|
+
spawnProcess.on('close', (code) => {
|
|
22
23
|
if (code === 0) {
|
|
23
24
|
resolve(stdout.toString());
|
|
24
25
|
}
|
|
@@ -26,7 +27,7 @@ export function spawnAsync(command, args, showOutput) {
|
|
|
26
27
|
reject(new Error(stderr.toString()));
|
|
27
28
|
}
|
|
28
29
|
});
|
|
29
|
-
|
|
30
|
+
spawnProcess.on('error', (err) => {
|
|
30
31
|
reject(err);
|
|
31
32
|
});
|
|
32
33
|
});
|
|
@@ -0,0 +1,3 @@
|
|
|
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>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// import { spawnAsync } from 'src/core/lib/spawnAsync'
|
|
2
|
+
// import type { DownloadOptions } from './interfaces/Downloader'
|
|
3
|
+
import { DEFAULT_FILENAME } from '../../lib/constants';
|
|
4
|
+
import { formYoutubeUrl } from '../../lib/ytUtils';
|
|
5
|
+
import { YtDlpDownloader } from '../../yt-dlp-downloader/YtDlpDownloader';
|
|
6
|
+
export async function downloadVideo(ytId, options) {
|
|
7
|
+
if (!ytId || !options.id)
|
|
8
|
+
return;
|
|
9
|
+
const url = formYoutubeUrl(ytId);
|
|
10
|
+
const taskOptions = formDownloadTaskOptions('video', options);
|
|
11
|
+
return new YtDlpDownloader().download(url, ytId, taskOptions);
|
|
12
|
+
}
|
|
13
|
+
export async function downloadAudio(ytId, options) {
|
|
14
|
+
if (!ytId || !options.id)
|
|
15
|
+
return;
|
|
16
|
+
const url = formYoutubeUrl(ytId);
|
|
17
|
+
const taskOptions = formDownloadTaskOptions('audio', options);
|
|
18
|
+
return new YtDlpDownloader().download(url, ytId, taskOptions);
|
|
19
|
+
}
|
|
20
|
+
function formDownloadTaskOptions(type, options) {
|
|
21
|
+
const taskOptions = {
|
|
22
|
+
id: options.id,
|
|
23
|
+
type,
|
|
24
|
+
outputPath: options.outputPath ?? '.',
|
|
25
|
+
filename: options.filename ?? DEFAULT_FILENAME
|
|
26
|
+
};
|
|
27
|
+
return taskOptions;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DownloadType = 'video' | 'audio';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DownloadType = 'video' | 'audio';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Downloader,
|
|
1
|
+
import type { Downloader, DownloadTasksOptions, DownloadResult } from '../interfaces/Downloader';
|
|
2
2
|
export declare class YtDlpDownloader implements Downloader {
|
|
3
|
-
download(url: string, options:
|
|
3
|
+
download(url: string, ytId: string, options: DownloadTasksOptions): Promise<DownloadResult>;
|
|
4
4
|
private buildYtDlpArgs;
|
|
5
5
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RUTAS } from '../lib/constants';
|
|
2
1
|
import { spawnAsync } from '../lib/spawnAsync';
|
|
2
|
+
import { resolveFilename } from '../lib/resolveFilename';
|
|
3
3
|
export class YtDlpDownloader {
|
|
4
|
-
async download(url, options) {
|
|
5
|
-
const args = this.buildYtDlpArgs(url, options);
|
|
4
|
+
async download(url, ytId, options) {
|
|
5
|
+
const args = this.buildYtDlpArgs(url, ytId, options);
|
|
6
6
|
// const result = await spawnAsync('yt-dlp', args, true)
|
|
7
7
|
await spawnAsync('yt-dlp', args, true);
|
|
8
8
|
return {
|
|
@@ -10,22 +10,18 @@ export class YtDlpDownloader {
|
|
|
10
10
|
path: 'unknown'
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
buildYtDlpArgs(url, options) {
|
|
13
|
+
buildYtDlpArgs(url, ytId, options) {
|
|
14
14
|
const { id, type } = options;
|
|
15
15
|
const isVideo = type === 'video';
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
: 'aac';
|
|
19
|
-
const exportRoute = isVideo
|
|
20
|
-
? RUTAS.VIDEOS_DESCARGADOS
|
|
21
|
-
: RUTAS.AUDIOS_DESCARGADOS;
|
|
22
|
-
const exportName = '%(id)s.%(ext)s';
|
|
16
|
+
const exportRoute = options.outputPath;
|
|
17
|
+
const exportName = resolveFilename({ filename: options.filename, id: options.id, ytId });
|
|
23
18
|
const audioFormat = 'aac';
|
|
19
|
+
const audioFormatPreferences = isVideo
|
|
20
|
+
? []
|
|
21
|
+
: ['-x', '--audio-format', audioFormat];
|
|
24
22
|
const args = [
|
|
25
|
-
'-f',
|
|
26
|
-
...
|
|
27
|
-
? []
|
|
28
|
-
: ['-x', '--audio-format', audioFormat]),
|
|
23
|
+
'-f', id,
|
|
24
|
+
...audioFormatPreferences,
|
|
29
25
|
'-o', exportName,
|
|
30
26
|
'-P', exportRoute,
|
|
31
27
|
url
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function downloadVideo(ytId: string, id: string): Promise<import("../../interfaces/Downloader").DownloadResult | undefined>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { formYoutubeUrl } from '../../lib/ytUtils';
|
|
2
|
-
import { YtDlpDownloader } from '../../yt-dlp-downloader/YtDlpDownloader';
|
|
3
|
-
export async function downloadVideo(ytId, id) {
|
|
4
|
-
if (!ytId || !id)
|
|
5
|
-
return;
|
|
6
|
-
const url = formYoutubeUrl(ytId);
|
|
7
|
-
const options = { id, type: 'video' };
|
|
8
|
-
return new YtDlpDownloader().download(url, options);
|
|
9
|
-
}
|