@yt-kit/core 0.2.0 → 0.2.2
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 +4 -0
- package/dist/index.js +7 -0
- package/dist/interfaces/Downloader.d.ts +11 -0
- package/dist/interfaces/Downloader.js +1 -0
- package/dist/lib/constants.d.ts +8 -0
- package/dist/lib/constants.js +9 -0
- package/dist/lib/spawnAsync.d.ts +2 -0
- package/dist/lib/spawnAsync.js +33 -0
- package/dist/lib/ytUtils.d.ts +1 -0
- package/dist/lib/ytUtils.js +4 -0
- package/dist/tasks/download/downloadVideo.d.ts +1 -0
- package/dist/tasks/download/downloadVideo.js +9 -0
- package/dist/types/processTypes.d.ts +3 -0
- package/dist/types/processTypes.js +1 -0
- package/dist/types/videoTypes.d.ts +3 -0
- package/dist/types/videoTypes.js +1 -0
- package/dist/yt-dlp-downloader/YtDlpDownloader.d.ts +5 -0
- package/dist/yt-dlp-downloader/YtDlpDownloader.js +35 -0
- package/package.json +5 -2
- package/.vscode/settings.json +0 -10
- package/eslint.config.mts +0 -25
- package/pruebas.ts +0 -5
- package/src/index.ts +0 -9
- package/src/interfaces/Downloader.ts +0 -13
- package/src/lib/constants.ts +0 -12
- package/src/lib/spawnAsync.ts +0 -37
- package/src/lib/ytUtils.ts +0 -5
- package/src/tasks/download/downloadVideo.ts +0 -13
- package/src/types/processTypes.ts +0 -4
- package/src/types/videoTypes.ts +0 -4
- package/src/yt-dlp-downloader/YtDlpDownloader.ts +0 -47
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -19
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Funcionalidades del programa
|
|
2
|
+
export * from '@core/tasks/download/downloadVideo';
|
|
3
|
+
// Tipos
|
|
4
|
+
export * from '@core/types/videoTypes';
|
|
5
|
+
export * from '@core/types/processTypes';
|
|
6
|
+
// Constantes públicas (seguras de exportar)
|
|
7
|
+
export { STANDARD_RESOLUTIONS } from '@core/lib/constants';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface Downloader {
|
|
2
|
+
download(url: string, options: DownloadOptions): Promise<DownloadResult>;
|
|
3
|
+
}
|
|
4
|
+
export interface DownloadOptions {
|
|
5
|
+
id: string;
|
|
6
|
+
type: 'video' | 'audio';
|
|
7
|
+
}
|
|
8
|
+
export interface DownloadResult {
|
|
9
|
+
path: string;
|
|
10
|
+
duration: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
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-linux";
|
|
4
|
+
};
|
|
5
|
+
export declare const RUTAS: {
|
|
6
|
+
readonly VIDEOS_DESCARGADOS: "/home/mango/Dev/yt-kit/storage/videos_descargados";
|
|
7
|
+
readonly AUDIOS_DESCARGADOS: "/home/mango/Dev/yt-kit/storage/audios_descargados";
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const STANDARD_RESOLUTIONS = [18, 144, 240, 360, 480, 720, 1080, 1440, 2160];
|
|
2
|
+
export const COMMANDS = {
|
|
3
|
+
'yt-dlp': 'yt-dlp-linux'
|
|
4
|
+
};
|
|
5
|
+
const KWD = '/home/mango/Dev/yt-kit'; // KWD: [K]it [W]orking [D]irectory
|
|
6
|
+
export const RUTAS = {
|
|
7
|
+
VIDEOS_DESCARGADOS: `${KWD}/storage/videos_descargados`,
|
|
8
|
+
AUDIOS_DESCARGADOS: `${KWD}/storage/audios_descargados`
|
|
9
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { COMMANDS } from '@core/lib/constants';
|
|
3
|
+
export function spawnAsync(command, args, showOutput) {
|
|
4
|
+
const _command = COMMANDS[command];
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const process = spawn(_command, args);
|
|
7
|
+
let stdout = '';
|
|
8
|
+
let stderr = '';
|
|
9
|
+
process.stdout.on('data', (chunk) => {
|
|
10
|
+
stdout += chunk;
|
|
11
|
+
const chunkStr = chunk.toString();
|
|
12
|
+
if (showOutput)
|
|
13
|
+
console.log(chunkStr);
|
|
14
|
+
});
|
|
15
|
+
process.stderr.on('data', (chunk) => {
|
|
16
|
+
stderr += chunk;
|
|
17
|
+
const chunkStr = chunk.toString();
|
|
18
|
+
if (showOutput)
|
|
19
|
+
console.log(chunkStr);
|
|
20
|
+
});
|
|
21
|
+
process.on('close', (code) => {
|
|
22
|
+
if (code === 0) {
|
|
23
|
+
resolve(stdout.toString());
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
reject(new Error(stderr.toString()));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
process.on('error', (err) => {
|
|
30
|
+
reject(err);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formYoutubeUrl(ytId: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadVideo(ytId: string, id: string): Promise<import("@core/interfaces/Downloader").DownloadResult | undefined>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { formYoutubeUrl } from '@core/lib/ytUtils';
|
|
2
|
+
import { YtDlpDownloader } from '@core/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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RUTAS } from '@core/lib/constants';
|
|
2
|
+
import { spawnAsync } from '@core/lib/spawnAsync';
|
|
3
|
+
export class YtDlpDownloader {
|
|
4
|
+
async download(url, options) {
|
|
5
|
+
const args = this.buildYtDlpArgs(url, options);
|
|
6
|
+
// const result = await spawnAsync('yt-dlp', args, true)
|
|
7
|
+
await spawnAsync('yt-dlp', args, true);
|
|
8
|
+
return {
|
|
9
|
+
duration: -1,
|
|
10
|
+
path: 'unknown'
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
buildYtDlpArgs(url, options) {
|
|
14
|
+
const { id, type } = options;
|
|
15
|
+
const isVideo = type === 'video';
|
|
16
|
+
const ext = isVideo
|
|
17
|
+
? 'mp4'
|
|
18
|
+
: 'aac';
|
|
19
|
+
const exportRoute = isVideo
|
|
20
|
+
? RUTAS.VIDEOS_DESCARGADOS
|
|
21
|
+
: RUTAS.AUDIOS_DESCARGADOS;
|
|
22
|
+
const exportName = '%(id)s.%(ext)s';
|
|
23
|
+
const audioFormat = 'aac';
|
|
24
|
+
const args = [
|
|
25
|
+
'-f', `${id}/${ext}`,
|
|
26
|
+
...(isVideo
|
|
27
|
+
? []
|
|
28
|
+
: ['-x', '--audio-format', audioFormat]),
|
|
29
|
+
'-o', exportName,
|
|
30
|
+
'-P', exportRoute,
|
|
31
|
+
url
|
|
32
|
+
];
|
|
33
|
+
return args;
|
|
34
|
+
}
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yt-kit/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -28,5 +28,8 @@
|
|
|
28
28
|
"typescript-eslint": "8.48.1",
|
|
29
29
|
"@types/bun": "latest",
|
|
30
30
|
"@types/node": "24.3.0"
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
]
|
|
32
35
|
}
|
package/.vscode/settings.json
DELETED
package/eslint.config.mts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js'
|
|
2
|
-
import globals from 'globals'
|
|
3
|
-
import tseslint from 'typescript-eslint'
|
|
4
|
-
import { defineConfig } from 'eslint/config'
|
|
5
|
-
import stylistic from '@stylistic/eslint-plugin'
|
|
6
|
-
|
|
7
|
-
export default defineConfig([
|
|
8
|
-
{ files: ['**/*.{js,mjs,cjs,ts,mts,cts}'], plugins: { js }, extends: ['js/recommended'], languageOptions: { globals: globals.node } },
|
|
9
|
-
tseslint.configs.recommended,
|
|
10
|
-
{
|
|
11
|
-
plugins: {
|
|
12
|
-
'@stylistic': stylistic
|
|
13
|
-
},
|
|
14
|
-
rules: {
|
|
15
|
-
'no-empty-pattern': 'off',
|
|
16
|
-
'@stylistic/quotes': ['error', 'single'],
|
|
17
|
-
'semi': ['error', 'never'],
|
|
18
|
-
'comma-dangle': ['error', 'never'],
|
|
19
|
-
'@stylistic/eol-last': ['error', 'always'],
|
|
20
|
-
'@typescript-eslint/consistent-type-imports': 'error',
|
|
21
|
-
'space-before-function-paren': ['error', 'always'],
|
|
22
|
-
'@stylistic/arrow-parens': ['error', 'always']
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
])
|
package/pruebas.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Funcionalidades del programa
|
|
2
|
-
export * from './tasks/download/downloadVideo'
|
|
3
|
-
|
|
4
|
-
// Tipos
|
|
5
|
-
export * from './types/videoTypes'
|
|
6
|
-
export * from './types/processTypes'
|
|
7
|
-
|
|
8
|
-
// Constantes públicas (seguras de exportar)
|
|
9
|
-
export { STANDARD_RESOLUTIONS } from './lib/constants'
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface Downloader {
|
|
2
|
-
download (url: string, options: DownloadOptions): Promise<DownloadResult>
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export interface DownloadOptions {
|
|
6
|
-
id: string
|
|
7
|
-
type: 'video' | 'audio'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface DownloadResult {
|
|
11
|
-
path: string
|
|
12
|
-
duration: number
|
|
13
|
-
}
|
package/src/lib/constants.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const STANDARD_RESOLUTIONS = [18, 144, 240, 360, 480, 720, 1080, 1440, 2160] as const
|
|
2
|
-
|
|
3
|
-
export const COMMANDS = {
|
|
4
|
-
'yt-dlp': 'yt-dlp-linux'
|
|
5
|
-
} as const
|
|
6
|
-
|
|
7
|
-
const KWD = '/home/mango/Dev/yt-kit' as const // KWD: [K]it [W]orking [D]irectory
|
|
8
|
-
|
|
9
|
-
export const RUTAS = {
|
|
10
|
-
VIDEOS_DESCARGADOS: `${KWD}/storage/videos_descargados`,
|
|
11
|
-
AUDIOS_DESCARGADOS: `${KWD}/storage/audios_descargados`
|
|
12
|
-
} as const
|
package/src/lib/spawnAsync.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process'
|
|
2
|
-
import type { CommandKey } from '../types/processTypes'
|
|
3
|
-
import { COMMANDS } from './constants'
|
|
4
|
-
|
|
5
|
-
export function spawnAsync (command: CommandKey, args: string[], showOutput?: boolean) {
|
|
6
|
-
const _command = COMMANDS[command]
|
|
7
|
-
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const process = spawn(_command, args)
|
|
10
|
-
let stdout = ''
|
|
11
|
-
let stderr = ''
|
|
12
|
-
|
|
13
|
-
process.stdout.on('data', (chunk) => {
|
|
14
|
-
stdout += chunk
|
|
15
|
-
const chunkStr = chunk.toString()
|
|
16
|
-
if (showOutput) console.log(chunkStr)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
process.stderr.on('data', (chunk) => {
|
|
20
|
-
stderr += chunk
|
|
21
|
-
const chunkStr = chunk.toString()
|
|
22
|
-
if (showOutput) console.log(chunkStr)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
process.on('close', (code) => {
|
|
26
|
-
if (code === 0) {
|
|
27
|
-
resolve(stdout.toString())
|
|
28
|
-
} else {
|
|
29
|
-
reject(new Error(stderr.toString()))
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
process.on('error', (err) => {
|
|
34
|
-
reject(err)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
}
|
package/src/lib/ytUtils.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// import { spawnAsync } from 'src/core/lib/spawnAsync'
|
|
2
|
-
import type { DownloadOptions } from 'src/interfaces/Downloader'
|
|
3
|
-
import { formYoutubeUrl } from 'src/lib/ytUtils'
|
|
4
|
-
import { YtDlpDownloader } from 'src/yt-dlp-downloader/YtDlpDownloader'
|
|
5
|
-
|
|
6
|
-
export async function downloadVideo (ytId: string, id: string) {
|
|
7
|
-
if (!ytId || !id) return
|
|
8
|
-
|
|
9
|
-
const url = formYoutubeUrl(ytId)
|
|
10
|
-
const options: DownloadOptions = { id, type: 'video' }
|
|
11
|
-
|
|
12
|
-
return new YtDlpDownloader().download(url, options)
|
|
13
|
-
}
|
package/src/types/videoTypes.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Downloader, DownloadOptions, DownloadResult } from '../interfaces/Downloader'
|
|
2
|
-
import { RUTAS } from '../lib/constants'
|
|
3
|
-
import { spawnAsync } from '../lib/spawnAsync'
|
|
4
|
-
|
|
5
|
-
export class YtDlpDownloader implements Downloader {
|
|
6
|
-
async download (url: string, options: DownloadOptions): Promise<DownloadResult> {
|
|
7
|
-
const args = this.buildYtDlpArgs(url, options)
|
|
8
|
-
|
|
9
|
-
// const result = await spawnAsync('yt-dlp', args, true)
|
|
10
|
-
await spawnAsync('yt-dlp', args, true)
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
duration: -1,
|
|
14
|
-
path: 'unknown'
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private buildYtDlpArgs (url: string, options: DownloadOptions) {
|
|
19
|
-
const { id, type } = options
|
|
20
|
-
const isVideo = type === 'video'
|
|
21
|
-
|
|
22
|
-
const ext = isVideo
|
|
23
|
-
? 'mp4'
|
|
24
|
-
: 'aac'
|
|
25
|
-
|
|
26
|
-
const exportRoute = isVideo
|
|
27
|
-
? RUTAS.VIDEOS_DESCARGADOS
|
|
28
|
-
: RUTAS.AUDIOS_DESCARGADOS
|
|
29
|
-
|
|
30
|
-
const exportName = '%(id)s.%(ext)s'
|
|
31
|
-
|
|
32
|
-
const audioFormat = 'aac'
|
|
33
|
-
|
|
34
|
-
const args = [
|
|
35
|
-
'-f', `${id}/${ext}`,
|
|
36
|
-
...(isVideo
|
|
37
|
-
? []
|
|
38
|
-
: ['-x', '--audio-format', audioFormat]
|
|
39
|
-
),
|
|
40
|
-
'-o', exportName,
|
|
41
|
-
'-P', exportRoute,
|
|
42
|
-
url
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
return args
|
|
46
|
-
}
|
|
47
|
-
}
|
package/tsconfig.build.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"noEmit": false,
|
|
5
|
-
"emitDeclarationOnly": false,
|
|
6
|
-
"allowImportingTsExtensions": false,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"module": "ESNext",
|
|
10
|
-
"moduleResolution": "Node",
|
|
11
|
-
"stripInternal": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src"]
|
|
14
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"],
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "Preserve",
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"allowImportingTsExtensions": true,
|
|
9
|
-
"verbatimModuleSyntax": true,
|
|
10
|
-
"noEmit": true,
|
|
11
|
-
|
|
12
|
-
"strict": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
|
|
15
|
-
"esModuleInterop": true,
|
|
16
|
-
"resolveJsonModule": true,
|
|
17
|
-
"baseUrl": "."
|
|
18
|
-
}
|
|
19
|
-
}
|