@blagoja/ts-dlp 0.1.2 → 0.1.3

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 CHANGED
@@ -117,11 +117,11 @@ await ytdlp
117
117
  - [x] `.download(url)`
118
118
  - [x] `.run()`
119
119
  - [x] `.output(path)`
120
- - [ ] `.format(format)`
120
+ - [x] `.format(format)`
121
121
  - [x] `.audio()`
122
122
  - [ ] `.video()`
123
123
  - [x] `.resolution()`
124
- - [ ] `.fps()`
124
+ - [x] `.fps()`
125
125
 
126
126
  Example:
127
127
 
package/dist/index.cjs CHANGED
@@ -51,6 +51,26 @@ var DownloadBuilder = class {
51
51
  audioFormat;
52
52
  outputDir;
53
53
  filenameTemplate;
54
+ videoExt;
55
+ videoFps;
56
+ videoHeight;
57
+ buildArgs() {
58
+ const args = [...this.args];
59
+ if (this.videoHeight || this.videoFps || this.videoExt || this.audioFormat) {
60
+ const heightFilter = this.videoHeight ? `[height<=${this.videoHeight}]` : "";
61
+ const fpsFilter = this.videoFps ? `[fps<=${this.videoFps}]` : "";
62
+ const extFilter = this.videoExt ? `[ext=${this.videoExt}]` : "";
63
+ const video = `bestvideo${heightFilter}${fpsFilter}${extFilter}`;
64
+ const audio = this.audioFormat ?? "bestaudio";
65
+ args.push("-f", `${video}+${audio}/best`);
66
+ }
67
+ if (this.outputDir || this.filenameTemplate) {
68
+ const dir = this.outputDir ?? "";
69
+ const file = this.filenameTemplate ?? "%(title)s.%(ext)s";
70
+ args.push("-o", dir ? `${dir}/${file}` : file);
71
+ }
72
+ return args;
73
+ }
54
74
  /**
55
75
  * Set the desired resolution for the video download.
56
76
  * The method will automatically select the best video format that is less than or equal to the specified resolution.
@@ -60,8 +80,7 @@ var DownloadBuilder = class {
60
80
  * @returns The current instance of DownloadBuilder for method chaining.
61
81
  */
62
82
  resolution(res) {
63
- const height = res.replace("p", "");
64
- this.videoFormat = `bestvideo[height<=${height}]`;
83
+ this.videoHeight = res.replace("p", "");
65
84
  return this;
66
85
  }
67
86
  /**
@@ -98,6 +117,27 @@ var DownloadBuilder = class {
98
117
  this.audioFormat = codec ? `bestaudio[ext=${codec}]` : "bestaudio";
99
118
  return this;
100
119
  }
120
+ /**
121
+ * Set the desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc.
122
+ * If specified, the method will select the best available video format that matches the specified extension.
123
+ * If not specified, it will select the best available video format regardless of extension.
124
+ *
125
+ * @example
126
+ * download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
127
+ * .format("mp4")
128
+ * .run();
129
+ *
130
+ * @param ext The desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc. If specified, the method will select the best available video format that matches the specified extension. If not specified, it will select the best available video format regardless of extension.
131
+ * @returns The current instance of DownloadBuilder for method chaining.
132
+ */
133
+ format(ext) {
134
+ this.videoExt = ext;
135
+ return this;
136
+ }
137
+ fps(fps) {
138
+ this.videoFps = fps;
139
+ return this;
140
+ }
101
141
  /**
102
142
  * Set the filename template for the downloaded file.
103
143
  * The callback receives common output fields as named parameters which are
@@ -145,17 +185,7 @@ var DownloadBuilder = class {
145
185
  *
146
186
  */
147
187
  async run() {
148
- const args = [...this.args];
149
- if (this.videoFormat || this.audioFormat) {
150
- const video = this.videoFormat ?? "bestvideo";
151
- const audio = this.audioFormat ?? "bestaudio";
152
- args.push("-f", `${video}+${audio}/best`);
153
- }
154
- if (this.outputDir || this.filenameTemplate) {
155
- const dir = this.outputDir ?? "";
156
- const file = this.filenameTemplate ?? "%(title)s.%(ext)s";
157
- args.push("-o", dir ? `${dir}/${file}` : file);
158
- }
188
+ const args = this.buildArgs();
159
189
  await runYtDlp([...args, this.url]);
160
190
  }
161
191
  };
