@khang07/zing-mp3-api 1.0.0 → 1.0.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 +21 -0
- package/README.md +323 -0
- package/dist/.types/index.d.ts +10 -7
- package/dist/.types/types/fetch.d.ts +8 -1
- package/dist/cjs/index.cjs +54 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +54 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +20 -18
- package/package.json +5 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GiaKhang
|
|
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,323 @@
|
|
|
1
|
+
# @khang07/zing-mp3-api
|
|
2
|
+
|
|
3
|
+
Node.js library để lấy stream nhạc và video từ Zing MP3 dưới dạng `Readable` stream.
|
|
4
|
+
|
|
5
|
+
Package này hiện tập trung vào 2 tác vụ chính:
|
|
6
|
+
|
|
7
|
+
- Lấy **nhạc** theo ID và trả về stream audio
|
|
8
|
+
- Lấy **video** theo ID và trả về stream video HLS
|
|
9
|
+
|
|
10
|
+
Library build sẵn cho cả **ESM** và **CommonJS**, có type cho TypeScript.
|
|
11
|
+
|
|
12
|
+
## Tính năng
|
|
13
|
+
|
|
14
|
+
- Export sẵn `client` dùng ngay
|
|
15
|
+
- Có thể tự tạo `new Client()` để chỉnh tốc độ stream/buffer
|
|
16
|
+
- Trả về `Readable` stream để pipe thẳng ra file, HTTP response, Discord voice pipeline, hoặc xử lý tiếp
|
|
17
|
+
- Có cookie jar nội bộ để giữ cookie giữa các request
|
|
18
|
+
- Có chữ ký request nội bộ cho API đang dùng
|
|
19
|
+
- Hỗ trợ ESM, CJS, TypeScript
|
|
20
|
+
|
|
21
|
+
## Cài đặt
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @khang07/zing-mp3-api
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
hoặc
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @khang07/zing-mp3-api
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Yêu cầu môi trường
|
|
34
|
+
|
|
35
|
+
Package này chạy cho **Node.js**, không dành cho browser vì dùng:
|
|
36
|
+
|
|
37
|
+
- `node:stream`
|
|
38
|
+
- `node:crypto`
|
|
39
|
+
- `axios` với Node adapter
|
|
40
|
+
- `m3u8stream`
|
|
41
|
+
|
|
42
|
+
## Dùng nhanh
|
|
43
|
+
|
|
44
|
+
### ESM
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import client from "@khang07/zing-mp3-api";
|
|
48
|
+
import { createWriteStream } from "node:fs";
|
|
49
|
+
|
|
50
|
+
const writer = createWriteStream("music.mp3");
|
|
51
|
+
const stream = await client.music("MUSIC_ID");
|
|
52
|
+
|
|
53
|
+
stream.pipe(writer);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### ESM với named import
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { client, Client } from "@khang07/zing-mp3-api";
|
|
60
|
+
import { createWriteStream } from "node:fs";
|
|
61
|
+
|
|
62
|
+
const musicWriter = createWriteStream("music.mp3");
|
|
63
|
+
client.musicSyncLike("MUSIC_ID").pipe(musicWriter);
|
|
64
|
+
|
|
65
|
+
const customClient = new Client({
|
|
66
|
+
maxRate: [256 * 1024, 64 * 1024]
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const videoWriter = createWriteStream("video.bin");
|
|
70
|
+
const videoStream = await customClient.video("VIDEO_ID");
|
|
71
|
+
videoStream.pipe(videoWriter);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### CommonJS
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
const { client, Client } = require("@khang07/zing-mp3-api");
|
|
78
|
+
const { createWriteStream } = require("node:fs");
|
|
79
|
+
|
|
80
|
+
const writer = createWriteStream("music.mp3");
|
|
81
|
+
client.musicSyncLike("MUSIC_ID").pipe(writer);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## API
|
|
85
|
+
|
|
86
|
+
### `new Client(options?)`
|
|
87
|
+
|
|
88
|
+
Tạo client mới.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { Client } from "@khang07/zing-mp3-api";
|
|
92
|
+
|
|
93
|
+
const client = new Client({
|
|
94
|
+
maxRate: [100 * 1024, 16 * 1024]
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### `ClientOptions`
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
interface ClientOptions {
|
|
102
|
+
maxRate?: [download?: number, highWaterMark?: number];
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Ý nghĩa:
|
|
107
|
+
|
|
108
|
+
- `download`: giới hạn tốc độ download cho request stream
|
|
109
|
+
- `highWaterMark`: buffer size cho `PassThrough` của các hàm `SyncLike`
|
|
110
|
+
|
|
111
|
+
Giá trị mặc định:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
[100 * 1024, 16 * 1024]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Các method
|
|
118
|
+
|
|
119
|
+
### `await client.music(musicID)`
|
|
120
|
+
|
|
121
|
+
Trả về `Promise<Readable>` cho audio stream.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import client from "@khang07/zing-mp3-api";
|
|
125
|
+
import { createWriteStream } from "node:fs";
|
|
126
|
+
|
|
127
|
+
const output = createWriteStream("music.mp3");
|
|
128
|
+
const stream = await client.music("ZZEEOZEC");
|
|
129
|
+
|
|
130
|
+
stream.pipe(output);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Ghi chú:
|
|
134
|
+
|
|
135
|
+
- Method này gọi API `/api/v2/song/get/streaming`
|
|
136
|
+
- Hiện tại code lấy URL tại `data[128]`
|
|
137
|
+
- Nghĩa là implementation hiện tại đang dùng nhánh stream **128 kbps**
|
|
138
|
+
|
|
139
|
+
### `client.musicSyncLike(musicID)`
|
|
140
|
+
|
|
141
|
+
Trả về `Readable` ngay để có thể pipe trực tiếp, phù hợp khi bạn muốn viết ngắn hơn.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import client from "@khang07/zing-mp3-api";
|
|
145
|
+
import { createWriteStream } from "node:fs";
|
|
146
|
+
|
|
147
|
+
client.musicSyncLike("ZZEEOZEC").pipe(createWriteStream("music.mp3"));
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### `await client.video(videoID)`
|
|
151
|
+
|
|
152
|
+
Trả về `Promise<Readable>` cho video stream.
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import client from "@khang07/zing-mp3-api";
|
|
156
|
+
import { createWriteStream } from "node:fs";
|
|
157
|
+
|
|
158
|
+
const output = createWriteStream("video.bin");
|
|
159
|
+
const stream = await client.video("ZZEEOZEC");
|
|
160
|
+
|
|
161
|
+
stream.pipe(output);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Ghi chú quan trọng:
|
|
165
|
+
|
|
166
|
+
- Method này gọi API `/api/v2/page/get/video`
|
|
167
|
+
- Hiện tại code chỉ lấy `streaming.hls["360p"]`
|
|
168
|
+
- Đây là **HLS stream** lấy qua `m3u8stream`
|
|
169
|
+
- Library **không transcode**, **không remux**, **không ép sang MP4 thật**
|
|
170
|
+
- Vì vậy bạn nên xem dữ liệu trả về là **stream media thô từ HLS**, không nên mặc định coi nó luôn là file `.mp4` chuẩn
|
|
171
|
+
|
|
172
|
+
### `client.videoSyncLike(videoID)`
|
|
173
|
+
|
|
174
|
+
Trả về `Readable` ngay để pipe trực tiếp.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import client from "@khang07/zing-mp3-api";
|
|
178
|
+
import { createWriteStream } from "node:fs";
|
|
179
|
+
|
|
180
|
+
client.videoSyncLike("ZZEEOZEC").pipe(createWriteStream("video.bin"));
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Bắt lỗi
|
|
184
|
+
|
|
185
|
+
Khi có lỗi, code ném ra error với các field thực tế đang có trong implementation:
|
|
186
|
+
|
|
187
|
+
- `name`: `ZING_MP3_ERROR`
|
|
188
|
+
- `message`
|
|
189
|
+
- `code`
|
|
190
|
+
- `status` (nếu có)
|
|
191
|
+
- `cause` (nếu có)
|
|
192
|
+
|
|
193
|
+
Các mã lỗi đang xuất hiện trong source:
|
|
194
|
+
|
|
195
|
+
- `ERROR_INVALID_ID`
|
|
196
|
+
- `ERROR_MUSIC_NOT_FOUND`
|
|
197
|
+
- `ERROR_MUSIC_VIP_ONLY`
|
|
198
|
+
- `ERROR_VIDEO_NOT_FOUND`
|
|
199
|
+
- `ERROR_STREAM_URL_NOT_FOUND`
|
|
200
|
+
- `ERROR_STREAM_DOWNLOAD`
|
|
201
|
+
- `ERROR_MUSIC_FETCH`
|
|
202
|
+
- `ERROR_VIDEO_FETCH`
|
|
203
|
+
|
|
204
|
+
Ví dụ:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import client from "@khang07/zing-mp3-api";
|
|
208
|
+
import { createWriteStream } from "node:fs";
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
const stream = await client.music("ZZEEOZEC");
|
|
212
|
+
const writer = createWriteStream("music.mp3");
|
|
213
|
+
|
|
214
|
+
stream.on("error", (error) => {
|
|
215
|
+
console.error("Stream error:", error);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
writer.on("error", (error) => {
|
|
219
|
+
console.error("Write error:", error);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
stream.pipe(writer);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error(error);
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Dùng với HTTP server
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import http from "node:http";
|
|
232
|
+
import client from "@khang07/zing-mp3-api";
|
|
233
|
+
|
|
234
|
+
const server = http.createServer(async (_req, res) => {
|
|
235
|
+
try {
|
|
236
|
+
const stream = await client.music("ZZEEOZEC");
|
|
237
|
+
|
|
238
|
+
res.writeHead(200, {
|
|
239
|
+
"Content-Type": "audio/mpeg"
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
stream.on("error", () => {
|
|
243
|
+
if (!res.headersSent)
|
|
244
|
+
res.writeHead(500);
|
|
245
|
+
|
|
246
|
+
res.end("Stream failed");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
stream.pipe(res);
|
|
250
|
+
} catch {
|
|
251
|
+
res.writeHead(500);
|
|
252
|
+
res.end("Failed to fetch music");
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
server.listen(3000);
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Build từ source
|
|
260
|
+
|
|
261
|
+
Project đang dùng TypeScript + Rollup + API Extractor.
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
bun install
|
|
265
|
+
bun run build
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Output build:
|
|
269
|
+
|
|
270
|
+
- `dist/esm` → bản ESM
|
|
271
|
+
- `dist/cjs` → bản CommonJS
|
|
272
|
+
- `dist/types` → type declarations gộp
|
|
273
|
+
|
|
274
|
+
Các script hiện có:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
bun run build:esm
|
|
278
|
+
bun run build:cjs
|
|
279
|
+
bun run build:types
|
|
280
|
+
bun run build
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Cấu trúc dự án
|
|
284
|
+
|
|
285
|
+
```text
|
|
286
|
+
source/
|
|
287
|
+
index.ts
|
|
288
|
+
types/
|
|
289
|
+
utils/
|
|
290
|
+
dist/
|
|
291
|
+
esm/
|
|
292
|
+
cjs/
|
|
293
|
+
types/
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Ghi chú triển khai hiện tại
|
|
297
|
+
|
|
298
|
+
Có vài điểm cần lưu ý:
|
|
299
|
+
|
|
300
|
+
- Chưa có API search public trong `Client` dù đang export type `SearchCategory`
|
|
301
|
+
- Video hiện mới lấy nhánh `360p`
|
|
302
|
+
- Music hiện mới lấy nhánh `128kps`
|
|
303
|
+
- Package phụ thuộc vào cấu trúc API/cookie/signature hiện tại của Zing MP3, nên nếu upstream đổi thì cần cập nhật source
|
|
304
|
+
|
|
305
|
+
## Ghi chú về file test trong repo
|
|
306
|
+
|
|
307
|
+
Trong repo hiện có `test/index.js` và `test/index.cjs`, nhưng chúng đang import từ `"zing-mp3-api"`.
|
|
308
|
+
|
|
309
|
+
Khi publish theo `package.json` hiện tại, import đúng cho người dùng ngoài sẽ là:
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
import { client } from "@khang07/zing-mp3-api";
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
hoặc:
|
|
316
|
+
|
|
317
|
+
```js
|
|
318
|
+
const { client } = require("@khang07/zing-mp3-api");
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
Xem tại [LICENSE](https://github.com/GiaKhang1810/zing-mp3-api#license)
|
package/dist/.types/index.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import type { ClientOptions, RequiredClientOptions, SearchCategory } from './types/index.js';
|
|
3
3
|
export type { ClientOptions, SearchCategory };
|
|
4
|
-
declare class
|
|
4
|
+
declare class ZingClient {
|
|
5
5
|
static readonly BASE_URL: string;
|
|
6
|
-
static readonly
|
|
7
|
-
static readonly
|
|
8
|
-
static readonly
|
|
9
|
-
readonly
|
|
6
|
+
static readonly VERSION_URL_V1: string;
|
|
7
|
+
static readonly VERSION_URL_V2: string;
|
|
8
|
+
static readonly SECRET_KEY_V1: string;
|
|
9
|
+
static readonly SECRET_KEY_V2: string;
|
|
10
|
+
static readonly API_KEY_V1: string;
|
|
11
|
+
static readonly API_KEY_V2: string;
|
|
10
12
|
private readonly jar;
|
|
11
13
|
private readonly instance;
|
|
14
|
+
get ctime(): string;
|
|
12
15
|
maxRate: RequiredClientOptions['maxRate'];
|
|
13
16
|
constructor(options?: ClientOptions);
|
|
14
17
|
video(videoID: string): Promise<Readable>;
|
|
@@ -16,5 +19,5 @@ declare class Client {
|
|
|
16
19
|
music(musicID: string): Promise<Readable>;
|
|
17
20
|
musicSyncLike(musicID: string): Readable;
|
|
18
21
|
}
|
|
19
|
-
declare const client:
|
|
20
|
-
export { client as default,
|
|
22
|
+
declare const client: ZingClient;
|
|
23
|
+
export { client as default, ZingClient };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -9,33 +9,40 @@ var cookies = require('./utils/cookies.cjs');
|
|
|
9
9
|
var encrypt = require('./utils/encrypt.cjs');
|
|
10
10
|
var lapse = require('./utils/lapse.cjs');
|
|
11
11
|
|
|
12
|
-
class
|
|
13
|
-
static BASE_URL = 'https://zingmp3.vn';
|
|
14
|
-
static
|
|
15
|
-
static
|
|
16
|
-
static
|
|
17
|
-
|
|
12
|
+
class ZingClient {
|
|
13
|
+
static BASE_URL = 'https://zingmp3.vn/';
|
|
14
|
+
static VERSION_URL_V1 = '1.6.34';
|
|
15
|
+
static VERSION_URL_V2 = '1.13.13';
|
|
16
|
+
static SECRET_KEY_V1 = '2aa2d1c561e809b267f3638c4a307aab';
|
|
17
|
+
static SECRET_KEY_V2 = '10a01dcf33762d3a204cb96429918ff6';
|
|
18
|
+
static API_KEY_V1 = '88265e23d4284f25963e6eedac8fbfa3';
|
|
19
|
+
static API_KEY_V2 = '38e8643fb0dc04e8d65b99994d3dafff';
|
|
18
20
|
jar;
|
|
19
21
|
instance;
|
|
22
|
+
get ctime() {
|
|
23
|
+
return Math.floor(Date.now() / 1000).toString();
|
|
24
|
+
}
|
|
20
25
|
maxRate;
|
|
21
26
|
constructor(options = {}) {
|
|
22
27
|
this.maxRate = [
|
|
23
28
|
options?.maxRate?.[0] ?? 100 * 1024,
|
|
24
29
|
options?.maxRate?.[1] ?? 16 * 1024
|
|
25
30
|
];
|
|
26
|
-
this.ctime = Math.floor(Date.now() / 1000).toString();
|
|
27
31
|
this.jar = new cookies.Cookies();
|
|
28
32
|
const axiosOptions = {
|
|
29
|
-
baseURL:
|
|
33
|
+
baseURL: ZingClient.BASE_URL,
|
|
30
34
|
params: {
|
|
31
|
-
version:
|
|
32
|
-
apiKey:
|
|
35
|
+
version: ZingClient.VERSION_URL_V1,
|
|
36
|
+
apiKey: ZingClient.API_KEY_V1,
|
|
33
37
|
ctime: this.ctime
|
|
34
38
|
},
|
|
35
39
|
maxRate: [
|
|
36
40
|
100 * 1024,
|
|
37
41
|
this.maxRate[0]
|
|
38
|
-
]
|
|
42
|
+
],
|
|
43
|
+
headers: {
|
|
44
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
|
|
45
|
+
}
|
|
39
46
|
};
|
|
40
47
|
this.instance = axios.create(axiosOptions);
|
|
41
48
|
this.instance.interceptors.request.use((options) => {
|
|
@@ -59,12 +66,12 @@ class Client {
|
|
|
59
66
|
throw new lapse.Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
|
|
60
67
|
const uri = '/api/v2/page/get/video';
|
|
61
68
|
try {
|
|
62
|
-
if (this.jar.getCookies(
|
|
69
|
+
if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
|
|
63
70
|
await this.instance.get('/');
|
|
64
71
|
const response = await this.instance.get(uri, {
|
|
65
72
|
params: {
|
|
66
73
|
id: videoID,
|
|
67
|
-
sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' +
|
|
74
|
+
sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
|
|
68
75
|
},
|
|
69
76
|
maxRate: [
|
|
70
77
|
100 * 1024,
|
|
@@ -116,14 +123,15 @@ class Client {
|
|
|
116
123
|
async music(musicID) {
|
|
117
124
|
if (typeof musicID !== 'string' || !musicID.trim().length)
|
|
118
125
|
throw new lapse.Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
|
|
126
|
+
let musicURL;
|
|
119
127
|
const uri = '/api/v2/song/get/streaming';
|
|
120
128
|
try {
|
|
121
|
-
if (this.jar.getCookies(
|
|
129
|
+
if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
|
|
122
130
|
await this.instance.get('/');
|
|
123
131
|
const response = await this.instance.get(uri, {
|
|
124
132
|
params: {
|
|
125
133
|
id: musicID,
|
|
126
|
-
sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' +
|
|
134
|
+
sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
|
|
127
135
|
},
|
|
128
136
|
maxRate: [
|
|
129
137
|
100 * 1024,
|
|
@@ -131,9 +139,36 @@ class Client {
|
|
|
131
139
|
]
|
|
132
140
|
});
|
|
133
141
|
const body = response.data;
|
|
134
|
-
if (body.err
|
|
142
|
+
if (body.err === -1150) {
|
|
143
|
+
let retrySuccess = false;
|
|
144
|
+
const uri_v2 = '/api/song/get-song-info';
|
|
145
|
+
for (let step = 0; step < 2; step++) {
|
|
146
|
+
const retry = await this.instance.get(uri_v2, {
|
|
147
|
+
params: {
|
|
148
|
+
id: musicID,
|
|
149
|
+
api_key: ZingClient.API_KEY_V2,
|
|
150
|
+
sig: encrypt.createSignature('/song/get-song-info', 'ctime=' + this.ctime + 'id=' + musicID, ZingClient.SECRET_KEY_V2),
|
|
151
|
+
version: void 0,
|
|
152
|
+
apiKey: void 0
|
|
153
|
+
},
|
|
154
|
+
maxRate: [
|
|
155
|
+
100 * 1024,
|
|
156
|
+
this.maxRate[0]
|
|
157
|
+
]
|
|
158
|
+
});
|
|
159
|
+
if (retry.data.err === 0) {
|
|
160
|
+
retrySuccess = true;
|
|
161
|
+
musicURL = retry.data.data?.streaming?.default?.[128];
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (!retrySuccess)
|
|
166
|
+
throw new lapse.Lapse('Music requested by VIP, PRI', 'ERROR_MUSIC_VIP_ONLY');
|
|
167
|
+
}
|
|
168
|
+
else if (body.err === 0)
|
|
169
|
+
musicURL = body.data?.[128];
|
|
170
|
+
else
|
|
135
171
|
throw new lapse.Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND');
|
|
136
|
-
const musicURL = body.data?.[128];
|
|
137
172
|
if (!musicURL || !musicURL.length)
|
|
138
173
|
throw new lapse.Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
|
|
139
174
|
const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });
|
|
@@ -179,9 +214,8 @@ const clientOptions = {
|
|
|
179
214
|
16 * 1024
|
|
180
215
|
]
|
|
181
216
|
};
|
|
182
|
-
const client = new
|
|
217
|
+
const client = new ZingClient(clientOptions);
|
|
183
218
|
|
|
184
|
-
exports.
|
|
185
|
-
exports.client = client;
|
|
219
|
+
exports.ZingClient = ZingClient;
|
|
186
220
|
exports.default = client;
|
|
187
221
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../esm/index.js"],"sourcesContent":["import axios from 'axios';\nimport m3u8stream from 'm3u8stream';\nimport { Readable, PassThrough } from 'node:stream';\nimport { Cookies } from './utils/cookies.js';\nimport { createSignature } from './utils/encrypt.js';\nimport { Lapse } from './utils/lapse.js';\nclass Client {\n static BASE_URL = 'https://zingmp3.vn';\n static VERSION_URL = '1.6.34';\n static SECRET_KEY = '2aa2d1c561e809b267f3638c4a307aab';\n static API_KEY = '88265e23d4284f25963e6eedac8fbfa3';\n ctime;\n jar;\n instance;\n maxRate;\n constructor(options = {}) {\n this.maxRate = [\n options?.maxRate?.[0] ?? 100 * 1024,\n options?.maxRate?.[1] ?? 16 * 1024\n ];\n this.ctime = Math.floor(Date.now() / 1000).toString();\n this.jar = new Cookies();\n const axiosOptions = {\n baseURL: Client.BASE_URL,\n params: {\n version: Client.VERSION_URL,\n apiKey: Client.API_KEY,\n ctime: this.ctime\n },\n maxRate: [\n 100 * 1024,\n this.maxRate[0]\n ]\n };\n this.instance = axios.create(axiosOptions);\n this.instance.interceptors.request.use((options) => {\n const base = options.baseURL ?? '';\n const url = new URL(options.url ?? '/', base).toString();\n const additionalHeaders = this.jar.applyToHeaders(url);\n for (const [key, value] of Object.entries(additionalHeaders))\n options.headers.set(key, value);\n return options;\n });\n this.instance.interceptors.response.use((response) => {\n const setCookie = response.headers['set-cookie'];\n const requestUrl = response.request?.res?.responseUrl ?? response.config.url;\n if (requestUrl && Array.isArray(setCookie))\n this.jar.setCookies(setCookie, requestUrl);\n return response;\n });\n }\n async video(videoID) {\n if (typeof videoID !== 'string' || !videoID.length)\n throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');\n const uri = '/api/v2/page/get/video';\n try {\n if (this.jar.getCookies(Client.BASE_URL).length === 0)\n await this.instance.get('/');\n const response = await this.instance.get(uri, {\n params: {\n id: videoID,\n sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + Client.VERSION_URL, Client.SECRET_KEY)\n },\n maxRate: [\n 100 * 1024,\n this.maxRate[0]\n ]\n });\n const body = response.data;\n if (body.err !== 0)\n throw new Lapse(body.msg, 'ERROR_VIDEO_NOT_FOUND');\n const videoURL = body.data?.streaming?.hls?.['360p'];\n if (!videoURL || !videoURL.length)\n throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');\n const streamVideo = m3u8stream(videoURL);\n streamVideo.once('error', (error) => {\n const lapse = new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);\n streamVideo.destroy(lapse);\n });\n return streamVideo;\n }\n catch (error) {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n }\n }\n videoSyncLike(videoID) {\n const video = new PassThrough({ highWaterMark: this.maxRate[1] });\n void this.video(videoID)\n .then((source) => {\n source.once('error', (error) => {\n const lapse = error instanceof Lapse ? error : new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);\n video.destroy(lapse);\n });\n const destroy = () => {\n if (!source.destroyed)\n source.destroy();\n };\n video.once('close', destroy);\n video.once('error', destroy);\n source.pipe(video);\n })\n .catch((error) => {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n });\n return video;\n }\n async music(musicID) {\n if (typeof musicID !== 'string' || !musicID.trim().length)\n throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');\n const uri = '/api/v2/song/get/streaming';\n try {\n if (this.jar.getCookies(Client.BASE_URL).length === 0)\n await this.instance.get('/');\n const response = await this.instance.get(uri, {\n params: {\n id: musicID,\n sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + Client.VERSION_URL, Client.SECRET_KEY)\n },\n maxRate: [\n 100 * 1024,\n this.maxRate[0]\n ]\n });\n const body = response.data;\n if (body.err !== 0)\n throw new Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND');\n const musicURL = body.data?.[128];\n if (!musicURL || !musicURL.length)\n throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');\n const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });\n streamMusic.data.once('error', (error) => {\n const lapse = new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', streamMusic.status, error);\n streamMusic.data.destroy(lapse);\n });\n return streamMusic.data;\n }\n catch (error) {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n }\n }\n musicSyncLike(musicID) {\n const music = new PassThrough({ highWaterMark: this.maxRate[1] });\n void this.music(musicID)\n .then((source) => {\n source.once('error', (error) => {\n const lapse = error instanceof Lapse ? error : new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);\n music.destroy(lapse);\n });\n const destroy = () => {\n if (!source.destroyed)\n source.destroy();\n };\n music.once('close', destroy);\n music.once('error', destroy);\n source.pipe(music);\n })\n .catch((error) => {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n });\n return music;\n }\n}\nconst clientOptions = {\n maxRate: [\n 100 * 1024,\n 16 * 1024\n ]\n};\nconst client = new Client(clientOptions);\nexport { client as default, client, Client };\n//# sourceMappingURL=index.js.map"],"names":["Cookies","Lapse","createSignature","lapse","PassThrough"],"mappings":";;;;;;;;;;;AAMA,MAAM,MAAM,CAAC;AACb,IAAI,OAAO,QAAQ,GAAG,oBAAoB;AAC1C,IAAI,OAAO,WAAW,GAAG,QAAQ;AACjC,IAAI,OAAO,UAAU,GAAG,kCAAkC;AAC1D,IAAI,OAAO,OAAO,GAAG,kCAAkC;AACvD,IAAI,KAAK;AACT,IAAI,GAAG;AACP,IAAI,QAAQ;AACZ,IAAI,OAAO;AACX,IAAI,WAAW,CAAC,OAAO,GAAG,EAAE,EAAE;AAC9B,QAAQ,IAAI,CAAC,OAAO,GAAG;AACvB,YAAY,OAAO,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,GAAG,GAAG,IAAI;AAC/C,YAAY,OAAO,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG;AAC1C,SAAS;AACT,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE;AAC7D,QAAQ,IAAI,CAAC,GAAG,GAAG,IAAIA,eAAO,EAAE;AAChC,QAAQ,MAAM,YAAY,GAAG;AAC7B,YAAY,OAAO,EAAE,MAAM,CAAC,QAAQ;AACpC,YAAY,MAAM,EAAE;AACpB,gBAAgB,OAAO,EAAE,MAAM,CAAC,WAAW;AAC3C,gBAAgB,MAAM,EAAE,MAAM,CAAC,OAAO;AACtC,gBAAgB,KAAK,EAAE,IAAI,CAAC;AAC5B,aAAa;AACb,YAAY,OAAO,EAAE;AACrB,gBAAgB,G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,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,EAAE,KAAK,CAAC;AACpJ,QAAQ,CAAC,CAAC;AACV,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;AACA,MAAM,aAAa,GAAG;AACtB,IAAI,OAAO,EAAE;AACb,QAAQ,GAAG,GAAG,IAAI;AAClB,QAAQ,EAAE,GAAG;AACb;AACA,CAAC;AACI,MAAC,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../esm/index.js"],"sourcesContent":["import axios from 'axios';\nimport m3u8stream from 'm3u8stream';\nimport { Readable, PassThrough } from 'node:stream';\nimport { Cookies } from './utils/cookies.js';\nimport { createSignature } from './utils/encrypt.js';\nimport { Lapse } from './utils/lapse.js';\nclass ZingClient {\n static BASE_URL = 'https://zingmp3.vn/';\n static VERSION_URL_V1 = '1.6.34';\n static VERSION_URL_V2 = '1.13.13';\n static SECRET_KEY_V1 = '2aa2d1c561e809b267f3638c4a307aab';\n static SECRET_KEY_V2 = '10a01dcf33762d3a204cb96429918ff6';\n static API_KEY_V1 = '88265e23d4284f25963e6eedac8fbfa3';\n static API_KEY_V2 = '38e8643fb0dc04e8d65b99994d3dafff';\n jar;\n instance;\n get ctime() {\n return Math.floor(Date.now() / 1000).toString();\n }\n maxRate;\n constructor(options = {}) {\n this.maxRate = [\n options?.maxRate?.[0] ?? 100 * 1024,\n options?.maxRate?.[1] ?? 16 * 1024\n ];\n this.jar = new Cookies();\n const axiosOptions = {\n baseURL: ZingClient.BASE_URL,\n params: {\n version: ZingClient.VERSION_URL_V1,\n apiKey: ZingClient.API_KEY_V1,\n ctime: this.ctime\n },\n maxRate: [\n 100 * 1024,\n this.maxRate[0]\n ],\n headers: {\n 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'\n }\n };\n this.instance = axios.create(axiosOptions);\n this.instance.interceptors.request.use((options) => {\n const base = options.baseURL ?? '';\n const url = new URL(options.url ?? '/', base).toString();\n const additionalHeaders = this.jar.applyToHeaders(url);\n for (const [key, value] of Object.entries(additionalHeaders))\n options.headers.set(key, value);\n return options;\n });\n this.instance.interceptors.response.use((response) => {\n const setCookie = response.headers['set-cookie'];\n const requestUrl = response.request?.res?.responseUrl ?? response.config.url;\n if (requestUrl && Array.isArray(setCookie))\n this.jar.setCookies(setCookie, requestUrl);\n return response;\n });\n }\n async video(videoID) {\n if (typeof videoID !== 'string' || !videoID.length)\n throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');\n const uri = '/api/v2/page/get/video';\n try {\n if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)\n await this.instance.get('/');\n const response = await this.instance.get(uri, {\n params: {\n id: videoID,\n sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)\n },\n maxRate: [\n 100 * 1024,\n this.maxRate[0]\n ]\n });\n const body = response.data;\n if (body.err !== 0)\n throw new Lapse(body.msg, 'ERROR_VIDEO_NOT_FOUND');\n const videoURL = body.data?.streaming?.hls?.['360p'];\n if (!videoURL || !videoURL.length)\n throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');\n const streamVideo = m3u8stream(videoURL);\n streamVideo.once('error', (error) => {\n const lapse = new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);\n streamVideo.destroy(lapse);\n });\n return streamVideo;\n }\n catch (error) {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n }\n }\n videoSyncLike(videoID) {\n const video = new PassThrough({ highWaterMark: this.maxRate[1] });\n void this.video(videoID)\n .then((source) => {\n source.once('error', (error) => {\n const lapse = error instanceof Lapse ? error : new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);\n video.destroy(lapse);\n });\n const destroy = () => {\n if (!source.destroyed)\n source.destroy();\n };\n video.once('close', destroy);\n video.once('error', destroy);\n source.pipe(video);\n })\n .catch((error) => {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n });\n return video;\n }\n async music(musicID) {\n if (typeof musicID !== 'string' || !musicID.trim().length)\n throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');\n let musicURL;\n const uri = '/api/v2/song/get/streaming';\n try {\n if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)\n await this.instance.get('/');\n const response = await this.instance.get(uri, {\n params: {\n id: musicID,\n sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)\n },\n maxRate: [\n 100 * 1024,\n this.maxRate[0]\n ]\n });\n const body = response.data;\n if (body.err === -1150) {\n let retrySuccess = false;\n const uri_v2 = '/api/song/get-song-info';\n for (let step = 0; step < 2; step++) {\n const retry = await this.instance.get(uri_v2, {\n params: {\n id: musicID,\n api_key: ZingClient.API_KEY_V2,\n sig: createSignature('/song/get-song-info', 'ctime=' + this.ctime + 'id=' + musicID, ZingClient.SECRET_KEY_V2),\n version: void 0,\n apiKey: void 0\n },\n maxRate: [\n 100 * 1024,\n this.maxRate[0]\n ]\n });\n if (retry.data.err === 0) {\n retrySuccess = true;\n musicURL = retry.data.data?.streaming?.default?.[128];\n break;\n }\n }\n if (!retrySuccess)\n throw new Lapse('Music requested by VIP, PRI', 'ERROR_MUSIC_VIP_ONLY');\n }\n else if (body.err === 0)\n musicURL = body.data?.[128];\n else\n throw new Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND');\n if (!musicURL || !musicURL.length)\n throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');\n const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });\n streamMusic.data.once('error', (error) => {\n const lapse = new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', streamMusic.status, error);\n streamMusic.data.destroy(lapse);\n });\n return streamMusic.data;\n }\n catch (error) {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n }\n }\n musicSyncLike(musicID) {\n const music = new PassThrough({ highWaterMark: this.maxRate[1] });\n void this.music(musicID)\n .then((source) => {\n source.once('error', (error) => {\n const lapse = error instanceof Lapse ? error : new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);\n music.destroy(lapse);\n });\n const destroy = () => {\n if (!source.destroyed)\n source.destroy();\n };\n music.once('close', destroy);\n music.once('error', destroy);\n source.pipe(music);\n })\n .catch((error) => {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n });\n return music;\n }\n}\nconst clientOptions = {\n maxRate: [\n 100 * 1024,\n 16 * 1024\n ]\n};\nconst client = new ZingClient(clientOptions);\nexport { client as default, ZingClient };\n//# sourceMappingURL=index.js.map"],"names":["Cookies","Lapse","createSignature","lapse","PassThrough"],"mappings":";;;;;;;;;;;AAMA,MAAM,UAAU,CAAC;AACjB,IAAI,OAAO,QAAQ,GAAG,qBAAqB;AAC3C,IAAI,OAAO,cAAc,GAAG,QAAQ;AACpC,IAAI,OAAO,cAAc,GAAG,SAAS;AACrC,IAAI,OAAO,aAAa,GAAG,kCAAkC;AAC7D,IAAI,OAAO,aAAa,GAAG,kCAAkC;AAC7D,IAAI,OAAO,UAAU,GAAG,kCAAkC;AAC1D,IAAI,OAAO,UAAU,GAAG,kCAAkC;AAC1D,IAAI,GAAG;AACP,IAAI,QAAQ;AACZ,IAAI,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AK;AAC5C,gBAAgB,MAAMD,OAAK,GAAG,KAAK,YAAYF,WAAK,GAAG,KAAK,GAAG,IAAIA,WAAK,CAAC,wBAAwB,EAAE,uBAAuB,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC;AAC1I,gBAAgB,KAAK,CAAC,OAAO,CAACE,OAAK,CAAC;AACpC,YAAY,CAAC,CAAC;AACd,YAAY,MAAM,OAAO,GAAG,MAAM;AAClC,gBAAgB,IAAI,CAAC,MAAM,CAAC,SAAS;AACrC,oBAAoB,MAAM,CAAC,OAAO,EAAE;AACpC,YAAY,CAAC;AACb,YAAY,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;AACxC,YAAY,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;AACxC,YAAY,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;AAC9B,QAAQ,CAAC;AACT,aAAa,KAAK,CAAC,CAAC,KAAK,KAAK;AAC9B,YAAY,IAAI,KAAK,YAAYF,WAAK;AACtC,gBAAgB,MAAM,KAAK;AAC3B,YAAY,MAAM,IAAIA,WAAK,CAAC,8BAA8B,EAAE,mBAAmB,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,EAAE,KAAK,CAAC;AACpJ,QAAQ,CAAC,CAAC;AACV,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;AACA,MAAM,aAAa,GAAG;AACtB,IAAI,OAAO,EAAE;AACb,QAAQ,GAAG,GAAG,IAAI;AAClB,QAAQ,EAAE,GAAG;AACb;AACA,CAAC;AACI,MAAC,MAAM,GAAG,IAAI,UAAU,CAAC,aAAa;;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -4,33 +4,40 @@ import { Readable, PassThrough } from 'node:stream';
|
|
|
4
4
|
import { Cookies } from './utils/cookies.js';
|
|
5
5
|
import { createSignature } from './utils/encrypt.js';
|
|
6
6
|
import { Lapse } from './utils/lapse.js';
|
|
7
|
-
class
|
|
8
|
-
static BASE_URL = 'https://zingmp3.vn';
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
|
|
7
|
+
class ZingClient {
|
|
8
|
+
static BASE_URL = 'https://zingmp3.vn/';
|
|
9
|
+
static VERSION_URL_V1 = '1.6.34';
|
|
10
|
+
static VERSION_URL_V2 = '1.13.13';
|
|
11
|
+
static SECRET_KEY_V1 = '2aa2d1c561e809b267f3638c4a307aab';
|
|
12
|
+
static SECRET_KEY_V2 = '10a01dcf33762d3a204cb96429918ff6';
|
|
13
|
+
static API_KEY_V1 = '88265e23d4284f25963e6eedac8fbfa3';
|
|
14
|
+
static API_KEY_V2 = '38e8643fb0dc04e8d65b99994d3dafff';
|
|
13
15
|
jar;
|
|
14
16
|
instance;
|
|
17
|
+
get ctime() {
|
|
18
|
+
return Math.floor(Date.now() / 1000).toString();
|
|
19
|
+
}
|
|
15
20
|
maxRate;
|
|
16
21
|
constructor(options = {}) {
|
|
17
22
|
this.maxRate = [
|
|
18
23
|
options?.maxRate?.[0] ?? 100 * 1024,
|
|
19
24
|
options?.maxRate?.[1] ?? 16 * 1024
|
|
20
25
|
];
|
|
21
|
-
this.ctime = Math.floor(Date.now() / 1000).toString();
|
|
22
26
|
this.jar = new Cookies();
|
|
23
27
|
const axiosOptions = {
|
|
24
|
-
baseURL:
|
|
28
|
+
baseURL: ZingClient.BASE_URL,
|
|
25
29
|
params: {
|
|
26
|
-
version:
|
|
27
|
-
apiKey:
|
|
30
|
+
version: ZingClient.VERSION_URL_V1,
|
|
31
|
+
apiKey: ZingClient.API_KEY_V1,
|
|
28
32
|
ctime: this.ctime
|
|
29
33
|
},
|
|
30
34
|
maxRate: [
|
|
31
35
|
100 * 1024,
|
|
32
36
|
this.maxRate[0]
|
|
33
|
-
]
|
|
37
|
+
],
|
|
38
|
+
headers: {
|
|
39
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
|
|
40
|
+
}
|
|
34
41
|
};
|
|
35
42
|
this.instance = axios.create(axiosOptions);
|
|
36
43
|
this.instance.interceptors.request.use((options) => {
|
|
@@ -54,12 +61,12 @@ class Client {
|
|
|
54
61
|
throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
|
|
55
62
|
const uri = '/api/v2/page/get/video';
|
|
56
63
|
try {
|
|
57
|
-
if (this.jar.getCookies(
|
|
64
|
+
if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
|
|
58
65
|
await this.instance.get('/');
|
|
59
66
|
const response = await this.instance.get(uri, {
|
|
60
67
|
params: {
|
|
61
68
|
id: videoID,
|
|
62
|
-
sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' +
|
|
69
|
+
sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
|
|
63
70
|
},
|
|
64
71
|
maxRate: [
|
|
65
72
|
100 * 1024,
|
|
@@ -111,14 +118,15 @@ class Client {
|
|
|
111
118
|
async music(musicID) {
|
|
112
119
|
if (typeof musicID !== 'string' || !musicID.trim().length)
|
|
113
120
|
throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
|
|
121
|
+
let musicURL;
|
|
114
122
|
const uri = '/api/v2/song/get/streaming';
|
|
115
123
|
try {
|
|
116
|
-
if (this.jar.getCookies(
|
|
124
|
+
if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
|
|
117
125
|
await this.instance.get('/');
|
|
118
126
|
const response = await this.instance.get(uri, {
|
|
119
127
|
params: {
|
|
120
128
|
id: musicID,
|
|
121
|
-
sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' +
|
|
129
|
+
sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
|
|
122
130
|
},
|
|
123
131
|
maxRate: [
|
|
124
132
|
100 * 1024,
|
|
@@ -126,9 +134,36 @@ class Client {
|
|
|
126
134
|
]
|
|
127
135
|
});
|
|
128
136
|
const body = response.data;
|
|
129
|
-
if (body.err
|
|
137
|
+
if (body.err === -1150) {
|
|
138
|
+
let retrySuccess = false;
|
|
139
|
+
const uri_v2 = '/api/song/get-song-info';
|
|
140
|
+
for (let step = 0; step < 2; step++) {
|
|
141
|
+
const retry = await this.instance.get(uri_v2, {
|
|
142
|
+
params: {
|
|
143
|
+
id: musicID,
|
|
144
|
+
api_key: ZingClient.API_KEY_V2,
|
|
145
|
+
sig: createSignature('/song/get-song-info', 'ctime=' + this.ctime + 'id=' + musicID, ZingClient.SECRET_KEY_V2),
|
|
146
|
+
version: void 0,
|
|
147
|
+
apiKey: void 0
|
|
148
|
+
},
|
|
149
|
+
maxRate: [
|
|
150
|
+
100 * 1024,
|
|
151
|
+
this.maxRate[0]
|
|
152
|
+
]
|
|
153
|
+
});
|
|
154
|
+
if (retry.data.err === 0) {
|
|
155
|
+
retrySuccess = true;
|
|
156
|
+
musicURL = retry.data.data?.streaming?.default?.[128];
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!retrySuccess)
|
|
161
|
+
throw new Lapse('Music requested by VIP, PRI', 'ERROR_MUSIC_VIP_ONLY');
|
|
162
|
+
}
|
|
163
|
+
else if (body.err === 0)
|
|
164
|
+
musicURL = body.data?.[128];
|
|
165
|
+
else
|
|
130
166
|
throw new Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND');
|
|
131
|
-
const musicURL = body.data?.[128];
|
|
132
167
|
if (!musicURL || !musicURL.length)
|
|
133
168
|
throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
|
|
134
169
|
const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });
|
|
@@ -174,6 +209,6 @@ const clientOptions = {
|
|
|
174
209
|
16 * 1024
|
|
175
210
|
]
|
|
176
211
|
};
|
|
177
|
-
const client = new
|
|
178
|
-
export { client as default,
|
|
212
|
+
const client = new ZingClient(clientOptions);
|
|
213
|
+
export { client as default, ZingClient };
|
|
179
214
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"source/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAYzC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"source/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAYzC,MAAM,UAAU;IACL,MAAM,CAAU,QAAQ,GAAW,qBAAqB,CAAC;IAEzD,MAAM,CAAU,cAAc,GAAW,QAAQ,CAAC;IAClD,MAAM,CAAU,cAAc,GAAW,SAAS,CAAC;IAEnD,MAAM,CAAU,aAAa,GAAW,kCAAkC,CAAC;IAC3E,MAAM,CAAU,aAAa,GAAW,kCAAkC,CAAC;IAE3E,MAAM,CAAU,UAAU,GAA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;gBACvB,IAAI,CAAC,MAAM,CAAC,SAAS;oBACjB,MAAM,CAAC,OAAO,EAAE,CAAC;YACzB,CAAC,CAAA;YAED,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7B,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAE7B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CACJ;aACA,KAAK,CACF,CAAC,KAAc,EAAQ,EAAE;YACrB,IAAI,KAAK,YAAY,KAAK;gBACtB,MAAM,KAAK,CAAC;YAEhB,MAAM,IAAI,KAAK,CAAC,8BAA8B,EAAE,mBAAmB,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QAC7I,CAAC,CACJ,CAAC;QAEN,OAAO,KAAK,CAAC;IACjB,CAAC;;AAGL,MAAM,aAAa,GAAkB;IACjC,OAAO,EAAE;QACL,GAAG,GAAG,IAAI;QACV,EAAE,GAAG,IAAI;KACZ;CACJ,CAAA;AACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,aAAa,CAAC,CAAC;AAE7C,OAAO,EACH,MAAM,IAAI,OAAO,EACjB,UAAU,EACb,CAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
static readonly BASE_URL: string;
|
|
5
|
-
static readonly VERSION_URL: string;
|
|
6
|
-
static readonly SECRET_KEY: string;
|
|
7
|
-
static readonly API_KEY: string;
|
|
8
|
-
readonly ctime: string;
|
|
9
|
-
private readonly jar;
|
|
10
|
-
private readonly instance;
|
|
11
|
-
maxRate: RequiredClientOptions['maxRate'];
|
|
12
|
-
constructor(options?: ClientOptions);
|
|
13
|
-
video(videoID: string): Promise<Readable>;
|
|
14
|
-
videoSyncLike(videoID: string): Readable;
|
|
15
|
-
music(musicID: string): Promise<Readable>;
|
|
16
|
-
musicSyncLike(musicID: string): Readable;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare const client: Client;
|
|
20
|
-
export { client }
|
|
3
|
+
declare const client: ZingClient;
|
|
21
4
|
export default client;
|
|
22
5
|
|
|
23
6
|
export declare interface ClientOptions {
|
|
@@ -30,4 +13,23 @@ declare interface RequiredClientOptions {
|
|
|
30
13
|
|
|
31
14
|
export declare type SearchCategory = 'artist' | 'music' | 'playlist' | 'video';
|
|
32
15
|
|
|
16
|
+
export declare class ZingClient {
|
|
17
|
+
static readonly BASE_URL: string;
|
|
18
|
+
static readonly VERSION_URL_V1: string;
|
|
19
|
+
static readonly VERSION_URL_V2: string;
|
|
20
|
+
static readonly SECRET_KEY_V1: string;
|
|
21
|
+
static readonly SECRET_KEY_V2: string;
|
|
22
|
+
static readonly API_KEY_V1: string;
|
|
23
|
+
static readonly API_KEY_V2: string;
|
|
24
|
+
private readonly jar;
|
|
25
|
+
private readonly instance;
|
|
26
|
+
get ctime(): string;
|
|
27
|
+
maxRate: RequiredClientOptions['maxRate'];
|
|
28
|
+
constructor(options?: ClientOptions);
|
|
29
|
+
video(videoID: string): Promise<Readable>;
|
|
30
|
+
videoSyncLike(videoID: string): Readable;
|
|
31
|
+
music(musicID: string): Promise<Readable>;
|
|
32
|
+
musicSyncLike(musicID: string): Readable;
|
|
33
|
+
}
|
|
34
|
+
|
|
33
35
|
export { }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khang07/zing-mp3-api",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"author": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"author": "GiaKhang <ngkhang9a5lqc11@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/GiaKhang1810/zing-mp3-api.git"
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
"m3u8stream": "^0.8.6"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
|
-
"dist"
|
|
50
|
+
"dist",
|
|
51
|
+
"README.md",
|
|
52
|
+
"LICENSE"
|
|
51
53
|
]
|
|
52
54
|
}
|