@hallelx/tytube 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/LICENSE +24 -0
- package/README.md +189 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2708 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +2552 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +488 -0
- package/dist/index.d.ts +488 -0
- package/dist/index.js +2523 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tytube contributors
|
|
4
|
+
|
|
5
|
+
Portions of this software are derived from pytube
|
|
6
|
+
(https://github.com/pytube/pytube), originally released under The Unlicense.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# tytube
|
|
4
|
+
|
|
5
|
+
**A TypeScript port of [pytube](https://github.com/pytube/pytube). Extract YouTube metadata, list streams, and read captions — without the YouTube Data API.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@hallelx/tytube)
|
|
8
|
+
[](https://www.npmjs.com/package/@hallelx/tytube)
|
|
9
|
+
[](https://bundlephobia.com/package/@hallelx/tytube)
|
|
10
|
+
[](https://github.com/hallelx2/tytube/actions/workflows/ci.yml)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
[](tsconfig.json)
|
|
13
|
+
[](package.json)
|
|
14
|
+
[](https://bun.sh)
|
|
15
|
+
[](tests)
|
|
16
|
+
|
|
17
|
+
`youtube` · `metadata` · `streams` · `captions` · `playlist` · `channel` · `search` · `no-api-key` · `pytube` · `bun` · `node` · `esm`
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
> **Status: pre-release.** Metadata extraction, stream discovery, and caption listing all work end-to-end against live YouTube. Full media downloads require a working `n`-parameter cipher against YouTube's current `base.js` and are not yet implemented in v0.1 — see [Limitations](#limitations).
|
|
24
|
+
|
|
25
|
+
## Why tytube?
|
|
26
|
+
|
|
27
|
+
Existing JS YouTube libraries either wrap a Python binary (`youtube-dl-exec`), depend on the YouTube Data API v3 (rate limits + API key required), or break under non-Node runtimes. tytube is a **pure TypeScript** rewrite of pytube's API surface that runs natively under **Bun**, has **zero runtime dependencies**, and ships **ESM + CJS + .d.ts** out of the box.
|
|
28
|
+
|
|
29
|
+
- **No Python**, no `yt-dlp` shell-out, no Data API key.
|
|
30
|
+
- **Zero runtime dependencies** — just `fetch` and (optionally) `node:fs`.
|
|
31
|
+
- **1:1 pytube API parity** — if you know pytube, you know tytube.
|
|
32
|
+
- **First-class Bun support** — built and tested on Bun matrix CI.
|
|
33
|
+
- **Strict TypeScript** with full `.d.ts` declarations and `noUncheckedIndexedAccess`.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bun add @hallelx/tytube # Bun
|
|
39
|
+
npm install @hallelx/tytube # Node
|
|
40
|
+
pnpm add @hallelx/tytube # pnpm
|
|
41
|
+
yarn add @hallelx/tytube # Yarn
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick start
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { YouTube } from '@hallelx/tytube';
|
|
48
|
+
|
|
49
|
+
const yt = new YouTube('https://youtu.be/lpFcNQpH81Q');
|
|
50
|
+
await yt.prefetch();
|
|
51
|
+
|
|
52
|
+
console.log(await yt.title()); // "Build a Language Learning Mobile App: …"
|
|
53
|
+
console.log(await yt.author()); // "Andreas Trolle"
|
|
54
|
+
console.log(await yt.length()); // 31126 (seconds)
|
|
55
|
+
console.log(await yt.views()); // 16372
|
|
56
|
+
|
|
57
|
+
const streams = await yt.streams();
|
|
58
|
+
console.log(`Found ${streams.length} streams`);
|
|
59
|
+
for (const stream of streams) {
|
|
60
|
+
console.log(stream.toString());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const captions = await yt.captions();
|
|
64
|
+
for (const c of captions) {
|
|
65
|
+
console.log(`${c.code}: ${c.name}`);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
After `prefetch()`, the `*Sync` getters work without further I/O:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
console.log(yt.titleSync);
|
|
73
|
+
console.log(yt.authorSync);
|
|
74
|
+
console.log(yt.streamsSync.length);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Playlists, channels, and search
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { Playlist, Channel, Search } from '@hallelx/tytube';
|
|
81
|
+
|
|
82
|
+
// Playlist iteration — async iterable, lazily paged
|
|
83
|
+
const playlist = new Playlist('https://www.youtube.com/playlist?list=PL...');
|
|
84
|
+
console.log(await playlist.title());
|
|
85
|
+
for await (const video of playlist) {
|
|
86
|
+
console.log(await video.title());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Channel videos
|
|
90
|
+
const channel = new Channel('https://www.youtube.com/c/SomeChannel');
|
|
91
|
+
console.log(await channel.channelName());
|
|
92
|
+
for await (const video of channel) {
|
|
93
|
+
console.log(await video.title());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Search results
|
|
97
|
+
const search = new Search('typescript tutorial');
|
|
98
|
+
const results = await search.results();
|
|
99
|
+
for (const yt of results) {
|
|
100
|
+
console.log(await yt.title());
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## CLI
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
bunx @hallelx/tytube https://youtu.be/lpFcNQpH81Q --list
|
|
108
|
+
bunx @hallelx/tytube https://youtu.be/lpFcNQpH81Q --list-captions
|
|
109
|
+
bunx @hallelx/tytube https://youtu.be/lpFcNQpH81Q -c en -t ./captions
|
|
110
|
+
bunx @hallelx/tytube --version
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> Download flags (`-r`, `--itag`, `-a`, `-f`) are wired up but currently constrained by the cipher limitation below.
|
|
114
|
+
|
|
115
|
+
## API parity with pytube
|
|
116
|
+
|
|
117
|
+
All metadata getters are async because they may trigger network I/O on first call. After `prefetch()`, sync `*Sync` getters work for hot-path access.
|
|
118
|
+
|
|
119
|
+
| pytube | tytube |
|
|
120
|
+
| --------------------------------------- | ----------------------------------------------- |
|
|
121
|
+
| `YouTube(url)` | `new YouTube(url)` |
|
|
122
|
+
| `yt.title` | `await yt.title()` · `yt.titleSync` |
|
|
123
|
+
| `yt.author` | `await yt.author()` |
|
|
124
|
+
| `yt.length` | `await yt.length()` |
|
|
125
|
+
| `yt.views` | `await yt.views()` |
|
|
126
|
+
| `yt.streams` | `await yt.streams()` |
|
|
127
|
+
| `yt.captions` | `await yt.captions()` |
|
|
128
|
+
| `yt.thumbnail_url` | `await yt.thumbnailUrl()` |
|
|
129
|
+
| `yt.channel_url` | `await yt.channelUrl()` |
|
|
130
|
+
| `yt.publish_date` | `await yt.publishDate()` |
|
|
131
|
+
| `yt.metadata` | `await yt.metadata()` |
|
|
132
|
+
| `Playlist(url).videos` | `for await (const v of new Playlist(url))` |
|
|
133
|
+
| `Channel(url).videos` | `for await (const v of new Channel(url))` |
|
|
134
|
+
| `Search(q).results` | `await new Search(q).results()` |
|
|
135
|
+
| `stream.download(output_path=…)` | `await stream.download({ outputPath: '…' })` |
|
|
136
|
+
| `caption.generate_srt_captions()` | `await caption.generateSrtCaptions()` |
|
|
137
|
+
|
|
138
|
+
Filtering streams works the same way:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const streams = await yt.streams();
|
|
142
|
+
|
|
143
|
+
streams.getHighestResolution();
|
|
144
|
+
streams.getLowestResolution();
|
|
145
|
+
streams.getAudioOnly('mp4');
|
|
146
|
+
streams.getByItag(22);
|
|
147
|
+
streams.getByResolution('720p');
|
|
148
|
+
streams.filter({ progressive: true, subtype: 'mp4' }).orderBy('resolution').last();
|
|
149
|
+
streams.filter({ onlyAudio: true }).orderBy('abr').last();
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Runtime support
|
|
153
|
+
|
|
154
|
+
| Runtime | Status |
|
|
155
|
+
| -------------------- | --------------------------------------------------------------------------------------- |
|
|
156
|
+
| Node.js ≥18 | ✅ Full support |
|
|
157
|
+
| Bun ≥1.0 | ✅ Full support — built and CI-tested on Bun |
|
|
158
|
+
| Deno | ✅ Works with `--allow-net` (uses global `fetch`) |
|
|
159
|
+
| Browser | ⚠️ Requires a CORS proxy — YouTube does not send CORS headers |
|
|
160
|
+
| Cloudflare Workers | ⚠️ Cipher path requires `Function()` which is blocked under default CSP |
|
|
161
|
+
|
|
162
|
+
## Limitations
|
|
163
|
+
|
|
164
|
+
**Media downloads currently fail with HTTP 403.** YouTube ciphers the `n` parameter on stream URLs, and decoding `n` requires running JavaScript extracted from YouTube's `base.js`. tytube's cipher extractor uses pytube's regex patterns, which YouTube's late-2025 `base.js` has drifted beyond. This is the same problem pytube has hit repeatedly — YouTube rotates `base.js` and breaks the regex.
|
|
165
|
+
|
|
166
|
+
**The metadata extraction path works completely** because it parses `ytInitialPlayerResponse` directly from the watch HTML, which doesn't depend on cipher decryption.
|
|
167
|
+
|
|
168
|
+
If you need actual media downloads today, use yt-dlp via `child_process.spawn` as a temporary bridge while we iterate on the cipher. We're tracking the cipher fix as the headline issue for v0.2.
|
|
169
|
+
|
|
170
|
+
## Contributing
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
git clone https://github.com/hallelx2/tytube
|
|
174
|
+
cd tytube
|
|
175
|
+
bun install
|
|
176
|
+
bunx vitest run # 45 tests, all passing
|
|
177
|
+
bunx tsup # build dist/
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
The package mirrors pytube's module layout 1:1 in [`src/`](src) so contributors can read both side-by-side. The Python pytube source lives in the parent directory at `../pytube/pytube/` as a read-only reference.
|
|
181
|
+
|
|
182
|
+
## Acknowledgements
|
|
183
|
+
|
|
184
|
+
- The original [pytube](https://github.com/pytube/pytube) project, whose architecture and regex patterns this port closely follows.
|
|
185
|
+
- [yt-dlp](https://github.com/yt-dlp/yt-dlp) for keeping the InnerTube client configurations current.
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
[MIT](LICENSE), with portions derived from pytube (originally The Unlicense).
|
package/dist/cli.d.ts
ADDED