@yt-kit/core 0.5.0 → 0.5.1

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,4 +1,6 @@
1
- export * from './tasks/download/download';
1
+ export { downloadAudio, downloadVideo } from './tasks/download/download';
2
+ export { findFormatId } from './yt-dlp/findFormatId';
3
+ export { formYoutubeUrl } from './lib/ytUtils';
2
4
  export * from './types/videoTypes';
3
5
  export * from './types/childProcessTypes';
4
6
  export { STANDARD_RESOLUTIONS } from './lib/constants';
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  // Funcionalidades del programa
2
- export * from './tasks/download/download';
2
+ export { downloadAudio, downloadVideo } from './tasks/download/download';
3
+ export { findFormatId } from './yt-dlp/findFormatId';
4
+ // Utilidades
5
+ export { formYoutubeUrl } from './lib/ytUtils';
3
6
  // Tipos
4
7
  export * from './types/videoTypes';
5
8
  export * from './types/childProcessTypes';
@@ -0,0 +1,7 @@
1
+ import type { FormatsToFind } from '../types/videoTypes';
2
+ import type { YtDlpFormat } from '../types/ytDlpFormatTypes';
3
+ export declare function findFormatId(url: string, formatToFind: FormatsToFind): Promise<{
4
+ foundSpecific: string | boolean;
5
+ formatId: string | undefined;
6
+ desiredFormat: YtDlpFormat | undefined;
7
+ }>;
@@ -0,0 +1,61 @@
1
+ import { getBetterFormat, getWorstFormat } from '../lib/compareFormats';
2
+ import { spawnAsync } from '../lib/spawnAsync';
3
+ export async function findFormatId(url, formatToFind) {
4
+ const isSpecificResolution = Boolean(formatToFind.match(/\d/));
5
+ let foundSpecific = isSpecificResolution ? false : 'N/A';
6
+ const args = ['--print', '%(formats)j', url];
7
+ let output = '';
8
+ try {
9
+ output = await spawnAsync('yt-dlp', args);
10
+ }
11
+ catch (err) {
12
+ console.error('Error consiguiendo el ID del formato');
13
+ throw err;
14
+ }
15
+ let formats = [];
16
+ try {
17
+ formats = JSON.parse(output);
18
+ }
19
+ catch (err) {
20
+ console.error('Error convirtiendo la salida de yt-dlp a JSON');
21
+ throw err;
22
+ }
23
+ if (!Array.isArray(formats)) {
24
+ throw new Error('Se esperaba un array');
25
+ }
26
+ let bestVideo = undefined;
27
+ let worstVideo = undefined;
28
+ let bestAudio = undefined;
29
+ let worstAudio = undefined;
30
+ let desiredFormat = undefined;
31
+ for (const format of formats) {
32
+ const audioOnly = format.resolution === 'audio only';
33
+ if (isSpecificResolution && format.format_note === formatToFind) {
34
+ foundSpecific = true;
35
+ desiredFormat = getBetterFormat(desiredFormat, format, { compareResolution: false, type: 'video' }) ?? format;
36
+ continue;
37
+ }
38
+ if (audioOnly) {
39
+ bestAudio = getBetterFormat(bestAudio, format, { compareResolution: false, type: 'audio' }) ?? format;
40
+ worstAudio = getWorstFormat(worstAudio, format, { compareResolution: false, type: 'audio' }) ?? format;
41
+ }
42
+ else {
43
+ bestVideo = getBetterFormat(bestVideo, format, { compareResolution: true, type: 'video' }) ?? format;
44
+ worstVideo = getWorstFormat(worstVideo, format, { compareResolution: true, type: 'video' }) ?? format;
45
+ }
46
+ }
47
+ if (!isSpecificResolution) {
48
+ const formats = {
49
+ 'best-video': bestVideo,
50
+ 'worst-video': worstVideo,
51
+ 'best-audio': bestAudio,
52
+ 'worst-audio': worstAudio
53
+ };
54
+ desiredFormat = formats[formatToFind];
55
+ }
56
+ return {
57
+ foundSpecific,
58
+ formatId: desiredFormat?.format_id,
59
+ desiredFormat
60
+ };
61
+ }
@@ -1,12 +1,5 @@
1
1
  import type { Downloader, DownloadTasksOptions, DownloadResult } from '../interfaces/Downloader';
