@yt-kit/core 0.3.0 → 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 +1 -1
- package/dist/index.js +1 -1
- package/dist/interfaces/Downloader.d.ts +3 -3
- package/dist/lib/constants.d.ts +5 -1
- package/dist/lib/constants.js +5 -1
- 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/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 +1 -1
- package/dist/tasks/download/download.js +4 -4
- package/dist/types/childProcessTypes.d.ts +3 -0
- package/dist/types/childProcessTypes.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 +1 -1
- package/dist/yt-dlp-downloader/YtDlpDownloader.js +6 -5
- package/package.json +1 -1
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
package/dist/index.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
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,15 +1,15 @@
|
|
|
1
1
|
export interface Downloader {
|
|
2
|
-
download(url: string, options: DownloadTasksOptions): Promise<DownloadResult>;
|
|
2
|
+
download(url: string, ytId: string, options: DownloadTasksOptions): Promise<DownloadResult>;
|
|
3
3
|
}
|
|
4
4
|
export interface DownloadOptions {
|
|
5
5
|
id: string;
|
|
6
|
-
|
|
6
|
+
outputPath?: string;
|
|
7
7
|
filename?: string;
|
|
8
8
|
}
|
|
9
9
|
export interface DownloadTasksOptions {
|
|
10
10
|
id: string;
|
|
11
11
|
type: 'video' | 'audio';
|
|
12
|
-
|
|
12
|
+
outputPath: string;
|
|
13
13
|
filename: string;
|
|
14
14
|
}
|
|
15
15
|
export interface DownloadResult {
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -2,4 +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 DEFAULT_FILENAME = "%(
|
|
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
|
+
};
|
package/dist/lib/constants.js
CHANGED
|
@@ -2,4 +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
|
-
export const DEFAULT_FILENAME = '%(
|
|
5
|
+
export const DEFAULT_FILENAME = '%(ytId)s.%(ext)s';
|
|
6
|
+
export const PATTERNS = {
|
|
7
|
+
ID: '%(id)s',
|
|
8
|
+
YT_ID: '%(ytId)s'
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function streamLog(type: 'data' | 'err', data: any): void;
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { COMMANDS } from '../lib/constants';
|
|
3
|
-
import { streamLog } from './
|
|
3
|
+
import { streamLog } from './logger';
|
|
4
4
|
export function spawnAsync(command, args, showOutput) {
|
|
5
5
|
const _command = COMMANDS[command];
|
|
6
6
|
return new Promise((resolve, reject) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// import { spawnAsync } from 'src/core/lib/spawnAsync'
|
|
2
2
|
// import type { DownloadOptions } from './interfaces/Downloader'
|
|
3
|
-
import { DEFAULT_FILENAME } from '
|
|
3
|
+
import { DEFAULT_FILENAME } from '../../lib/constants';
|
|
4
4
|
import { formYoutubeUrl } from '../../lib/ytUtils';
|
|
5
5
|
import { YtDlpDownloader } from '../../yt-dlp-downloader/YtDlpDownloader';
|
|
6
6
|
export async function downloadVideo(ytId, options) {
|
|
@@ -8,20 +8,20 @@ export async function downloadVideo(ytId, options) {
|
|
|
8
8
|
return;
|
|
9
9
|
const url = formYoutubeUrl(ytId);
|
|
10
10
|
const taskOptions = formDownloadTaskOptions('video', options);
|
|
11
|
-
return new YtDlpDownloader().download(url, taskOptions);
|
|
11
|
+
return new YtDlpDownloader().download(url, ytId, taskOptions);
|
|
12
12
|
}
|
|
13
13
|
export async function downloadAudio(ytId, options) {
|
|
14
14
|
if (!ytId || !options.id)
|
|
15
15
|
return;
|
|
16
16
|
const url = formYoutubeUrl(ytId);
|
|
17
17
|
const taskOptions = formDownloadTaskOptions('audio', options);
|
|
18
|
-
return new YtDlpDownloader().download(url, taskOptions);
|
|
18
|
+
return new YtDlpDownloader().download(url, ytId, taskOptions);
|
|
19
19
|
}
|
|
20
20
|
function formDownloadTaskOptions(type, options) {
|
|
21
21
|
const taskOptions = {
|
|
22
22
|
id: options.id,
|
|
23
23
|
type,
|
|
24
|
-
|
|
24
|
+
outputPath: options.outputPath ?? '.',
|
|
25
25
|
filename: options.filename ?? DEFAULT_FILENAME
|
|
26
26
|
};
|
|
27
27
|
return taskOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DownloadType = 'video' | 'audio';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Downloader, DownloadTasksOptions, DownloadResult } from '../interfaces/Downloader';
|
|
2
2
|
export declare class YtDlpDownloader implements Downloader {
|
|
3
|
-
download(url: string, options: DownloadTasksOptions): Promise<DownloadResult>;
|
|
3
|
+
download(url: string, ytId: string, options: DownloadTasksOptions): Promise<DownloadResult>;
|
|
4
4
|
private buildYtDlpArgs;
|
|
5
5
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { spawnAsync } from '../lib/spawnAsync';
|
|
2
|
+
import { resolveFilename } from '../lib/resolveFilename';
|
|
2
3
|
export class YtDlpDownloader {
|
|
3
|
-
async download(url, options) {
|
|
4
|
-
const args = this.buildYtDlpArgs(url, options);
|
|
4
|
+
async download(url, ytId, options) {
|
|
5
|
+
const args = this.buildYtDlpArgs(url, ytId, options);
|
|
5
6
|
// const result = await spawnAsync('yt-dlp', args, true)
|
|
6
7
|
await spawnAsync('yt-dlp', args, true);
|
|
7
8
|
return {
|
|
@@ -9,11 +10,11 @@ export class YtDlpDownloader {
|
|
|
9
10
|
path: 'unknown'
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
|
-
buildYtDlpArgs(url, options) {
|
|
13
|
+
buildYtDlpArgs(url, ytId, options) {
|
|
13
14
|
const { id, type } = options;
|
|
14
15
|
const isVideo = type === 'video';
|
|
15
|
-
const exportRoute = options.
|
|
16
|
-
const exportName = options.filename;
|
|
16
|
+
const exportRoute = options.outputPath;
|
|
17
|
+
const exportName = resolveFilename({ filename: options.filename, id: options.id, ytId });
|
|
17
18
|
const audioFormat = 'aac';
|
|
18
19
|
const audioFormatPreferences = isVideo
|
|
19
20
|
? []
|