@yt-kit/core 0.2.1 → 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.
@@ -0,0 +1,4 @@
1
+ export * from '@core/tasks/download/downloadVideo';
2
+ export * from '@core/types/videoTypes';
3
+ export * from '@core/types/processTypes';
4
+ export { STANDARD_RESOLUTIONS } from '@core/lib/constants';
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,2 @@
1
+ import type { CommandKey } from '@core/types/processTypes';
2
+ export declare function spawnAsync(command: CommandKey, args: string[], showOutput?: boolean): Promise<unknown>;
@@ -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,4 @@
1
+ const YOUTUBE_VIDEO_URL = 'https://youtube.com/watch';
2
+ export function formYoutubeUrl(ytId) {
3
+ return `${YOUTUBE_VIDEO_URL}?v=${ytId}`;
4
+ }
@@ -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,3 @@
1
+ import type { COMMANDS } from '@core/lib/constants';
2
+ export type CommandKey = keyof typeof COMMANDS;
3
+ export type Command = typeof COMMANDS[keyof typeof COMMANDS];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { STANDARD_RESOLUTIONS } from '@core/lib/constants';
2
+ export type Height = typeof STANDARD_RESOLUTIONS[number];
3
+ export type Resolution = `${Height}p`;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Downloader, DownloadOptions, DownloadResult } from '@core/interfaces/Downloader';
2
+ export declare class YtDlpDownloader implements Downloader {
3
+ download(url: string, options: DownloadOptions): Promise<DownloadResult>;
4
+ private buildYtDlpArgs;
5
+ }
@@ -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.1",
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
  }
@@ -1,10 +0,0 @@
1
- {
2
- "conventionalCommits.scopes": [
3
- "interface",
4
- "library",
5
- "service",
6
- "step",
7
- "config",
8
- "build"
9
- ]
10
- }
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
@@ -1,5 +0,0 @@
1
- // Acá voy a ir probando el core de primeras, para no tener que navegar mucho para probar el código
2
-
3
- import { downloadVideo } from './src/tasks/download/downloadVideo'
4
-
5
- await downloadVideo('wKVJi-FLvak', '135')
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- // Funcionalidades del programa
2
- export * from '@core/tasks/download/downloadVideo'
3
-
4
- // Tipos
5
- export * from '@core/types/videoTypes'
6
- export * from '@core/types/processTypes'
7
-
8
- // Constantes públicas (seguras de exportar)
9
- export { STANDARD_RESOLUTIONS } from '@core/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
- }
@@ -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
@@ -1,37 +0,0 @@
1
- import { spawn } from 'node:child_process'
2
- import type { CommandKey } from '@core/types/processTypes'
3
- import { COMMANDS } from '@core/lib/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
- }
@@ -1,5 +0,0 @@
1
- const YOUTUBE_VIDEO_URL = 'https://youtube.com/watch'
2
-
3
- export function formYoutubeUrl (ytId: string) {
4
- return `${YOUTUBE_VIDEO_URL}?v=${ytId}`
5
- }
@@ -1,13 +0,0 @@
1
- // import { spawnAsync } from 'src/core/lib/spawnAsync'
2
- import type { DownloadOptions } from '@core/interfaces/Downloader'
3
- import { formYoutubeUrl } from '@core/lib/ytUtils'
4
- import { YtDlpDownloader } from '@core/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
- }
@@ -1,4 +0,0 @@
1
- import type { COMMANDS } from '@core/lib/constants'
2
-
3
- export type CommandKey = keyof typeof COMMANDS
4
- export type Command = typeof COMMANDS[keyof typeof COMMANDS]
@@ -1,4 +0,0 @@
1
- import type { STANDARD_RESOLUTIONS } from '@core/lib/constants'
2
-
3
- export type Height = typeof STANDARD_RESOLUTIONS[number]
4
- export type Resolution = `${Height}p`
@@ -1,47 +0,0 @@
1
- import type { Downloader, DownloadOptions, DownloadResult } from '@core/interfaces/Downloader'
2
- import { RUTAS } from '@core/lib/constants'
3
- import { spawnAsync } from '@core/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
- }
@@ -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,22 +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
- "paths": {
19
- "@core/*": ["src/*"]
20
- }
21
- }
22
- }