@blagoja/ts-dlp 0.1.0 → 0.1.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/README.md +1 -1
- package/dist/index.cjs +108 -0
- package/dist/index.d.cts +46 -0
- package/dist/index.d.ts +46 -3
- package/dist/index.js +80 -4
- package/package.json +7 -5
package/README.md
CHANGED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
download: () => download
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/internal/runner.ts
|
|
28
|
+
var import_execa = require("execa");
|
|
29
|
+
async function runYtDlp(args) {
|
|
30
|
+
await (0, import_execa.execa)("yt-dlp", ["--js-runtimes", "node", ...args], {
|
|
31
|
+
stdio: "inherit"
|
|
32
|
+
}).catch(handleEnoent);
|
|
33
|
+
}
|
|
34
|
+
function handleEnoent(error) {
|
|
35
|
+
if (error instanceof import_execa.ExecaError && error.code === "ENOENT") {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"yt-dlp is not installed or not in PATH. Please refer to https://github.com/yt-dlp/yt-dlp#installation"
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/download.ts
|
|
44
|
+
var DownloadBuilder = class {
|
|
45
|
+
constructor(url) {
|
|
46
|
+
this.url = url;
|
|
47
|
+
}
|
|
48
|
+
url;
|
|
49
|
+
args = [];
|
|
50
|
+
/**
|
|
51
|
+
* Set the desired resolution for the video to be downloaded.
|
|
52
|
+
* This will instruct yt-dlp to download the best video and audio streams that are less than or equal to the specified height.
|
|
53
|
+
* For example, if you specify "720p", yt-dlp will download the best video and audio streams that are 720 pixels in height or less.
|
|
54
|
+
* If you want to download the best available quality regardless of resolution, you can omit this option or set it to a very high value like "9999p".
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
58
|
+
* .resolution("720p")
|
|
59
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
60
|
+
*
|
|
61
|
+
* @param res The desired resolution for the video. For example: "720p", "1080p", etc. This will tell yt-dlp to download the best video and audio streams that are less than or equal to the specified height. If you want to download the best available quality, you can omit this option or set it to a very high value like "9999p".
|
|
62
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
63
|
+
*/
|
|
64
|
+
resolution(res) {
|
|
65
|
+
const height = res.replace("p", "");
|
|
66
|
+
this.args.push(
|
|
67
|
+
"-f",
|
|
68
|
+
`bestvideo[height<=${height}]+bestaudio/best[height<=${height}]`
|
|
69
|
+
);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Set the output directory and filename template for the downloaded file.
|
|
74
|
+
*
|
|
75
|
+
* @param template The output template for the downloaded file. You can use placeholders like %(title)s, %(ext)s, etc. For example: "downloads/%(title)s.%(ext)s"
|
|
76
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
77
|
+
*/
|
|
78
|
+
output(template) {
|
|
79
|
+
this.args.push("-o", template);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Execute the download with the specified options.
|
|
84
|
+
* This will run yt-dlp with the accumulated arguments and the provided URL.
|
|
85
|
+
* The output will be displayed in the console.
|
|
86
|
+
*
|
|
87
|
+
* @throws Will throw an error if yt-dlp is not installed or not in PATH, or if any other error occurs during the execution of yt-dlp.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
91
|
+
* .resolution("720p")
|
|
92
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
93
|
+
* .run();
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
async run() {
|
|
97
|
+
await runYtDlp([...this.args, this.url]);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/index.ts
|
|
102
|
+
function download(url) {
|
|
103
|
+
return new DownloadBuilder(url);
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
download
|
|
108
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
declare class DownloadBuilder {
|
|
2
|
+
private readonly url;
|
|
3
|
+
private readonly args;
|
|
4
|
+
constructor(url: string);
|
|
5
|
+
/**
|
|
6
|
+
* Set the desired resolution for the video to be downloaded.
|
|
7
|
+
* This will instruct yt-dlp to download the best video and audio streams that are less than or equal to the specified height.
|
|
8
|
+
* For example, if you specify "720p", yt-dlp will download the best video and audio streams that are 720 pixels in height or less.
|
|
9
|
+
* If you want to download the best available quality regardless of resolution, you can omit this option or set it to a very high value like "9999p".
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
13
|
+
* .resolution("720p")
|
|
14
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
15
|
+
*
|
|
16
|
+
* @param res The desired resolution for the video. For example: "720p", "1080p", etc. This will tell yt-dlp to download the best video and audio streams that are less than or equal to the specified height. If you want to download the best available quality, you can omit this option or set it to a very high value like "9999p".
|
|
17
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
18
|
+
*/
|
|
19
|
+
resolution(res: string): this;
|
|
20
|
+
/**
|
|
21
|
+
* Set the output directory and filename template for the downloaded file.
|
|
22
|
+
*
|
|
23
|
+
* @param template The output template for the downloaded file. You can use placeholders like %(title)s, %(ext)s, etc. For example: "downloads/%(title)s.%(ext)s"
|
|
24
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
25
|
+
*/
|
|
26
|
+
output(template: string): this;
|
|
27
|
+
/**
|
|
28
|
+
* Execute the download with the specified options.
|
|
29
|
+
* This will run yt-dlp with the accumulated arguments and the provided URL.
|
|
30
|
+
* The output will be displayed in the console.
|
|
31
|
+
*
|
|
32
|
+
* @throws Will throw an error if yt-dlp is not installed or not in PATH, or if any other error occurs during the execution of yt-dlp.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
36
|
+
* .resolution("720p")
|
|
37
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
38
|
+
* .run();
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
run(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare function download(url: string): DownloadBuilder;
|
|
45
|
+
|
|
46
|
+
export { download };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare class DownloadBuilder {
|
|
2
|
+
private readonly url;
|
|
3
|
+
private readonly args;
|
|
4
|
+
constructor(url: string);
|
|
5
|
+
/**
|
|
6
|
+
* Set the desired resolution for the video to be downloaded.
|
|
7
|
+
* This will instruct yt-dlp to download the best video and audio streams that are less than or equal to the specified height.
|
|
8
|
+
* For example, if you specify "720p", yt-dlp will download the best video and audio streams that are 720 pixels in height or less.
|
|
9
|
+
* If you want to download the best available quality regardless of resolution, you can omit this option or set it to a very high value like "9999p".
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
13
|
+
* .resolution("720p")
|
|
14
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
15
|
+
*
|
|
16
|
+
* @param res The desired resolution for the video. For example: "720p", "1080p", etc. This will tell yt-dlp to download the best video and audio streams that are less than or equal to the specified height. If you want to download the best available quality, you can omit this option or set it to a very high value like "9999p".
|
|
17
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
18
|
+
*/
|
|
19
|
+
resolution(res: string): this;
|
|
20
|
+
/**
|
|
21
|
+
* Set the output directory and filename template for the downloaded file.
|
|
22
|
+
*
|
|
23
|
+
* @param template The output template for the downloaded file. You can use placeholders like %(title)s, %(ext)s, etc. For example: "downloads/%(title)s.%(ext)s"
|
|
24
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
25
|
+
*/
|
|
26
|
+
output(template: string): this;
|
|
27
|
+
/**
|
|
28
|
+
* Execute the download with the specified options.
|
|
29
|
+
* This will run yt-dlp with the accumulated arguments and the provided URL.
|
|
30
|
+
* The output will be displayed in the console.
|
|
31
|
+
*
|
|
32
|
+
* @throws Will throw an error if yt-dlp is not installed or not in PATH, or if any other error occurs during the execution of yt-dlp.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
36
|
+
* .resolution("720p")
|
|
37
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
38
|
+
* .run();
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
run(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare function download(url: string): DownloadBuilder;
|
|
45
|
+
|
|
46
|
+
export { download };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/internal/runner.ts
|
|
2
|
+
import { execa, ExecaError } from "execa";
|
|
3
|
+
async function runYtDlp(args) {
|
|
4
|
+
await execa("yt-dlp", ["--js-runtimes", "node", ...args], {
|
|
5
|
+
stdio: "inherit"
|
|
6
|
+
}).catch(handleEnoent);
|
|
4
7
|
}
|
|
5
|
-
|
|
8
|
+
function handleEnoent(error) {
|
|
9
|
+
if (error instanceof ExecaError && error.code === "ENOENT") {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"yt-dlp is not installed or not in PATH. Please refer to https://github.com/yt-dlp/yt-dlp#installation"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/download.ts
|
|
18
|
+
var DownloadBuilder = class {
|
|
19
|
+
constructor(url) {
|
|
20
|
+
this.url = url;
|
|
21
|
+
}
|
|
22
|
+
url;
|
|
23
|
+
args = [];
|
|
24
|
+
/**
|
|
25
|
+
* Set the desired resolution for the video to be downloaded.
|
|
26
|
+
* This will instruct yt-dlp to download the best video and audio streams that are less than or equal to the specified height.
|
|
27
|
+
* For example, if you specify "720p", yt-dlp will download the best video and audio streams that are 720 pixels in height or less.
|
|
28
|
+
* If you want to download the best available quality regardless of resolution, you can omit this option or set it to a very high value like "9999p".
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
32
|
+
* .resolution("720p")
|
|
33
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
34
|
+
*
|
|
35
|
+
* @param res The desired resolution for the video. For example: "720p", "1080p", etc. This will tell yt-dlp to download the best video and audio streams that are less than or equal to the specified height. If you want to download the best available quality, you can omit this option or set it to a very high value like "9999p".
|
|
36
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
37
|
+
*/
|
|
38
|
+
resolution(res) {
|
|
39
|
+
const height = res.replace("p", "");
|
|
40
|
+
this.args.push(
|
|
41
|
+
"-f",
|
|
42
|
+
`bestvideo[height<=${height}]+bestaudio/best[height<=${height}]`
|
|
43
|
+
);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Set the output directory and filename template for the downloaded file.
|
|
48
|
+
*
|
|
49
|
+
* @param template The output template for the downloaded file. You can use placeholders like %(title)s, %(ext)s, etc. For example: "downloads/%(title)s.%(ext)s"
|
|
50
|
+
* @returns The current instance of DownloadBuilder for method chaining.
|
|
51
|
+
*/
|
|
52
|
+
output(template) {
|
|
53
|
+
this.args.push("-o", template);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Execute the download with the specified options.
|
|
58
|
+
* This will run yt-dlp with the accumulated arguments and the provided URL.
|
|
59
|
+
* The output will be displayed in the console.
|
|
60
|
+
*
|
|
61
|
+
* @throws Will throw an error if yt-dlp is not installed or not in PATH, or if any other error occurs during the execution of yt-dlp.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
|
65
|
+
* .resolution("720p")
|
|
66
|
+
* .output("downloads/%(title)s.%(ext)s")
|
|
67
|
+
* .run();
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
async run() {
|
|
71
|
+
await runYtDlp([...this.args, this.url]);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/index.ts
|
|
76
|
+
function download(url) {
|
|
77
|
+
return new DownloadBuilder(url);
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
download
|
|
81
|
+
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blagoja/ts-dlp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A human readable TypeScript wrapper for yt-dlp",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
9
|
"import": "./dist/index.js",
|
|
10
|
-
"types": "./dist/index.d.ts"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
|
-
"build": "
|
|
15
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
15
16
|
"dev": "tsx src/index.ts",
|
|
16
17
|
"lint": "eslint src",
|
|
17
18
|
"prepublishOnly": "npm run build"
|
|
@@ -33,11 +34,12 @@
|
|
|
33
34
|
"type": "module",
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/node": "^25.9.1",
|
|
36
|
-
"typescript-eslint": "^8.60.0",
|
|
37
37
|
"eslint": "^10.4.0",
|
|
38
38
|
"jiti": "^2.7.0",
|
|
39
|
+
"tsup": "^8.5.1",
|
|
39
40
|
"tsx": "^4.22.3",
|
|
40
|
-
"typescript": "^6.0.3"
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"typescript-eslint": "^8.60.0"
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
43
45
|
"execa": "^9.6.1"
|