package/dist/index.d.cts CHANGED
@@ -1,4 +1,7 @@
1
- type Resolution = "144p" | "240p" | "360p" | "480p" | "720p" | "1080p" | "1440p" | "2160p" | (string & {});
1
+ type LiteralUnion<T extends string> = T | (string & {});
2
+ type Resolution = LiteralUnion<"144p" | "240p" | "360p" | "480p" | "720p" | "1080p" | "1440p" | "2160p">;
3
+ type AudioCodec = LiteralUnion<"opus" | "aac" | "m4a" | "mp3" | "flac" | "wav">;
4
+ type VideoExt = LiteralUnion<"mp4" | "mov" | "webm" | "flv" | "mkv" | "avi">;
2
5
  type OutputFields = {
3
6
  title: string;
4
7
  ext: string;
@@ -20,7 +23,6 @@ type OutputFields = {
20
23
  playlist_index: string;
21
24
  autonumber: string;
22
25
  };
23
- type AudioCodec = "opus" | "aac" | "m4a" | "mp3" | "flac" | "wav" | (string & {});
24
26
 
25
27
  declare class DownloadBuilder {
26
28
  private readonly url;
@@ -29,7 +31,11 @@ declare class DownloadBuilder {
29
31
  private audioFormat?;
30
32
  private outputDir?;
31
33
  private filenameTemplate?;
34
+ private videoExt?;
35
+ private videoFps?;
36
+ private videoHeight?;
32
37
  constructor(url: string);
38
+ private buildArgs;
33
39
  /**
34
40
  * Set the desired resolution for the video download.
35
41
  * The method will automatically select the best video format that is less than or equal to the specified resolution.
@@ -67,6 +73,21 @@ declare class DownloadBuilder {
67
73
  * @returns The current instance of DownloadBuilder for method chaining.
68
74
  */
69
75
  audio(codec?: AudioCodec): this;
76
+ /**
77
+ * Set the desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc.
78
+ * If specified, the method will select the best available video format that matches the specified extension.
79
+ * If not specified, it will select the best available video format regardless of extension.
80
+ *
81
+ * @example
82
+ * download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
83
+ * .format("mp4")
84
+ * .run();
85
+ *
86
+ * @param ext The desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc. If specified, the method will select the best available video format that matches the specified extension. If not specified, it will select the best available video format regardless of extension.
87
+ * @returns The current instance of DownloadBuilder for method chaining.
88
+ */
89
+ format(ext: VideoExt): this;
90
+ fps(fps: number): this;
70
91
  /**
71
92
  * Set the filename template for the downloaded file.
72
93
  * The callback receives common output fields as named parameters which are
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- type Resolution = "144p" | "240p" | "360p" | "480p" | "720p" | "1080p" | "1440p" | "2160p" | (string & {});
1
+ type LiteralUnion<T extends string> = T | (string & {});
2
+ type Resolution = LiteralUnion<"144p" | "240p" | "360p" | "480p" | "720p" | "1080p" | "1440p" | "2160p">;
3
+ type AudioCodec = LiteralUnion<"opus" | "aac" | "m4a" | "mp3" | "flac" | "wav">;
4
+ type VideoExt = LiteralUnion<"mp4" | "mov" | "webm" | "flv" | "mkv" | "avi">;
2
5
  type OutputFields = {
3
6
  title: string;
4
7
  ext: string;
@@ -20,7 +23,6 @@ type OutputFields = {
20
23
  playlist_index: string;
21
24
  autonumber: string;
22
25
  };
23
- type AudioCodec = "opus" | "aac" | "m4a" | "mp3" | "flac" | "wav" | (string & {});
24
26
 
25
27
  declare class DownloadBuilder {
26
28
  private readonly url;
@@ -29,7 +31,11 @@ declare class DownloadBuilder {
29
31
  private audioFormat?;
30
32
  private outputDir?;
31
33
  private filenameTemplate?;
34
+ private videoExt?;
35
+ private videoFps?;
36
+ private videoHeight?;
32
37
  constructor(url: string);
38
+ private buildArgs;
33
39
  /**
34
40
  * Set the desired resolution for the video download.
35
41
  * The method will automatically select the best video format that is less than or equal to the specified resolution.
@@ -67,6 +73,21 @@ declare class DownloadBuilder {
67
73
  * @returns The current instance of DownloadBuilder for method chaining.
68
74
  */
69
75
  audio(codec?: AudioCodec): this;
76
+ /**
77
+ * Set the desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc.
78
+ * If specified, the method will select the best available video format that matches the specified extension.
79
+ * If not specified, it will select the best available video format regardless of extension.
80
+ *
81
+ * @example
82
+ * download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
83
+ * .format("mp4")
84
+ * .run();
85
+ *
86
+ * @param ext The desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc. If specified, the method will select the best available video format that matches the specified extension. If not specified, it will select the best available video format regardless of extension.
87
+ * @returns The current instance of DownloadBuilder for method chaining.
88
+ */
89
+ format(ext: VideoExt): this;
90
+ fps(fps: number): this;
70
91
  /**
71
92
  * Set the filename template for the downloaded file.
72
93
  * The callback receives common output fields as named parameters which are
package/dist/index.js CHANGED
@@ -25,6 +25,26 @@ var DownloadBuilder = class {
25
25
  audioFormat;
26
26
  outputDir;
27
27
  filenameTemplate;
28
+ videoExt;
29
+ videoFps;
30
+ videoHeight;
31
+ buildArgs() {
32
+ const args = [...this.args];
33
+ if (this.videoHeight || this.videoFps || this.videoExt || this.audioFormat) {
34
+ const heightFilter = this.videoHeight ? `[height<=${this.videoHeight}]` : "";
35
+ const fpsFilter = this.videoFps ? `[fps<=${this.videoFps}]` : "";
36
+ const extFilter = this.videoExt ? `[ext=${this.videoExt}]` : "";
37
+ const video = `bestvideo${heightFilter}${fpsFilter}${extFilter}`;
38
+ const audio = this.audioFormat ?? "bestaudio";
39
+ args.push("-f", `${video}+${audio}/best`);
40
+ }
41
+ if (this.outputDir || this.filenameTemplate) {
42
+ const dir = this.outputDir ?? "";
43
+ const file = this.filenameTemplate ?? "%(title)s.%(ext)s";
44
+ args.push("-o", dir ? `${dir}/${file}` : file);
45
+ }
46
+ return args;
47
+ }
28
48
  /**
29
49
  * Set the desired resolution for the video download.
30
50
  * The method will automatically select the best video format that is less than or equal to the specified resolution.
@@ -34,8 +54,7 @@ var DownloadBuilder = class {
34
54
  * @returns The current instance of DownloadBuilder for method chaining.
35
55
  */
36
56
  resolution(res) {
37
- const height = res.replace("p", "");
38
- this.videoFormat = `bestvideo[height<=${height}]`;
57
+ this.videoHeight = res.replace("p", "");
39
58
  return this;
40
59
  }
41
60
  /**
@@ -72,6 +91,27 @@ var DownloadBuilder = class {
72
91
  this.audioFormat = codec ? `bestaudio[ext=${codec}]` : "bestaudio";
73
92
  return this;
74
93
  }
94
+ /**
95
+ * Set the desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc.
96
+ * If specified, the method will select the best available video format that matches the specified extension.
97
+ * If not specified, it will select the best available video format regardless of extension.
98
+ *
99
+ * @example
100
+ * download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
101
+ * .format("mp4")
102
+ * .run();
103
+ *
104
+ * @param ext The desired video file extension for the download. You can specify common video extensions like "mp4", "mkv", "webm", etc. If specified, the method will select the best available video format that matches the specified extension. If not specified, it will select the best available video format regardless of extension.
105
+ * @returns The current instance of DownloadBuilder for method chaining.
106
+ */
107
+ format(ext) {
108
+ this.videoExt = ext;
109
+ return this;
110
+ }
111
+ fps(fps) {
112
+ this.videoFps = fps;
113
+ return this;
114
+ }
75
115
  /**
76
116
  * Set the filename template for the downloaded file.
77
117
  * The callback receives common output fields as named parameters which are
@@ -119,17 +159,7 @@ var DownloadBuilder = class {
119
159
  *
120
160
  */
121
161
  async run() {
122
- const args = [...this.args];
123
- if (this.videoFormat || this.audioFormat) {
124
- const video = this.videoFormat ?? "bestvideo";
125
- const audio = this.audioFormat ?? "bestaudio";
126
- args.push("-f", `${video}+${audio}/best`);
127
- }
128
- if (this.outputDir || this.filenameTemplate) {
129
- const dir = this.outputDir ?? "";
130
- const file = this.filenameTemplate ?? "%(title)s.%(ext)s";
131
- args.push("-o", dir ? `${dir}/${file}` : file);
132
- }
162
+ const args = this.buildArgs();
133
163
  await runYtDlp([...args, this.url]);
134
164
  }
135
165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blagoja/ts-dlp",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A human readable TypeScript wrapper for yt-dlp",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",