@ziplayer/plugin 0.1.33 → 0.1.40
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 +180 -180
- package/YTSR_README.md +310 -310
- package/dist/TTSPlugin.js.map +1 -1
- package/dist/YTSRPlugin.d.ts.map +1 -1
- package/dist/YTSRPlugin.js +17 -1
- package/dist/YTSRPlugin.js.map +1 -1
- package/dist/YouTubePlugin.d.ts +15 -6
- package/dist/YouTubePlugin.d.ts.map +1 -1
- package/dist/YouTubePlugin.js +122 -47
- package/dist/YouTubePlugin.js.map +1 -1
- package/dist/utils/progress-bar.d.ts +8 -0
- package/dist/utils/progress-bar.d.ts.map +1 -0
- package/dist/utils/progress-bar.js +24 -0
- package/dist/utils/progress-bar.js.map +1 -0
- package/dist/utils/sabr-stream-factory.d.ts +25 -0
- package/dist/utils/sabr-stream-factory.d.ts.map +1 -0
- package/dist/utils/sabr-stream-factory.js +83 -0
- package/dist/utils/sabr-stream-factory.js.map +1 -0
- package/dist/utils/stream-converter.d.ts +10 -0
- package/dist/utils/stream-converter.d.ts.map +1 -0
- package/dist/utils/stream-converter.js +78 -0
- package/dist/utils/stream-converter.js.map +1 -0
- package/package.json +44 -42
- package/src/SoundCloudPlugin.ts +368 -368
- package/src/SpotifyPlugin.ts +312 -312
- package/src/TTSPlugin.ts +361 -361
- package/src/YTSRPlugin.ts +596 -583
- package/src/YouTubePlugin.ts +620 -528
- package/src/index.ts +103 -103
- package/src/types/googlevideo.d.ts +45 -0
- package/src/utils/sabr-stream-factory.ts +96 -0
- package/src/utils/stream-converter.ts +87 -0
- package/tsconfig.json +23 -23
package/README.md
CHANGED
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
<img width="1175" height="305" alt="logo" src="https://
|
|
2
|
-
|
|
3
|
-
# @ziplayer/plugin
|
|
4
|
-
|
|
5
|
-
Official plugin bundle for ZiPlayer. It ships a set of ready‑to‑use source plugins you can register on your `PlayerManager`:
|
|
6
|
-
|
|
7
|
-
- YouTubePlugin: search + stream YouTube videos and playlists
|
|
8
|
-
- SoundCloudPlugin: search + stream SoundCloud tracks and sets
|
|
9
|
-
- SpotifyPlugin: resolve tracks/albums/playlists, stream via fallbacks
|
|
10
|
-
- TTSPlugin: Text‑to‑Speech playback from simple `tts:` queries
|
|
11
|
-
|
|
12
|
-
ZiPlayer is an audio player built on top of `@discordjs/voice` and `discord.js`. This package provides sources; the core player
|
|
13
|
-
lives in `ziplayer`.
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @ziplayer/plugin ziplayer @discordjs/voice discord.js
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
The TTS plugin uses a lightweight Google TTS wrapper and HTTP fetches:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @zibot/zitts axios
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Quick Start
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
import { PlayerManager } from "ziplayer";
|
|
31
|
-
import { YouTubePlugin, SoundCloudPlugin, SpotifyPlugin, TTSPlugin } from "@ziplayer/plugin";
|
|
32
|
-
|
|
33
|
-
const manager = new PlayerManager({
|
|
34
|
-
plugins: [
|
|
35
|
-
// Order matters: put more specific handlers first (e.g., TTS)
|
|
36
|
-
new TTSPlugin({ defaultLang: "en" }),
|
|
37
|
-
new YouTubePlugin(),
|
|
38
|
-
new SoundCloudPlugin(),
|
|
39
|
-
new SpotifyPlugin(),
|
|
40
|
-
],
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Create and connect a player (discord.js VoiceChannel instance)
|
|
44
|
-
const player = manager.create(guildId, { userdata: { channel: textChannel } });
|
|
45
|
-
await player.connect(voiceChannel);
|
|
46
|
-
|
|
47
|
-
// Search & play
|
|
48
|
-
await player.play("never gonna give you up", requestedBy);
|
|
49
|
-
|
|
50
|
-
// Play a playlist URL directly
|
|
51
|
-
await player.play("https://www.youtube.com/playlist?list=...", requestedBy);
|
|
52
|
-
|
|
53
|
-
// Speak with TTS
|
|
54
|
-
await player.play("tts:en:Hello there!", requestedBy);
|
|
55
|
-
|
|
56
|
-
// Handle events via the manager
|
|
57
|
-
manager.on("trackStart", (plr, track) => {
|
|
58
|
-
plr.userdata?.channel?.send?.(`Now playing: ${track.title}`);
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Included Plugins
|
|
63
|
-
|
|
64
|
-
### YouTubePlugin
|
|
65
|
-
|
|
66
|
-
- Resolves YouTube videos and playlists.
|
|
67
|
-
- Uses `youtubei.js` under the hood.
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import { YouTubePlugin } from "@ziplayer/plugin";
|
|
71
|
-
const youtube = new YouTubePlugin();
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### SoundCloudPlugin
|
|
75
|
-
|
|
76
|
-
- Resolves tracks and sets. You may further tune streaming by combining with other plugins that provide fallbacks.
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
import { SoundCloudPlugin } from "@ziplayer/plugin";
|
|
80
|
-
const sc = new SoundCloudPlugin();
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### SpotifyPlugin
|
|
84
|
-
|
|
85
|
-
- Resolves track/album/playlist metadata from Spotify.
|
|
86
|
-
- Streaming typically uses fallback sources (e.g., YouTube) discovered by your plugin set.
|
|
87
|
-
|
|
88
|
-
```ts
|
|
89
|
-
import { SpotifyPlugin } from "@ziplayer/plugin";
|
|
90
|
-
const sp = new SpotifyPlugin();
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### TTSPlugin (Text‑to‑Speech)
|
|
94
|
-
|
|
95
|
-
- Plays spoken audio from text using a lightweight Google TTS wrapper.
|
|
96
|
-
- Supported query formats:
|
|
97
|
-
- `tts: <text>`
|
|
98
|
-
- `tts:<lang>:<text>` (e.g., `tts:vi:xin chao`)
|
|
99
|
-
- `tts:<lang>:1:<text>` (set `slow = true`, `0` = normal)
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
import { TTSPlugin } from "@ziplayer/plugin";
|
|
103
|
-
const tts = new TTSPlugin({ defaultLang: "en", slow: false });
|
|
104
|
-
await player.play("tts:en:1:good morning", requestedBy);
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Note: Please comply with the service’s terms and provide your own quotas. The wrapper is intended for lightweight usage and may
|
|
108
|
-
change without notice.
|
|
109
|
-
|
|
110
|
-
Advanced: custom TTS provider
|
|
111
|
-
|
|
112
|
-
You can override audio generation by passing a `createStream` function. It receives the text and context and can return a Node
|
|
113
|
-
`Readable`, an HTTP(S) URL string, or a `Buffer`.
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
const tts = new TTSPlugin({
|
|
117
|
-
defaultLang: "vi",
|
|
118
|
-
async createStream(text, ctx) {
|
|
119
|
-
// Example: integrate with Azure, CAMB.AI, etc.
|
|
120
|
-
// Return a URL and the plugin will stream it
|
|
121
|
-
const url = await myTTSService(text, { lang: ctx?.lang, slow: ctx?.slow });
|
|
122
|
-
return url; // or Readable / Buffer
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## Writing Your Own Plugin
|
|
128
|
-
|
|
129
|
-
Plugins implement the `BasePlugin` contract from `ziplayer`:
|
|
130
|
-
|
|
131
|
-
```ts
|
|
132
|
-
import { BasePlugin, Track, SearchResult, StreamInfo } from "ziplayer";
|
|
133
|
-
|
|
134
|
-
export class MyPlugin extends BasePlugin {
|
|
135
|
-
name = "myplugin";
|
|
136
|
-
version = "1.0.0";
|
|
137
|
-
|
|
138
|
-
canHandle(query: string): boolean {
|
|
139
|
-
// Return true if this plugin can handle a given query/URL
|
|
140
|
-
return query.includes("mysite.com");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async search(query: string, requestedBy: string): Promise<SearchResult> {
|
|
144
|
-
// Return one or more tracks for the query
|
|
145
|
-
return {
|
|
146
|
-
tracks: [
|
|
147
|
-
{
|
|
148
|
-
id: "abc",
|
|
149
|
-
title: "My Track",
|
|
150
|
-
url: "https://mysite.com/track/abc",
|
|
151
|
-
duration: 180,
|
|
152
|
-
requestedBy,
|
|
153
|
-
source: this.name,
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async getStream(track: Track): Promise<StreamInfo> {
|
|
160
|
-
// Return a Node Readable stream and an input type
|
|
161
|
-
return { stream, type: "arbitrary" };
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
Tips
|
|
167
|
-
|
|
168
|
-
- Keep network calls bounded; ZiPlayer applies timeouts to extractor operations.
|
|
169
|
-
- For sources that require indirection (like Spotify), consider a `getFallback` strategy via other plugins.
|
|
170
|
-
- Use `track.metadata` for any source‑specific fields you want to carry along.
|
|
171
|
-
|
|
172
|
-
## Requirements
|
|
173
|
-
|
|
174
|
-
- Node.js 18+
|
|
175
|
-
- `discord.js` 14 and `@discordjs/voice` 0.19+
|
|
176
|
-
- For TTS: `@zibot/zitts` and `axios`
|
|
177
|
-
|
|
178
|
-
## License
|
|
179
|
-
|
|
180
|
-
MIT
|
|
1
|
+
<img width="1175" height="305" alt="logo" src="https://raw.githubusercontent.com/ZiProject/ZiPlayer/refs/heads/main/publish/logo.png" />
|
|
2
|
+
|
|
3
|
+
# @ziplayer/plugin
|
|
4
|
+
|
|
5
|
+
Official plugin bundle for ZiPlayer. It ships a set of ready‑to‑use source plugins you can register on your `PlayerManager`:
|
|
6
|
+
|
|
7
|
+
- YouTubePlugin: search + stream YouTube videos and playlists
|
|
8
|
+
- SoundCloudPlugin: search + stream SoundCloud tracks and sets
|
|
9
|
+
- SpotifyPlugin: resolve tracks/albums/playlists, stream via fallbacks
|
|
10
|
+
- TTSPlugin: Text‑to‑Speech playback from simple `tts:` queries
|
|
11
|
+
|
|
12
|
+
ZiPlayer is an audio player built on top of `@discordjs/voice` and `discord.js`. This package provides sources; the core player
|
|
13
|
+
lives in `ziplayer`.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @ziplayer/plugin ziplayer @discordjs/voice discord.js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The TTS plugin uses a lightweight Google TTS wrapper and HTTP fetches:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @zibot/zitts axios
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { PlayerManager } from "ziplayer";
|
|
31
|
+
import { YouTubePlugin, SoundCloudPlugin, SpotifyPlugin, TTSPlugin } from "@ziplayer/plugin";
|
|
32
|
+
|
|
33
|
+
const manager = new PlayerManager({
|
|
34
|
+
plugins: [
|
|
35
|
+
// Order matters: put more specific handlers first (e.g., TTS)
|
|
36
|
+
new TTSPlugin({ defaultLang: "en" }),
|
|
37
|
+
new YouTubePlugin(),
|
|
38
|
+
new SoundCloudPlugin(),
|
|
39
|
+
new SpotifyPlugin(),
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Create and connect a player (discord.js VoiceChannel instance)
|
|
44
|
+
const player = await manager.create(guildId, { userdata: { channel: textChannel } });
|
|
45
|
+
await player.connect(voiceChannel);
|
|
46
|
+
|
|
47
|
+
// Search & play
|
|
48
|
+
await player.play("never gonna give you up", requestedBy);
|
|
49
|
+
|
|
50
|
+
// Play a playlist URL directly
|
|
51
|
+
await player.play("https://www.youtube.com/playlist?list=...", requestedBy);
|
|
52
|
+
|
|
53
|
+
// Speak with TTS
|
|
54
|
+
await player.play("tts:en:Hello there!", requestedBy);
|
|
55
|
+
|
|
56
|
+
// Handle events via the manager
|
|
57
|
+
manager.on("trackStart", (plr, track) => {
|
|
58
|
+
plr.userdata?.channel?.send?.(`Now playing: ${track.title}`);
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Included Plugins
|
|
63
|
+
|
|
64
|
+
### YouTubePlugin
|
|
65
|
+
|
|
66
|
+
- Resolves YouTube videos and playlists.
|
|
67
|
+
- Uses `youtubei.js` under the hood.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { YouTubePlugin } from "@ziplayer/plugin";
|
|
71
|
+
const youtube = new YouTubePlugin();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### SoundCloudPlugin
|
|
75
|
+
|
|
76
|
+
- Resolves tracks and sets. You may further tune streaming by combining with other plugins that provide fallbacks.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { SoundCloudPlugin } from "@ziplayer/plugin";
|
|
80
|
+
const sc = new SoundCloudPlugin();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### SpotifyPlugin
|
|
84
|
+
|
|
85
|
+
- Resolves track/album/playlist metadata from Spotify.
|
|
86
|
+
- Streaming typically uses fallback sources (e.g., YouTube) discovered by your plugin set.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { SpotifyPlugin } from "@ziplayer/plugin";
|
|
90
|
+
const sp = new SpotifyPlugin();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### TTSPlugin (Text‑to‑Speech)
|
|
94
|
+
|
|
95
|
+
- Plays spoken audio from text using a lightweight Google TTS wrapper.
|
|
96
|
+
- Supported query formats:
|
|
97
|
+
- `tts: <text>`
|
|
98
|
+
- `tts:<lang>:<text>` (e.g., `tts:vi:xin chao`)
|
|
99
|
+
- `tts:<lang>:1:<text>` (set `slow = true`, `0` = normal)
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { TTSPlugin } from "@ziplayer/plugin";
|
|
103
|
+
const tts = new TTSPlugin({ defaultLang: "en", slow: false });
|
|
104
|
+
await player.play("tts:en:1:good morning", requestedBy);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Note: Please comply with the service’s terms and provide your own quotas. The wrapper is intended for lightweight usage and may
|
|
108
|
+
change without notice.
|
|
109
|
+
|
|
110
|
+
Advanced: custom TTS provider
|
|
111
|
+
|
|
112
|
+
You can override audio generation by passing a `createStream` function. It receives the text and context and can return a Node
|
|
113
|
+
`Readable`, an HTTP(S) URL string, or a `Buffer`.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const tts = new TTSPlugin({
|
|
117
|
+
defaultLang: "vi",
|
|
118
|
+
async createStream(text, ctx) {
|
|
119
|
+
// Example: integrate with Azure, CAMB.AI, etc.
|
|
120
|
+
// Return a URL and the plugin will stream it
|
|
121
|
+
const url = await myTTSService(text, { lang: ctx?.lang, slow: ctx?.slow });
|
|
122
|
+
return url; // or Readable / Buffer
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Writing Your Own Plugin
|
|
128
|
+
|
|
129
|
+
Plugins implement the `BasePlugin` contract from `ziplayer`:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { BasePlugin, Track, SearchResult, StreamInfo } from "ziplayer";
|
|
133
|
+
|
|
134
|
+
export class MyPlugin extends BasePlugin {
|
|
135
|
+
name = "myplugin";
|
|
136
|
+
version = "1.0.0";
|
|
137
|
+
|
|
138
|
+
canHandle(query: string): boolean {
|
|
139
|
+
// Return true if this plugin can handle a given query/URL
|
|
140
|
+
return query.includes("mysite.com");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async search(query: string, requestedBy: string): Promise<SearchResult> {
|
|
144
|
+
// Return one or more tracks for the query
|
|
145
|
+
return {
|
|
146
|
+
tracks: [
|
|
147
|
+
{
|
|
148
|
+
id: "abc",
|
|
149
|
+
title: "My Track",
|
|
150
|
+
url: "https://mysite.com/track/abc",
|
|
151
|
+
duration: 180,
|
|
152
|
+
requestedBy,
|
|
153
|
+
source: this.name,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async getStream(track: Track): Promise<StreamInfo> {
|
|
160
|
+
// Return a Node Readable stream and an input type
|
|
161
|
+
return { stream, type: "arbitrary" };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Tips
|
|
167
|
+
|
|
168
|
+
- Keep network calls bounded; ZiPlayer applies timeouts to extractor operations.
|
|
169
|
+
- For sources that require indirection (like Spotify), consider a `getFallback` strategy via other plugins.
|
|
170
|
+
- Use `track.metadata` for any source‑specific fields you want to carry along.
|
|
171
|
+
|
|
172
|
+
## Requirements
|
|
173
|
+
|
|
174
|
+
- Node.js 18+
|
|
175
|
+
- `discord.js` 14 and `@discordjs/voice` 0.19+
|
|
176
|
+
- For TTS: `@zibot/zitts` and `axios`
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT
|