@blagoja/ts-dlp 0.1.1 → 0.1.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/README.md +9 -14
- package/dist/index.cjs +80 -18
- package/dist/index.d.cts +74 -11
- package/dist/index.d.ts +74 -11
- package/dist/index.js +80 -18
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -108,24 +108,19 @@ await ytdlp
|
|
|
108
108
|
## v0.1.0 - Foundation
|
|
109
109
|
|
|
110
110
|
- [x] Detect yt-dlp installation
|
|
111
|
-
- [
|
|
111
|
+
- [x] Execute simple yt-dlp commands
|
|
112
112
|
- [ ] Basic command runner
|
|
113
113
|
- [ ] Error handling
|
|
114
114
|
- [ ] Capture stdout/stderr
|
|
115
115
|
- [ ] TypeScript support
|
|
116
116
|
- [ ] Unit test setup
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
## v0.2.0 - Download API
|
|
121
|
-
|
|
122
|
-
- [ ] `.download(url)`
|
|
123
|
-
- [ ] `.run()`
|
|
124
|
-
- [ ] `.output(path)`
|
|
117
|
+
- [x] `.download(url)`
|
|
118
|
+
- [x] `.run()`
|
|
119
|
+
- [x] `.output(path)`
|
|
125
120
|
- [ ] `.format(format)`
|
|
126
|
-
- [
|
|
121
|
+
- [x] `.audio()`
|
|
127
122
|
- [ ] `.video()`
|
|
128
|
-
- [
|
|
123
|
+
- [x] `.resolution()`
|
|
129
124
|
- [ ] `.fps()`
|
|
130
125
|
|
|
131
126
|
Example:
|
|
@@ -136,7 +131,7 @@ await ytdlp.download(url).resolution("720p").run();
|
|
|
136
131
|
|
|
137
132
|
---
|
|
138
133
|
|
|
139
|
-
## v0.
|
|
134
|
+
## v0.2.0 - Metadata & Information
|
|
140
135
|
|
|
141
136
|
- [ ] `.info()`
|
|
142
137
|
- [ ] Video metadata parsing
|
|
@@ -152,7 +147,7 @@ const info = await ytdlp.info(url);
|
|
|
152
147
|
|
|
153
148
|
---
|
|
154
149
|
|
|
155
|
-
## v0.
|
|
150
|
+
## v0.3.0 - Advanced Features
|
|
156
151
|
|
|
157
152
|
- [ ] Subtitle support
|
|
158
153
|
- [ ] Thumbnail downloads
|
|
@@ -163,7 +158,7 @@ const info = await ytdlp.info(url);
|
|
|
163
158
|
|
|
164
159
|
---
|
|
165
160
|
|
|
166
|
-
## v0.
|
|
161
|
+
## v0.4.0 - Developer Experience
|
|
167
162
|
|
|
168
163
|
- [ ] Better typed builders
|
|
169
164
|
- [ ] Presets
|
package/dist/index.cjs
CHANGED
|
@@ -47,36 +47,87 @@ var DownloadBuilder = class {
|
|
|
47
47
|
}
|
|
48
48
|
url;
|
|
49
49
|
args = [];
|
|
50
|
+
videoFormat;
|
|
51
|
+
audioFormat;
|
|
52
|
+
outputDir;
|
|
53
|
+
filenameTemplate;
|
|
50
54
|
/**
|
|
51
|
-
* Set the desired resolution for the video
|
|
52
|
-
*
|
|
53
|
-
* For example, if you specify "720p",
|
|
54
|
-
*
|
|
55
|
+
* Set the desired resolution for the video download.
|
|
56
|
+
* The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
57
|
+
* For example, if you specify "720p", it will select the best available video format that is 720p or lower.
|
|
58
|
+
*
|
|
59
|
+
* @param res The desired resolution for the video. You can specify common resolutions like "720p", "1080p", etc. The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
60
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
61
|
+
*/
|
|
62
|
+
resolution(res) {
|
|
63
|
+
const height = res.replace("p", "");
|
|
64
|
+
this.videoFormat = `bestvideo[height<=${height}]`;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set the output directory for the downloaded file. You can specify a directory path like "downloads".
|
|
69
|
+
* If not specified, the file will be saved in the current working directory.
|
|
55
70
|
*
|
|
56
71
|
* @example
|
|
57
72
|
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
58
|
-
*
|
|
59
|
-
*
|
|
73
|
+
* .output("downloads")
|
|
74
|
+
* .run();
|
|
60
75
|
*
|
|
61
|
-
* @param
|
|
76
|
+
* @param dir The output directory where the downloaded file will be saved.
|
|
77
|
+
* You can specify a directory path like "downloads". If not specified, the file will be saved in the current working directory.
|
|
62
78
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
63
79
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.args.push(
|
|
67
|
-
"-f",
|
|
68
|
-
`bestvideo[height<=${height}]+bestaudio/best[height<=${height}]`
|
|
69
|
-
);
|
|
80
|
+
output(dir) {
|
|
81
|
+
this.outputDir = dir;
|
|
70
82
|
return this;
|
|
71
83
|
}
|
|
72
84
|
/**
|
|
73
|
-
* Set the
|
|
85
|
+
* Set the desired audio codec for the download.
|
|
86
|
+
* The method will select the best available audio format that matches the specified codec.
|
|
87
|
+
* If no codec is specified, it will select the best available audio format regardless of codec.
|
|
88
|
+
*
|
|
89
|
+
* @example // Specifying an audio codec
|
|
90
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
91
|
+
* .audio("mp3")
|
|
92
|
+
* .run();
|
|
93
|
+
*
|
|
94
|
+
* @param codec The desired audio codec for the download. You can specify common audio codecs like "mp3", "aac", "opus", etc. If no codec is specified, it will select the best available audio format.
|
|
95
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
96
|
+
*/
|
|
97
|
+
audio(codec) {
|
|
98
|
+
this.audioFormat = codec ? `bestaudio[ext=${codec}]` : "bestaudio";
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Set the filename template for the downloaded file.
|
|
103
|
+
* The callback receives common output fields as named parameters which are
|
|
104
|
+
* automatically mapped to their values at download time.
|
|
105
|
+
*
|
|
106
|
+
* @example // Using a string template
|
|
107
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
108
|
+
* .output("downloads")
|
|
109
|
+
* .filename("%(title)s.%(ext)s")
|
|
110
|
+
*
|
|
111
|
+
* @example // Using a callback to specify a custom filename template
|
|
112
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
113
|
+
* .output("downloads")
|
|
114
|
+
* .filename(({ title, ext }) => `${title}.${ext}`)
|
|
115
|
+
* .run();
|
|
74
116
|
*
|
|
75
|
-
* @param template
|
|
117
|
+
* @param template A callback that receives output fields and returns a filename string. If omitted, defaults to the video title with its original extension.
|
|
76
118
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
77
119
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
120
|
+
filename(template) {
|
|
121
|
+
if (typeof template === "string") {
|
|
122
|
+
this.filenameTemplate = template;
|
|
123
|
+
} else {
|
|
124
|
+
const fields = new Proxy({}, {
|
|
125
|
+
get(_, prop) {
|
|
126
|
+
return `%(${prop})s`;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
this.filenameTemplate = template(fields);
|
|
130
|
+
}
|
|
80
131
|
return this;
|
|
81
132
|
}
|
|
82
133
|
/**
|
|
@@ -94,7 +145,18 @@ var DownloadBuilder = class {
|
|
|
94
145
|
*
|
|
95
146
|
*/
|
|
96
147
|
async run() {
|
|
97
|
-
|
|
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
|
+
}
|
|
159
|
+
await runYtDlp([...args, this.url]);
|
|
98
160
|
}
|
|
99
161
|
};
|
|
100
162
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,29 +1,92 @@
|
|
|
1
|
+
type Resolution = "144p" | "240p" | "360p" | "480p" | "720p" | "1080p" | "1440p" | "2160p" | (string & {});
|
|
2
|
+
type OutputFields = {
|
|
3
|
+
title: string;
|
|
4
|
+
ext: string;
|
|
5
|
+
id: string;
|
|
6
|
+
uploader: string;
|
|
7
|
+
uploader_id: string;
|
|
8
|
+
channel: string;
|
|
9
|
+
upload_date: string;
|
|
10
|
+
release_date: string;
|
|
11
|
+
epoch: string;
|
|
12
|
+
height: string;
|
|
13
|
+
width: string;
|
|
14
|
+
resolution: string;
|
|
15
|
+
fps: string;
|
|
16
|
+
vcodec: string;
|
|
17
|
+
acodec: string;
|
|
18
|
+
duration_string: string;
|
|
19
|
+
playlist_title: string;
|
|
20
|
+
playlist_index: string;
|
|
21
|
+
autonumber: string;
|
|
22
|
+
};
|
|
23
|
+
type AudioCodec = "opus" | "aac" | "m4a" | "mp3" | "flac" | "wav" | (string & {});
|
|
24
|
+
|
|
1
25
|
declare class DownloadBuilder {
|
|
2
26
|
private readonly url;
|
|
3
27
|
private readonly args;
|
|
28
|
+
private videoFormat?;
|
|
29
|
+
private audioFormat?;
|
|
30
|
+
private outputDir?;
|
|
31
|
+
private filenameTemplate?;
|
|
4
32
|
constructor(url: string);
|
|
5
33
|
/**
|
|
6
|
-
* Set the desired resolution for the video
|
|
7
|
-
*
|
|
8
|
-
* For example, if you specify "720p",
|
|
9
|
-
*
|
|
34
|
+
* Set the desired resolution for the video download.
|
|
35
|
+
* The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
36
|
+
* For example, if you specify "720p", it will select the best available video format that is 720p or lower.
|
|
37
|
+
*
|
|
38
|
+
* @param res The desired resolution for the video. You can specify common resolutions like "720p", "1080p", etc. The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
39
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
40
|
+
*/
|
|
41
|
+
resolution(res: Resolution): this;
|
|
42
|
+
/**
|
|
43
|
+
* Set the output directory for the downloaded file. You can specify a directory path like "downloads".
|
|
44
|
+
* If not specified, the file will be saved in the current working directory.
|
|
10
45
|
*
|
|
11
46
|
* @example
|
|
12
47
|
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
13
|
-
*
|
|
14
|
-
*
|
|
48
|
+
* .output("downloads")
|
|
49
|
+
* .run();
|
|
15
50
|
*
|
|
16
|
-
* @param
|
|
51
|
+
* @param dir The output directory where the downloaded file will be saved.
|
|
52
|
+
* You can specify a directory path like "downloads". If not specified, the file will be saved in the current working directory.
|
|
17
53
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
18
54
|
*/
|
|
19
|
-
|
|
55
|
+
output(dir: string): this;
|
|
20
56
|
/**
|
|
21
|
-
* Set the
|
|
57
|
+
* Set the desired audio codec for the download.
|
|
58
|
+
* The method will select the best available audio format that matches the specified codec.
|
|
59
|
+
* If no codec is specified, it will select the best available audio format regardless of codec.
|
|
60
|
+
*
|
|
61
|
+
* @example // Specifying an audio codec
|
|
62
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
63
|
+
* .audio("mp3")
|
|
64
|
+
* .run();
|
|
65
|
+
*
|
|
66
|
+
* @param codec The desired audio codec for the download. You can specify common audio codecs like "mp3", "aac", "opus", etc. If no codec is specified, it will select the best available audio format.
|
|
67
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
68
|
+
*/
|
|
69
|
+
audio(codec?: AudioCodec): this;
|
|
70
|
+
/**
|
|
71
|
+
* Set the filename template for the downloaded file.
|
|
72
|
+
* The callback receives common output fields as named parameters which are
|
|
73
|
+
* automatically mapped to their values at download time.
|
|
74
|
+
*
|
|
75
|
+
* @example // Using a string template
|
|
76
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
77
|
+
* .output("downloads")
|
|
78
|
+
* .filename("%(title)s.%(ext)s")
|
|
79
|
+
*
|
|
80
|
+
* @example // Using a callback to specify a custom filename template
|
|
81
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
82
|
+
* .output("downloads")
|
|
83
|
+
* .filename(({ title, ext }) => `${title}.${ext}`)
|
|
84
|
+
* .run();
|
|
22
85
|
*
|
|
23
|
-
* @param template
|
|
86
|
+
* @param template A callback that receives output fields and returns a filename string. If omitted, defaults to the video title with its original extension.
|
|
24
87
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
25
88
|
*/
|
|
26
|
-
|
|
89
|
+
filename(template: ((fields: OutputFields) => string) | string): this;
|
|
27
90
|
/**
|
|
28
91
|
* Execute the download with the specified options.
|
|
29
92
|
* This will run yt-dlp with the accumulated arguments and the provided URL.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,92 @@
|
|
|
1
|
+
type Resolution = "144p" | "240p" | "360p" | "480p" | "720p" | "1080p" | "1440p" | "2160p" | (string & {});
|
|
2
|
+
type OutputFields = {
|
|
3
|
+
title: string;
|
|
4
|
+
ext: string;
|
|
5
|
+
id: string;
|
|
6
|
+
uploader: string;
|
|
7
|
+
uploader_id: string;
|
|
8
|
+
channel: string;
|
|
9
|
+
upload_date: string;
|
|
10
|
+
release_date: string;
|
|
11
|
+
epoch: string;
|
|
12
|
+
height: string;
|
|
13
|
+
width: string;
|
|
14
|
+
resolution: string;
|
|
15
|
+
fps: string;
|
|
16
|
+
vcodec: string;
|
|
17
|
+
acodec: string;
|
|
18
|
+
duration_string: string;
|
|
19
|
+
playlist_title: string;
|
|
20
|
+
playlist_index: string;
|
|
21
|
+
autonumber: string;
|
|
22
|
+
};
|
|
23
|
+
type AudioCodec = "opus" | "aac" | "m4a" | "mp3" | "flac" | "wav" | (string & {});
|
|
24
|
+
|
|
1
25
|
declare class DownloadBuilder {
|
|
2
26
|
private readonly url;
|
|
3
27
|
private readonly args;
|
|
28
|
+
private videoFormat?;
|
|
29
|
+
private audioFormat?;
|
|
30
|
+
private outputDir?;
|
|
31
|
+
private filenameTemplate?;
|
|
4
32
|
constructor(url: string);
|
|
5
33
|
/**
|
|
6
|
-
* Set the desired resolution for the video
|
|
7
|
-
*
|
|
8
|
-
* For example, if you specify "720p",
|
|
9
|
-
*
|
|
34
|
+
* Set the desired resolution for the video download.
|
|
35
|
+
* The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
36
|
+
* For example, if you specify "720p", it will select the best available video format that is 720p or lower.
|
|
37
|
+
*
|
|
38
|
+
* @param res The desired resolution for the video. You can specify common resolutions like "720p", "1080p", etc. The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
39
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
40
|
+
*/
|
|
41
|
+
resolution(res: Resolution): this;
|
|
42
|
+
/**
|
|
43
|
+
* Set the output directory for the downloaded file. You can specify a directory path like "downloads".
|
|
44
|
+
* If not specified, the file will be saved in the current working directory.
|
|
10
45
|
*
|
|
11
46
|
* @example
|
|
12
47
|
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
13
|
-
*
|
|
14
|
-
*
|
|
48
|
+
* .output("downloads")
|
|
49
|
+
* .run();
|
|
15
50
|
*
|
|
16
|
-
* @param
|
|
51
|
+
* @param dir The output directory where the downloaded file will be saved.
|
|
52
|
+
* You can specify a directory path like "downloads". If not specified, the file will be saved in the current working directory.
|
|
17
53
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
18
54
|
*/
|
|
19
|
-
|
|
55
|
+
output(dir: string): this;
|
|
20
56
|
/**
|
|
21
|
-
* Set the
|
|
57
|
+
* Set the desired audio codec for the download.
|
|
58
|
+
* The method will select the best available audio format that matches the specified codec.
|
|
59
|
+
* If no codec is specified, it will select the best available audio format regardless of codec.
|
|
60
|
+
*
|
|
61
|
+
* @example // Specifying an audio codec
|
|
62
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
63
|
+
* .audio("mp3")
|
|
64
|
+
* .run();
|
|
65
|
+
*
|
|
66
|
+
* @param codec The desired audio codec for the download. You can specify common audio codecs like "mp3", "aac", "opus", etc. If no codec is specified, it will select the best available audio format.
|
|
67
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
68
|
+
*/
|
|
69
|
+
audio(codec?: AudioCodec): this;
|
|
70
|
+
/**
|
|
71
|
+
* Set the filename template for the downloaded file.
|
|
72
|
+
* The callback receives common output fields as named parameters which are
|
|
73
|
+
* automatically mapped to their values at download time.
|
|
74
|
+
*
|
|
75
|
+
* @example // Using a string template
|
|
76
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
77
|
+
* .output("downloads")
|
|
78
|
+
* .filename("%(title)s.%(ext)s")
|
|
79
|
+
*
|
|
80
|
+
* @example // Using a callback to specify a custom filename template
|
|
81
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
82
|
+
* .output("downloads")
|
|
83
|
+
* .filename(({ title, ext }) => `${title}.${ext}`)
|
|
84
|
+
* .run();
|
|
22
85
|
*
|
|
23
|
-
* @param template
|
|
86
|
+
* @param template A callback that receives output fields and returns a filename string. If omitted, defaults to the video title with its original extension.
|
|
24
87
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
25
88
|
*/
|
|
26
|
-
|
|
89
|
+
filename(template: ((fields: OutputFields) => string) | string): this;
|
|
27
90
|
/**
|
|
28
91
|
* Execute the download with the specified options.
|
|
29
92
|
* This will run yt-dlp with the accumulated arguments and the provided URL.
|
package/dist/index.js
CHANGED
|
@@ -21,36 +21,87 @@ var DownloadBuilder = class {
|
|
|
21
21
|
}
|
|
22
22
|
url;
|
|
23
23
|
args = [];
|
|
24
|
+
videoFormat;
|
|
25
|
+
audioFormat;
|
|
26
|
+
outputDir;
|
|
27
|
+
filenameTemplate;
|
|
24
28
|
/**
|
|
25
|
-
* Set the desired resolution for the video
|
|
26
|
-
*
|
|
27
|
-
* For example, if you specify "720p",
|
|
28
|
-
*
|
|
29
|
+
* Set the desired resolution for the video download.
|
|
30
|
+
* The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
31
|
+
* For example, if you specify "720p", it will select the best available video format that is 720p or lower.
|
|
32
|
+
*
|
|
33
|
+
* @param res The desired resolution for the video. You can specify common resolutions like "720p", "1080p", etc. The method will automatically select the best video format that is less than or equal to the specified resolution.
|
|
34
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
35
|
+
*/
|
|
36
|
+
resolution(res) {
|
|
37
|
+
const height = res.replace("p", "");
|
|
38
|
+
this.videoFormat = `bestvideo[height<=${height}]`;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set the output directory for the downloaded file. You can specify a directory path like "downloads".
|
|
43
|
+
* If not specified, the file will be saved in the current working directory.
|
|
29
44
|
*
|
|
30
45
|
* @example
|
|
31
46
|
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
32
|
-
*
|
|
33
|
-
*
|
|
47
|
+
* .output("downloads")
|
|
48
|
+
* .run();
|
|
34
49
|
*
|
|
35
|
-
* @param
|
|
50
|
+
* @param dir The output directory where the downloaded file will be saved.
|
|
51
|
+
* You can specify a directory path like "downloads". If not specified, the file will be saved in the current working directory.
|
|
36
52
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
37
53
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.args.push(
|
|
41
|
-
"-f",
|
|
42
|
-
`bestvideo[height<=${height}]+bestaudio/best[height<=${height}]`
|
|
43
|
-
);
|
|
54
|
+
output(dir) {
|
|
55
|
+
this.outputDir = dir;
|
|
44
56
|
return this;
|
|
45
57
|
}
|
|
46
58
|
/**
|
|
47
|
-
* Set the
|
|
59
|
+
* Set the desired audio codec for the download.
|
|
60
|
+
* The method will select the best available audio format that matches the specified codec.
|
|
61
|
+
* If no codec is specified, it will select the best available audio format regardless of codec.
|
|
62
|
+
*
|
|
63
|
+
* @example // Specifying an audio codec
|
|
64
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
65
|
+
* .audio("mp3")
|
|
66
|
+
* .run();
|
|
67
|
+
*
|
|
68
|
+
* @param codec The desired audio codec for the download. You can specify common audio codecs like "mp3", "aac", "opus", etc. If no codec is specified, it will select the best available audio format.
|
|
69
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
70
|
+
*/
|
|
71
|
+
audio(codec) {
|
|
72
|
+
this.audioFormat = codec ? `bestaudio[ext=${codec}]` : "bestaudio";
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set the filename template for the downloaded file.
|
|
77
|
+
* The callback receives common output fields as named parameters which are
|
|
78
|
+
* automatically mapped to their values at download time.
|
|
79
|
+
*
|
|
80
|
+
* @example // Using a string template
|
|
81
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
82
|
+
* .output("downloads")
|
|
83
|
+
* .filename("%(title)s.%(ext)s")
|
|
84
|
+
*
|
|
85
|
+
* @example // Using a callback to specify a custom filename template
|
|
86
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
87
|
+
* .output("downloads")
|
|
88
|
+
* .filename(({ title, ext }) => `${title}.${ext}`)
|
|
89
|
+
* .run();
|
|
48
90
|
*
|
|
49
|
-
* @param template
|
|
91
|
+
* @param template A callback that receives output fields and returns a filename string. If omitted, defaults to the video title with its original extension.
|
|
50
92
|
* @returns The current instance of DownloadBuilder for method chaining.
|
|
51
93
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
94
|
+
filename(template) {
|
|
95
|
+
if (typeof template === "string") {
|
|
96
|
+
this.filenameTemplate = template;
|
|
97
|
+
} else {
|
|
98
|
+
const fields = new Proxy({}, {
|
|
99
|
+
get(_, prop) {
|
|
100
|
+
return `%(${prop})s`;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
this.filenameTemplate = template(fields);
|
|
104
|
+
}
|
|
54
105
|
return this;
|
|
55
106
|
}
|
|
56
107
|
/**
|
|
@@ -68,7 +119,18 @@ var DownloadBuilder = class {
|
|
|
68
119
|
*
|
|
69
120
|
*/
|
|
70
121
|
async run() {
|
|
71
|
-
|
|
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
|
+
}
|
|
133
|
+
await runYtDlp([...args, this.url]);
|
|
72
134
|
}
|
|
73
135
|
};
|
|
74
136
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blagoja/ts-dlp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A human readable TypeScript wrapper for yt-dlp",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"downloader",
|
|
24
24
|
"wrapper"
|
|
25
25
|
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/blagojablazhevski/ts-dlp.git"
|
|
29
|
+
},
|
|
26
30
|
"author": "Blagoja Blazhevski",
|
|
27
31
|
"files": [
|
|
28
32
|
"dist"
|
|
@@ -30,7 +34,7 @@
|
|
|
30
34
|
"engines": {
|
|
31
35
|
"node": ">=18"
|
|
32
36
|
},
|
|
33
|
-
"license": "
|
|
37
|
+
"license": "MIT",
|
|
34
38
|
"type": "module",
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"@types/node": "^25.9.1",
|