yt-direct 1.0.0
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/LICENSE +21 -0
- package/README.md +269 -0
- package/dist/.integrity +1 -0
- package/dist/index.js +1304 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License - Maycol B.T - 2026
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yt-direct contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# yt-direct
|
|
2
|
+
|
|
3
|
+
**Zero-dependency YouTube video downloader**
|
|
4
|
+
Uses the InnerTube API (same as yt-dlp). No external modules required.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install yt-direct
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **No external dependencies** — only uses Node.js built-in modules
|
|
15
|
+
- **InnerTube API** — same protocol as yt-dlp, no scraper needed
|
|
16
|
+
- **Quality selection** — auto, 2160p, 1440p, 1080p, 720p, 480p, 360p, audio
|
|
17
|
+
- **Format selection** — mp4, webm, mkv, avi, mov, m4a, aac, flac, ogg, mp3, wav
|
|
18
|
+
- **FFmpeg merge** — combine separate video + audio streams
|
|
19
|
+
- **Parallel downloads** — faster large file transfers
|
|
20
|
+
- **Stream interface** — pipe directly to writable streams
|
|
21
|
+
- **No API key required**
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const ytdl = require('yt-direct');
|
|
29
|
+
|
|
30
|
+
(async () => {
|
|
31
|
+
const video = await ytdl('https://www.youtube.com/watch?v=dQw4w9WgXcQ', {
|
|
32
|
+
quality: '720p',
|
|
33
|
+
format: 'mp4',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log('Title:', video.title);
|
|
37
|
+
await video.download('./video.mp4');
|
|
38
|
+
})();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
And don't worry, it is compatible with ESM:
|
|
42
|
+
```javascript
|
|
43
|
+
import ytdl from 'yt-direct';
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## API Reference
|
|
49
|
+
|
|
50
|
+
### `ytdl(url, options?)`
|
|
51
|
+
|
|
52
|
+
Downloads a YouTube video. Returns a `VideoResult` object.
|
|
53
|
+
|
|
54
|
+
| Option | Type | Default | Description |
|
|
55
|
+
|--------|------|---------|-------------|
|
|
56
|
+
| `quality` | `string` | `'auto'` | `'auto'`, `'best'`, `'2160p'`, `'1440p'`, `'1080p'`, `'720p'`, `'480p'`, `'360p'`, `'audio'` |
|
|
57
|
+
| `format` | `string` | `null` | Target container (see Format Support) |
|
|
58
|
+
| `filter` | `string` | `'audioandvideo'` | `'audioandvideo'`, `'videoonly'`, `'audioonly'` |
|
|
59
|
+
| `preferMp4` | `boolean` | `true` | Prefer mp4 over webm at same quality |
|
|
60
|
+
| `concurrency` | `number` | `6` | Parallel download streams (1–12) |
|
|
61
|
+
| `merge` | `object` | `null` | FFmpeg merge config (see Merging) |
|
|
62
|
+
| `onProgress` | `function` | `null` | `(done, total) => {}` |
|
|
63
|
+
|
|
64
|
+
#### VideoResult
|
|
65
|
+
|
|
66
|
+
| Property | Type | Description |
|
|
67
|
+
|----------|------|-------------|
|
|
68
|
+
| `title` | `string` | Video title |
|
|
69
|
+
| `url` | `string` | Direct stream URL |
|
|
70
|
+
| `format` | `Format` | Selected video format |
|
|
71
|
+
| `audio` | `Format?` | Selected audio format (if separate) |
|
|
72
|
+
| `type` | `string` | `'combined'`, `'separate'`, `'video-only'`, `'audio'` |
|
|
73
|
+
| `stream()` | `ReadableStream` | Get a readable stream |
|
|
74
|
+
| `pipe(writable)` | `Writable` | Pipe to a writable stream |
|
|
75
|
+
| `download(path?)` | `Promise<string>` | Download to file |
|
|
76
|
+
| `merge(output?)` | `Promise<string>` | Download and merge via FFmpeg |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Format Support
|
|
81
|
+
|
|
82
|
+
### Native (direct from YouTube)
|
|
83
|
+
|
|
84
|
+
| Container | Extension | Video | Audio | Native Source |
|
|
85
|
+
|-----------|-----------|-------|-------|---------------|
|
|
86
|
+
| MP4 | `.mp4` | H.264, AV1 | AAC | ✓ |
|
|
87
|
+
| WebM | `.webm` | VP9, AV1 | Opus | ✓ |
|
|
88
|
+
| M4A | `.m4a` | — | AAC | ✓ |
|
|
89
|
+
|
|
90
|
+
### Require Conversion (via FFmpeg)
|
|
91
|
+
|
|
92
|
+
| Container | Extension | Codec |
|
|
93
|
+
|-----------|-----------|-------|
|
|
94
|
+
| MKV | `.mkv` | Matroska |
|
|
95
|
+
| AVI | `.avi` | AVI |
|
|
96
|
+
| MOV | `.mov` | QuickTime |
|
|
97
|
+
| MP3 | `.mp3` | MPEG Audio |
|
|
98
|
+
| AAC | `.aac` | AAC |
|
|
99
|
+
| FLAC | `.flac` | FLAC |
|
|
100
|
+
| OGG | `.ogg` | Ogg Vorbis |
|
|
101
|
+
| WAV | `.wav` | WAV |
|
|
102
|
+
|
|
103
|
+
When requesting a container that requires conversion, yt-direct throws a `FormatError` with a clear message. Use `merge` to convert:
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
const video = await ytdl(url, {
|
|
107
|
+
quality: '1080p',
|
|
108
|
+
format: 'mkv',
|
|
109
|
+
merge: { tool: 'ffmpeg' }, // auto-detect ffmpeg
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
await video.merge('./output.mkv');
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Quality Reference
|
|
118
|
+
|
|
119
|
+
| Quality | Resolution | Typical Bitrate (Video) |
|
|
120
|
+
|---------|-----------|----------------------|
|
|
121
|
+
| 4320p | 7680×4320 | 40–80 Mbps |
|
|
122
|
+
| 2160p | 3840×2160 | 20–45 Mbps |
|
|
123
|
+
| 1440p | 2560×1440 | 10–20 Mbps |
|
|
124
|
+
| 1080p | 1920×1080 | 5–12 Mbps |
|
|
125
|
+
| 720p | 1280×720 | 2.5–6 Mbps |
|
|
126
|
+
| 480p | 854×480 | 1–3 Mbps |
|
|
127
|
+
| 360p | 640×360 | 0.5–1.5 Mbps |
|
|
128
|
+
| 240p | 426×240 | 0.3–0.8 Mbps |
|
|
129
|
+
| 144p | 256×144 | 0.1–0.4 Mbps |
|
|
130
|
+
| audio | — | 32–256 Kbps |
|
|
131
|
+
|
|
132
|
+
Quality fallback: if the requested quality is unavailable, the next lower tier is tried automatically.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Audio-Only
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
const audio = await ytdl(url, { quality: 'audio', format: 'm4a' });
|
|
140
|
+
await audio.download('./audio.m4a');
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
For MP3 output:
|
|
144
|
+
```javascript
|
|
145
|
+
const audio = await ytdl(url, {
|
|
146
|
+
quality: 'audio',
|
|
147
|
+
format: 'mp3',
|
|
148
|
+
merge: { tool: 'ffmpeg' },
|
|
149
|
+
});
|
|
150
|
+
await audio.merge('./audio.mp3');
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Merging Audio + Video
|
|
156
|
+
|
|
157
|
+
For high-quality downloads (1080p+), YouTube provides separate video and audio streams. Use the `merge` option to combine them:
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
const video = await ytdl(url, {
|
|
161
|
+
quality: '2160p',
|
|
162
|
+
format: 'mp4',
|
|
163
|
+
merge: {
|
|
164
|
+
tool: 'ffmpeg', // or 'avconv'
|
|
165
|
+
path: '/usr/bin/ffmpeg', // optional custom path
|
|
166
|
+
output: './output.mp4', // optional (auto-generated)
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await video.merge();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
If format conversion is needed (e.g., mp4 → mkv), yt-direct prompts you with:
|
|
174
|
+
|
|
175
|
+
> *Format "mkv" requires a merge/convert tool. Use { merge: { tool: "ffmpeg", output: "file.mkv" } }.*
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Get Video Info
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
const info = await ytdl.getInfo('https://youtube.com/watch?v=xxx');
|
|
183
|
+
|
|
184
|
+
console.log(info.title);
|
|
185
|
+
console.log(info.formats); // all available formats
|
|
186
|
+
console.log(info.combined); // audio+video formats
|
|
187
|
+
console.log(info.adaptive); // separate audio/video streams
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Streaming / Piping
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
const fs = require('node:fs');
|
|
196
|
+
const video = await ytdl(url, { quality: '720p' });
|
|
197
|
+
video.pipe(fs.createWriteStream('./video.mp4'));
|
|
198
|
+
|
|
199
|
+
// Or use stream()
|
|
200
|
+
const stream = video.stream();
|
|
201
|
+
stream.pipe(fs.createWriteStream('./video.mp4'));
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Error Handling
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
const { FormatError, ValidationError, YouTubeError } = ytdl;
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
await ytdl(url, { format: 'mp3' });
|
|
213
|
+
} catch (err) {
|
|
214
|
+
if (err instanceof FormatError) {
|
|
215
|
+
console.log('Format unavailable:', err.message);
|
|
216
|
+
// err.details contains resolution info
|
|
217
|
+
} else if (err instanceof ValidationError) {
|
|
218
|
+
console.log('Invalid options:', err.message);
|
|
219
|
+
} else {
|
|
220
|
+
console.log('YouTube error:', err.message);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Available Formats & Qualities
|
|
228
|
+
|
|
229
|
+
```javascript
|
|
230
|
+
console.log('Formats:', ytdl.FORMATS);
|
|
231
|
+
console.log('Qualities:', ytdl.QUALITIES);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Formats:** `mp4`, `webm`, `mkv`, `avi`, `mov`, `m4a`, `aac`, `flac`, `ogg`, `mp3`, `wav`
|
|
235
|
+
|
|
236
|
+
**Qualities:** `4320p`, `2160p`, `1440p`, `1080p`, `720p`, `480p`, `360p`, `240p`, `144p`, `auto`, `best`, `audio`
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Getting the Download URL (without downloading)
|
|
241
|
+
|
|
242
|
+
```javascript
|
|
243
|
+
const ytdl = require('yt-direct');
|
|
244
|
+
|
|
245
|
+
(async () => {
|
|
246
|
+
const video = await ytdl('https://www.youtube.com/watch?v=dQw4w9WgXcQ', {
|
|
247
|
+
quality: '1080p',
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
console.log('Title:', video.title);
|
|
251
|
+
console.log('Video URL:', video.url);
|
|
252
|
+
if (video.audio) console.log('Audio URL:', video.audio.url);
|
|
253
|
+
|
|
254
|
+
// Use the URL directly with curl, wget, etc.
|
|
255
|
+
})();
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
If you only need to inspect formats without selecting one:
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
const info = await ytdl.getInfo('https://youtube.com/watch?v=xxx');
|
|
262
|
+
console.log(info.formats); // array of { itag, quality, container, codec, size, url }
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Requirements
|
|
268
|
+
|
|
269
|
+
- Node.js 18+ (uses native fetch-compatible modules)
|
package/dist/.integrity
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6209fc3fb8c9d05879bee4b001aa61dd647ccccf455a8fe22ed77e94ecef86eb
|