dnx-ytdown 1.0.0 → 1.0.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
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
A simple command-line tool to download YouTube videos, music, or playlists using `yt-dlp`.
|
|
4
4
|
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
You must have **[yt-dlp](https://github.com/yt-dlp/yt-dlp)** installed on your system and available in your system's PATH.
|
|
8
|
-
|
|
9
|
-
This tool is a wrapper around `yt-dlp` and will not work without it.
|
|
10
|
-
|
|
11
5
|
## Installation
|
|
12
6
|
|
|
13
7
|
Install the tool globally using npm:
|
|
@@ -19,7 +13,7 @@ npm install -g .
|
|
|
19
13
|
|
|
20
14
|
To publish and install from the registry, you would use:
|
|
21
15
|
```bash
|
|
22
|
-
npm install -g ytdown
|
|
16
|
+
npm install -g dnx-ytdown
|
|
23
17
|
```
|
|
24
18
|
|
|
25
19
|
## Usage
|
package/index.js
CHANGED
|
@@ -2,56 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
import yargs from 'yargs';
|
|
4
4
|
import { hideBin } from 'yargs/helpers';
|
|
5
|
-
import {
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const YtDlpWrap = require('yt-dlp-wrap');
|
|
6
8
|
import path from 'path';
|
|
7
9
|
import process from 'process';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'Download a YouTube video, music, or playlist.',
|
|
25
|
-
(yargs) => {
|
|
26
|
-
return yargs.positional('link', {
|
|
27
|
-
describe: 'URL of the video, music, or playlist',
|
|
28
|
-
type: 'string',
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
(argv) => {
|
|
32
|
-
if (argv.link) {
|
|
33
|
-
download(argv.link, argv.format, argv.output);
|
|
34
|
-
} else {
|
|
35
|
-
yargs.showHelp();
|
|
36
|
-
}
|
|
11
|
+
yargs(hideBin(process.argv))
|
|
12
|
+
.command(
|
|
13
|
+
'$0 <link>',
|
|
14
|
+
'Download a YouTube video, music, or playlist.',
|
|
15
|
+
(yargs) => {
|
|
16
|
+
return yargs.positional('link', {
|
|
17
|
+
describe: 'URL of the video, music, or playlist',
|
|
18
|
+
type: 'string',
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
(argv) => {
|
|
22
|
+
if (argv.link) {
|
|
23
|
+
download(argv.link, argv.format, argv.output);
|
|
24
|
+
} else {
|
|
25
|
+
yargs.showHelp();
|
|
37
26
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
.option('format', {
|
|
30
|
+
alias: 'f',
|
|
31
|
+
describe: 'Download format',
|
|
32
|
+
choices: ['mp3', 'mp4'],
|
|
33
|
+
default: 'mp4',
|
|
34
|
+
})
|
|
35
|
+
.option('output', {
|
|
36
|
+
alias: 'o',
|
|
37
|
+
describe: 'Output directory',
|
|
38
|
+
type: 'string',
|
|
39
|
+
default: process.cwd(), // Defaults to the current working directory
|
|
40
|
+
})
|
|
41
|
+
.help()
|
|
42
|
+
.alias('help', 'h')
|
|
43
|
+
.parse();
|
|
44
|
+
|
|
55
45
|
|
|
56
46
|
function download(link, format, outputDir) {
|
|
57
47
|
console.log(`Starting download...`);
|
|
@@ -59,6 +49,8 @@ function download(link, format, outputDir) {
|
|
|
59
49
|
console.log(` - Format: ${format}`);
|
|
60
50
|
console.log(` - Output Dir: ${outputDir}`);
|
|
61
51
|
|
|
52
|
+
const ytDlpWrap = new (YtDlpWrap.default || YtDlpWrap)();
|
|
53
|
+
|
|
62
54
|
const args = [
|
|
63
55
|
'-i', // Ignore errors
|
|
64
56
|
'--no-overwrites',
|
|
@@ -78,7 +70,7 @@ function download(link, format, outputDir) {
|
|
|
78
70
|
'-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'
|
|
79
71
|
);
|
|
80
72
|
}
|
|
81
|
-
|
|
73
|
+
|
|
82
74
|
// Define the output template
|
|
83
75
|
const outputTemplate = path.join(outputDir, '%(title)s.%(ext)s');
|
|
84
76
|
args.push('-o', outputTemplate);
|
|
@@ -88,25 +80,21 @@ function download(link, format, outputDir) {
|
|
|
88
80
|
|
|
89
81
|
console.log(`\nExecuting: yt-dlp ${args.join(' ')}\n`);
|
|
90
82
|
|
|
91
|
-
const ytdlp =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
ytdlp.on('error', (err) => {
|
|
110
|
-
console.error('Failed to start the yt-dlp process. Is it installed and in your PATH?', err);
|
|
111
|
-
});
|
|
83
|
+
const ytdlp = ytDlpWrap.exec(args)
|
|
84
|
+
.on('stdout', (data) => {
|
|
85
|
+
process.stdout.write(data.toString());
|
|
86
|
+
})
|
|
87
|
+
.on('stderr', (data) => {
|
|
88
|
+
process.stderr.write(data.toString());
|
|
89
|
+
})
|
|
90
|
+
.on('close', (code) => {
|
|
91
|
+
if (code === 0) {
|
|
92
|
+
console.log('\nDownload completed successfully.');
|
|
93
|
+
} else {
|
|
94
|
+
console.error(`\nProcess exited with code ${code}. There might have been an error.`);
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
.on('error', (err) => {
|
|
98
|
+
console.error('Failed to start the yt-dlp process.', err);
|
|
99
|
+
});
|
|
112
100
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dnx-ytdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A command-line tool to download YouTube videos, music, or playlists as MP4 or MP3.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"author": "",
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"yargs": "^18.0.0"
|
|
24
|
+
"yargs": "^18.0.0",
|
|
25
|
+
"yt-dlp-wrap": "^2.3.12"
|
|
25
26
|
}
|
|
26
27
|
}
|
|
Binary file
|
|
Binary file
|