2
- import type { FormatsToFind } from '../types/videoTypes';
3
- import type { YtDlpFormat } from '../types/ytDlpFormatTypes';
4
2
  export declare class YtDlpDownloader implements Downloader {
5
3
  download(url: string, ytId: string, options: DownloadTasksOptions): Promise<DownloadResult>;
6
- findFormatId(url: string, formatToFind: FormatsToFind): Promise<{
7
- foundSpecific: string | boolean;
8
- formatId: string | undefined;
9
- desiredFormat: YtDlpFormat | undefined;
10
- }>;
11
4
  private buildYtDlpArgs;
12
5
  }
@@ -1,6 +1,5 @@
1
1
  import { spawnAsync } from '../lib/spawnAsync';
2
2
  import { resolveFilename } from '../lib/resolveFilename';
3
- import { getBetterFormat, getWorstFormat } from '../lib/compareFormats';
4
3
  export class YtDlpDownloader {
5
4
  async download(url, ytId, options) {
6
5
  const args = this.buildYtDlpArgs(url, ytId, options);
@@ -11,65 +10,6 @@ export class YtDlpDownloader {
11
10
  path: 'unknown'
12
11
  };
13
12
  }
14
- async findFormatId(url, formatToFind) {
15
- const isSpecificResolution = Boolean(formatToFind.match(/\d/));
16
- let foundSpecific = isSpecificResolution ? false : 'N/A';
17
- const args = ['--print', '%(formats)j', url];
18
- let output = '';
19
- try {
20
- output = await spawnAsync('yt-dlp', args);
21
- }
22
- catch (err) {
23
- console.error('Error consiguiendo el ID del formato');
24
- throw err;
25
- }
26
- let formats = [];
27
- try {
28
- formats = JSON.parse(output);
29
- }
30
- catch (err) {
31
- console.error('Error convirtiendo la salida de yt-dlp a JSON');
32
- throw err;
33
- }
34
- if (!Array.isArray(formats)) {
35
- throw new Error('Se esperaba un array');
36
- }
37
- let bestVideo = undefined;
38
- let worstVideo = undefined;
39
- let bestAudio = undefined;
40
- let worstAudio = undefined;
41
- let desiredFormat = undefined;
42
- for (const format of formats) {
43
- const audioOnly = format.resolution === 'audio only';
44
- if (isSpecificResolution && format.format_note === formatToFind) {
45
- foundSpecific = true;
46
- desiredFormat = getBetterFormat(desiredFormat, format, { compareResolution: false, type: 'video' }) ?? format;
47
- continue;
48
- }
49
- if (audioOnly) {
50
- bestAudio = getBetterFormat(bestAudio, format, { compareResolution: false, type: 'audio' }) ?? format;
51
- worstAudio = getWorstFormat(worstAudio, format, { compareResolution: false, type: 'audio' }) ?? format;
52
- }
53
- else {
54
- bestVideo = getBetterFormat(bestVideo, format, { compareResolution: true, type: 'video' }) ?? format;
55
- worstVideo = getWorstFormat(worstVideo, format, { compareResolution: true, type: 'video' }) ?? format;
56
- }
57
- }
58
- if (!isSpecificResolution) {
59
- const formats = {
60
- 'best-video': bestVideo,
61
- 'worst-video': worstVideo,
62
- 'best-audio': bestAudio,
63
- 'worst-audio': worstAudio
64
- };
65
- desiredFormat = formats[formatToFind];
66
- }
67
- return {
68
- foundSpecific,
69
- formatId: desiredFormat?.format_id,
70
- desiredFormat
71
- };
72
- }
73
13
  buildYtDlpArgs(url, ytId, options) {
74
14
  const { id, type } = options;
75
15
  const isVideo = type === 'video';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yt-kit/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -11,16 +11,24 @@
11
11
  "types": "./dist/index.d.ts"
12
12
  }
13
13
  },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/ubiufboeuf/yt-kit.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/ubiufboeuf/yt-kit/issues"
20
+ },
21
+ "homepage": "https://github.com/ubiufboeuf/yt-kit#readme",
14
22
  "scripts": {
15
23
  "start": "bun pruebas.ts",
16
24
  "build": "tsc -p tsconfig.build.json",
17
25
  "prepublishOnly": "bun run build"
18
26
  },
19
27
  "dependencies": {
20
- "eslint": "9.39.1",
21
28
  "typescript": "5"
22
29
  },
23
30
  "devDependencies": {
31
+ "eslint": "9.39.1",
24
32
  "@eslint/js": "9.39.1",
25
33
  "@stylistic/eslint-plugin": "5.6.1",
26
34
  "globals": "16.5.0",
@@ -32,4 +40,4 @@
32
40
  "files": [
33
41
  "dist"
34
42
  ]
35
- }
43
+ }