@khang07/zing-mp3-api 1.0.0 → 1.1.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 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,476 @@
1
+ # @khang07/zing-mp3-api
2
+
3
+ A lightweight Node.js library for working with Zing MP3 streams.
4
+
5
+ This package focuses on a small, practical API:
6
+ - fetch a music stream by song ID
7
+ - fetch a video stream by video ID
8
+ - search songs by keyword
9
+ - expose a reusable cookie jar utility
10
+ - expose the signature generator used by the API
11
+ - wrap library failures with a dedicated `Lapse` error class
12
+
13
+ The package ships with:
14
+ - ESM build
15
+ - CommonJS build
16
+ - TypeScript declarations
17
+
18
+ ## Features
19
+
20
+ - Stream music as a Node.js `Readable`
21
+ - Stream video as a Node.js `Readable`
22
+ - Sync-like helpers that return a stream immediately and pipe later
23
+ - Built-in cookie handling for Zing requests
24
+ - Typed response for `search()`
25
+ - Small public surface area
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install @khang07/zing-mp3-api
31
+ ```
32
+
33
+ ## Requirements
34
+
35
+ - Node.js
36
+ - A runtime that supports Node streams
37
+
38
+ ## Package exports
39
+
40
+ Main package:
41
+
42
+ ```ts
43
+ import client, { ZingClient } from "@khang07/zing-mp3-api";
44
+ ```
45
+
46
+ Subpath exports:
47
+
48
+ ```ts
49
+ import { Cookies } from "@khang07/zing-mp3-api/utils/cookies";
50
+ import { createSignature } from "@khang07/zing-mp3-api/utils/encrypt";
51
+ import { Lapse } from "@khang07/zing-mp3-api/utils/lapse";
52
+ ```
53
+
54
+ ## Quick start
55
+
56
+ ### Use the default client
57
+
58
+ ```ts
59
+ import fs from "node:fs";
60
+ import client from "@khang07/zing-mp3-api";
61
+
62
+ const stream = await client.music("Z7ACBFEF");
63
+ stream.pipe(fs.createWriteStream("music.mp3"));
64
+ ```
65
+
66
+ ### Create your own client
67
+
68
+ ```ts
69
+ import { ZingClient } from "@khang07/zing-mp3-api";
70
+
71
+ const client = new ZingClient({
72
+ maxRate: [100 * 1024, 16 * 1024]
73
+ });
74
+ ```
75
+
76
+ ## API
77
+
78
+ ### `new ZingClient(options?)`
79
+
80
+ Create a new client instance.
81
+
82
+ #### Parameters
83
+
84
+ ```ts
85
+ interface ClientOptions {
86
+ maxRate?: [download?: number, highWaterMark?: number];
87
+ }
88
+ ```
89
+
90
+ #### Notes
91
+
92
+ - `maxRate[0]`: download rate limit passed to Axios
93
+ - `maxRate[1]`: `highWaterMark` used by `musicSyncLike()` and `videoSyncLike()`
94
+
95
+ ### `client.music(musicID)`
96
+
97
+ Fetches a music stream by song ID.
98
+
99
+ #### Signature
100
+
101
+ ```ts
102
+ music(musicID: string): Promise<Readable>
103
+ ```
104
+
105
+ #### Returns
106
+
107
+ A `Promise<Readable>` for the audio stream.
108
+
109
+ #### Example
110
+
111
+ ```ts
112
+ import fs from "node:fs";
113
+ import client from "@khang07/zing-mp3-api";
114
+
115
+ const music = await client.music("Z7ACBFEF");
116
+ music.pipe(fs.createWriteStream("track.mp3"));
117
+ ```
118
+
119
+ #### Behavior
120
+
121
+ - validates the input ID
122
+ - initializes cookies if needed
123
+ - requests the Zing streaming endpoint
124
+ - retries a secondary endpoint for some VIP/PRI-style responses
125
+ - throws a `Lapse` when the song cannot be streamed
126
+
127
+ ### `client.musicSyncLike(musicID)`
128
+
129
+ Returns a stream immediately and starts resolving the remote source in the background.
130
+
131
+ #### Signature
132
+
133
+ ```ts
134
+ musicSyncLike(musicID: string): Readable
135
+ ```
136
+
137
+ #### Example
138
+
139
+ ```ts
140
+ import fs from "node:fs";
141
+ import client from "@khang07/zing-mp3-api";
142
+
143
+ const music = client.musicSyncLike("Z7ACBFEF");
144
+ music.pipe(fs.createWriteStream("track.mp3"));
145
+ ```
146
+
147
+ #### When to use
148
+
149
+ Use this when you want a stream object right away instead of awaiting `Promise<Readable>`.
150
+
151
+ ### `client.video(videoID)`
152
+
153
+ Fetches a video stream by video ID.
154
+
155
+ #### Signature
156
+
157
+ ```ts
158
+ video(videoID: string): Promise<Readable>
159
+ ```
160
+
161
+ #### Returns
162
+
163
+ A `Promise<Readable>` for the video stream.
164
+
165
+ #### Example
166
+
167
+ ```ts
168
+ import fs from "node:fs";
169
+ import client from "@khang07/zing-mp3-api";
170
+
171
+ const video = await client.video("ZO8I9ZZC");
172
+ video.pipe(fs.createWriteStream("video.ts"));
173
+ ```
174
+
175
+ #### Behavior
176
+
177
+ - validates the input ID
178
+ - initializes cookies if needed
179
+ - requests the video endpoint
180
+ - reads the HLS `360p` stream URL from the response
181
+ - uses `m3u8stream` to produce the returned stream
182
+
183
+ #### Important
184
+
185
+ The current implementation streams HLS media from the `360p` source. It does **not** remux or convert the output into MP4 by itself.
186
+
187
+ ### `client.videoSyncLike(videoID)`
188
+
189
+ Returns a stream immediately and starts resolving the remote video source in the background.
190
+
191
+ #### Signature
192
+
193
+ ```ts
194
+ videoSyncLike(videoID: string): Readable
195
+ ```
196
+
197
+ #### Example
198
+
199
+ ```ts
200
+ import fs from "node:fs";
201
+ import client from "@khang07/zing-mp3-api";
202
+
203
+ const video = client.videoSyncLike("ZO8I9ZZC");
204
+ video.pipe(fs.createWriteStream("video.ts"));
205
+ ```
206
+
207
+ ### `client.search(keyword)`
208
+
209
+ Searches songs by keyword.
210
+
211
+ #### Signature
212
+
213
+ ```ts
214
+ search(keyword: string): Promise<ResponseSearch[]>
215
+ ```
216
+
217
+ #### Return type
218
+
219
+ ```ts
220
+ interface ResponseSearch {
221
+ id: string;
222
+ name: string;
223
+ alias: string;
224
+ isOffical: boolean;
225
+ username: string;
226
+ artists: {
227
+ id: string;
228
+ name: string;
229
+ alias: string;
230
+ thumbnail: {
231
+ w240: string;
232
+ w360: string;
233
+ };
234
+ }[];
235
+ thumbnail: {
236
+ w94: string;
237
+ w240: string;
238
+ };
239
+ duration: number;
240
+ releaseDate: number;
241
+ }
242
+ ```
243
+
244
+ #### Example
245
+
246
+ ```ts
247
+ import client from "@khang07/zing-mp3-api";
248
+
249
+ const results = await client.search("mở mắt");
250
+
251
+ for (const song of results) {
252
+ console.log(song.id, song.name, song.artists.map((artist) => artist.name).join(", "));
253
+ }
254
+ ```
255
+
256
+ #### Important
257
+
258
+ The current implementation only maps the `songs` section from the search response. It does not currently return artists, playlists, or videos.
259
+
260
+ ## Utility exports
261
+
262
+ ### `Cookies`
263
+
264
+ A lightweight in-memory cookie jar.
265
+
266
+ #### Available methods
267
+
268
+ ```ts
269
+ class Cookies {
270
+ setCookie(setCookie: string, requestUrl: string): void;
271
+ setCookies(setCookies: string[] | undefined, requestUrl: string): void;
272
+ getCookies(requestUrl: string): CookieRecord[];
273
+ getCookieHeader(requestUrl: string): string;
274
+ applyToHeaders(requestUrl: string, headers?: Record<string, string>): Record<string, string>;
275
+ deleteCookie(domain: string, path: string, name: string): void;
276
+ cleanup(): void;
277
+ toJSON(): CookieRecord[];
278
+ fromJSON(cookies: CookieRecord[]): void;
279
+ }
280
+ ```
281
+
282
+ #### Example
283
+
284
+ ```ts
285
+ import { Cookies } from "@khang07/zing-mp3-api/utils/cookies";
286
+
287
+ const jar = new Cookies();
288
+ jar.setCookie("sessionid=abc123; Path=/; HttpOnly", "https://zingmp3.vn/");
289
+
290
+ const headers = jar.applyToHeaders("https://zingmp3.vn/api/v2/song/get/streaming");
291
+ console.log(headers.Cookie);
292
+ ```
293
+
294
+ ### `createSignature(uri, params, secret)`
295
+
296
+ Creates the request signature used by the Zing endpoints.
297
+
298
+ #### Signature
299
+
300
+ ```ts
301
+ createSignature(uri: string, params: string, secret: string): string
302
+ ```
303
+
304
+ #### Example
305
+
306
+ ```ts
307
+ import { createSignature } from "@khang07/zing-mp3-api/utils/encrypt";
308
+
309
+ const sig = createSignature(
310
+ "/api/v2/song/get/streaming",
311
+ "ctime=1234567890id=Z7ACBFEFversion=1.6.34",
312
+ "2aa2d1c561e809b267f3638c4a307aab"
313
+ );
314
+
315
+ console.log(sig);
316
+ ```
317
+
318
+ ### `Lapse`
319
+
320
+ A custom error class used by the library.
321
+
322
+ #### Signature
323
+
324
+ ```ts
325
+ class Lapse extends Error {
326
+ code: string;
327
+ status?: number;
328
+ cause?: unknown;
329
+ }
330
+ ```
331
+
332
+ #### Example
333
+
334
+ ```ts
335
+ import client from "@khang07/zing-mp3-api";
336
+ import { Lapse } from "@khang07/zing-mp3-api/utils/lapse";
337
+
338
+ try {
339
+ await client.music("");
340
+ } catch (error) {
341
+ if (error instanceof Lapse) {
342
+ console.error(error.name);
343
+ console.error(error.code);
344
+ console.error(error.message);
345
+ console.error(error.status);
346
+ }
347
+ }
348
+ ```
349
+
350
+ ## Error codes
351
+
352
+ The current codebase throws these `Lapse.code` values:
353
+
354
+ | Code | Meaning |
355
+ |---|---|
356
+ | `ERROR_INVALID_ID` | `music()` or `video()` received an empty or invalid ID |
357
+ | `ERROR_INVALID_KEYWORD` | `search()` received an empty keyword |
358
+ | `ERROR_MUSIC_NOT_FOUND` | Music was not found from the primary endpoint |
359
+ | `ERROR_MUSIC_VIP_ONLY` | Music required access not available through the fallback flow |
360
+ | `ERROR_VIDEO_NOT_FOUND` | Video was not found |
361
+ | `ERROR_STREAM_URL_NOT_FOUND` | The API response did not contain a playable stream URL |
362
+ | `ERROR_STREAM_DOWNLOAD` | The download stream failed while reading data |
363
+ | `ERROR_MUSIC_FETCH` | A non-library failure occurred while fetching music |
364
+ | `ERROR_VIDEO_FETCH` | A non-library failure occurred while fetching video |
365
+ | `ERROR_SEARCH_FAILED` | Search endpoint returned an error response |
366
+ | `ERROR_SEARCH` | A non-library failure occurred while performing search |
367
+
368
+ ## Demo
369
+
370
+ ### Download a song to file
371
+
372
+ ```ts
373
+ import fs from "node:fs";
374
+ import client from "@khang07/zing-mp3-api";
375
+ import { Lapse } from "@khang07/zing-mp3-api/utils/lapse";
376
+
377
+ async function main(): Promise<void> {
378
+ try {
379
+ const stream = await client.music("Z7ACBFEF");
380
+ stream.pipe(fs.createWriteStream("song.mp3"));
381
+ } catch (error) {
382
+ if (error instanceof Lapse)
383
+ console.error(error.code, error.message);
384
+ else
385
+ console.error(error);
386
+ }
387
+ }
388
+
389
+ void main();
390
+ ```
391
+
392
+ ### Download a video stream to file
393
+
394
+ ```ts
395
+ import fs from "node:fs";
396
+ import client from "@khang07/zing-mp3-api";
397
+
398
+ async function main(): Promise<void> {
399
+ const stream = await client.video("ZO8I9ZZC");
400
+ stream.pipe(fs.createWriteStream("video.ts"));
401
+ }
402
+
403
+ void main();
404
+ ```
405
+
406
+ ### Search then download the first result
407
+
408
+ ```ts
409
+ import fs from "node:fs";
410
+ import client from "@khang07/zing-mp3-api";
411
+ import { Lapse } from "@khang07/zing-mp3-api/utils/lapse";
412
+
413
+ async function main(): Promise<void> {
414
+ try {
415
+ const results = await client.search("mở mắt");
416
+ const first = results[0];
417
+
418
+ if (!first)
419
+ throw new Error("No result found");
420
+
421
+ const stream = await client.music(first.id);
422
+ stream.pipe(fs.createWriteStream(first.alias + ".mp3"));
423
+ } catch (error) {
424
+ if (error instanceof Lapse)
425
+ console.error(error.code, error.message);
426
+ else
427
+ console.error(error);
428
+ }
429
+ }
430
+
431
+ void main();
432
+ ```
433
+
434
+ ## CommonJS example
435
+
436
+ ```js
437
+ const fs = require("node:fs");
438
+ const zing = require("@khang07/zing-mp3-api");
439
+
440
+ async function main() {
441
+ const client = zing.default;
442
+ const stream = await client.music("Z7ACBFEF");
443
+ stream.pipe(fs.createWriteStream("track.mp3"));
444
+ }
445
+
446
+ main();
447
+ ```
448
+
449
+ ## Build
450
+
451
+ ```bash
452
+ npm run build
453
+ ```
454
+
455
+ Current scripts in the project:
456
+
457
+ ```json
458
+ {
459
+ "build:esm": "tsc -p tsconfig.json",
460
+ "build:cjs": "rollup -c",
461
+ "build": "rm -rf dist && bun run build:esm && bun run build:cjs && rm -fr dist/esm/types dist/cjs/types",
462
+ "test": "mocha"
463
+ }
464
+ ```
465
+
466
+ ## Notes
467
+
468
+ - The default export is a preconfigured client instance.
469
+ - The named export is `ZingClient`.
470
+ - Search currently returns songs only.
471
+ - Video currently streams HLS `360p`.
472
+ - Errors are wrapped in `Lapse` for consistent handling.
473
+
474
+ ## License
475
+
476
+ MIT
@@ -9,12 +9,15 @@ 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 Client {
13
- static BASE_URL = 'https://zingmp3.vn';
14
- static VERSION_URL = '1.6.34';
15
- static SECRET_KEY = '2aa2d1c561e809b267f3638c4a307aab';
16
- static API_KEY = '88265e23d4284f25963e6eedac8fbfa3';
17
- ctime;
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';
20
+ ctime = Math.floor(Date.now() / 1000).toString();
18
21
  jar;
19
22
  instance;
20
23
  maxRate;
@@ -23,19 +26,21 @@ class Client {
23
26
  options?.maxRate?.[0] ?? 100 * 1024,
24
27
  options?.maxRate?.[1] ?? 16 * 1024
25
28
  ];
26
- this.ctime = Math.floor(Date.now() / 1000).toString();
27
29
  this.jar = new cookies.Cookies();
28
30
  const axiosOptions = {
29
- baseURL: Client.BASE_URL,
31
+ baseURL: ZingClient.BASE_URL,
30
32
  params: {
31
- version: Client.VERSION_URL,
32
- apiKey: Client.API_KEY,
33
+ version: ZingClient.VERSION_URL_V1,
34
+ apiKey: ZingClient.API_KEY_V1,
33
35
  ctime: this.ctime
34
36
  },
35
37
  maxRate: [
36
38
  100 * 1024,
37
39
  this.maxRate[0]
38
- ]
40
+ ],
41
+ headers: {
42
+ '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'
43
+ }
39
44
  };
40
45
  this.instance = axios.create(axiosOptions);
41
46
  this.instance.interceptors.request.use((options) => {
@@ -59,21 +64,17 @@ class Client {
59
64
  throw new lapse.Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
60
65
  const uri = '/api/v2/page/get/video';
61
66
  try {
62
- if (this.jar.getCookies(Client.BASE_URL).length === 0)
63
- await this.instance.get('/');
67
+ if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
68
+ void await this.instance.get('/');
64
69
  const response = await this.instance.get(uri, {
65
70
  params: {
66
71
  id: videoID,
67
- sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + Client.VERSION_URL, Client.SECRET_KEY)
68
- },
69
- maxRate: [
70
- 100 * 1024,
71
- this.maxRate[0]
72
- ]
72
+ sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
73
+ }
73
74
  });
74
75
  const body = response.data;
75
76
  if (body.err !== 0)
76
- throw new lapse.Lapse(body.msg, 'ERROR_VIDEO_NOT_FOUND');
77
+ throw new lapse.Lapse('Video could not be found', 'ERROR_VIDEO_NOT_FOUND', response.status, body);
77
78
  const videoURL = body.data?.streaming?.hls?.['360p'];
78
79
  if (!videoURL || !videoURL.length)
79
80
  throw new lapse.Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
@@ -116,24 +117,44 @@ class Client {
116
117
  async music(musicID) {
117
118
  if (typeof musicID !== 'string' || !musicID.trim().length)
118
119
  throw new lapse.Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
120
+ let musicURL;
119
121
  const uri = '/api/v2/song/get/streaming';
120
122
  try {
121
- if (this.jar.getCookies(Client.BASE_URL).length === 0)
122
- await this.instance.get('/');
123
+ if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
124
+ void await this.instance.get('/');
123
125
  const response = await this.instance.get(uri, {
124
126
  params: {
125
127
  id: musicID,
126
- sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + Client.VERSION_URL, Client.SECRET_KEY)
127
- },
128
- maxRate: [
129
- 100 * 1024,
130
- this.maxRate[0]
131
- ]
128
+ sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
129
+ }
132
130
  });
133
131
  const body = response.data;
134
- if (body.err !== 0)
135
- throw new lapse.Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND');
136
- const musicURL = body.data?.[128];
132
+ if (body.err === -1150) {
133
+ let retrySuccess = false;
134
+ const uri_v2 = '/api/song/get-song-info';
135
+ for (let step = 0; step < 2; step++) {
136
+ const retry = await this.instance.get(uri_v2, {
137
+ params: {
138
+ id: musicID,
139
+ api_key: ZingClient.API_KEY_V2,
140
+ sig: encrypt.createSignature('/song/get-song-info', 'ctime=' + this.ctime + 'id=' + musicID, ZingClient.SECRET_KEY_V2),
141
+ version: void 0,
142
+ apiKey: void 0
143
+ }
144
+ });
145
+ if (retry.data.err === 0) {
146
+ retrySuccess = true;
147
+ musicURL = retry.data.data?.streaming?.default?.[128];
148
+ break;
149
+ }
150
+ }
151
+ if (!retrySuccess)
152
+ throw new lapse.Lapse('Music requested by VIP, PRI', 'ERROR_MUSIC_VIP_ONLY', response.status, body);
153
+ }
154
+ else if (body.err === 0)
155
+ musicURL = body.data?.[128];
156
+ else
157
+ throw new lapse.Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND', response.status, body);
137
158
  if (!musicURL || !musicURL.length)
138
159
  throw new lapse.Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
139
160
  const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });
@@ -172,6 +193,52 @@ class Client {
172
193
  });
173
194
  return music;
174
195
  }
196
+ async search(keyword) {
197
+ if (typeof keyword !== 'string' || !keyword.trim().length)
198
+ throw new lapse.Lapse('Keyword must be a non-empty string', 'ERROR_INVALID_KEYWORD');
199
+ const uri = '/api/v2/search/multi';
200
+ try {
201
+ if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
202
+ void await this.instance.get('/');
203
+ const response = await this.instance.get(uri, {
204
+ params: {
205
+ q: keyword,
206
+ sig: encrypt.createSignature(uri, 'ctime=' + this.ctime + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
207
+ }
208
+ });
209
+ const body = response.data;
210
+ if (body.err !== 0)
211
+ throw new lapse.Lapse('Could not perform search', 'ERROR_SEARCH_FAILED', response.status, body);
212
+ const songs = body.data?.songs ?? [];
213
+ return songs.map((song) => ({
214
+ id: song.encodeId,
215
+ name: song.title,
216
+ alias: song.alias,
217
+ isOffical: song.isOffical,
218
+ username: song.username,
219
+ artists: song.artists.map((artist) => ({
220
+ id: artist.id,
221
+ name: artist.name,
222
+ alias: artist.alias,
223
+ thumbnail: {
224
+ w240: artist.thumbnailM,
225
+ w360: artist.thumbnail
226
+ }
227
+ })),
228
+ thumbnail: {
229
+ w94: song.thumbnailM,
230
+ w240: song.thumbnail
231
+ },
232
+ duration: song.duration,
233
+ releaseDate: song.releaseDate
234
+ }));
235
+ }
236
+ catch (error) {
237
+ if (error instanceof lapse.Lapse)
238
+ throw error;
239
+ throw new lapse.Lapse('Failed to perform search', 'ERROR_SEARCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
240
+ }
241
+ }
175
242
  }
176
243
  const clientOptions = {
177
244
  maxRate: [
@@ -179,9 +246,8 @@ const clientOptions = {
179
246
  16 * 1024
180
247
  ]
181
248
  };
182
- const client = new Client(clientOptions);
249
+ const client = new ZingClient(clientOptions);
183
250
 
184
- exports.Client = Client;
185
- exports.client = client;
251
+ exports.ZingClient = ZingClient;
186
252
  exports.default = client;
187
253
  //# sourceMappingURL=index.cjs.map
@@ -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,CA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AAC,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,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 ctime = Math.floor(Date.now() / 1000).toString();\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.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 void 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 });\n const body = response.data;\n if (body.err !== 0)\n throw new Lapse('Video could not be found', 'ERROR_VIDEO_NOT_FOUND', response.status, body);\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 void 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 });\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 });\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', response.status, body);\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', response.status, body);\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 async search(keyword) {\n if (typeof keyword !== 'string' || !keyword.trim().length)\n throw new Lapse('Keyword must be a non-empty string', 'ERROR_INVALID_KEYWORD');\n const uri = '/api/v2/search/multi';\n try {\n if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)\n void await this.instance.get('/');\n const response = await this.instance.get(uri, {\n params: {\n q: keyword,\n sig: createSignature(uri, 'ctime=' + this.ctime + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)\n }\n });\n const body = response.data;\n if (body.err !== 0)\n throw new Lapse('Could not perform search', 'ERROR_SEARCH_FAILED', response.status, body);\n const songs = body.data?.songs ?? [];\n return songs.map((song) => ({\n id: song.encodeId,\n name: song.title,\n alias: song.alias,\n isOffical: song.isOffical,\n username: song.username,\n artists: song.artists.map((artist) => ({\n id: artist.id,\n name: artist.name,\n alias: artist.alias,\n thumbnail: {\n w240: artist.thumbnailM,\n w360: artist.thumbnail\n }\n })),\n thumbnail: {\n w94: song.thumbnailM,\n w240: song.thumbnail\n },\n duration: song.duration,\n releaseDate: song.releaseDate\n }));\n }\n catch (error) {\n if (error instanceof Lapse)\n throw error;\n throw new Lapse('Failed to perform search', 'ERROR_SEARCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);\n }\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,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE;AACpD,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,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C3I,QAAQ;AACR,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,12 +4,15 @@ 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 Client {
8
- static BASE_URL = 'https://zingmp3.vn';
9
- static VERSION_URL = '1.6.34';
10
- static SECRET_KEY = '2aa2d1c561e809b267f3638c4a307aab';
11
- static API_KEY = '88265e23d4284f25963e6eedac8fbfa3';
12
- ctime;
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';
15
+ ctime = Math.floor(Date.now() / 1000).toString();
13
16
  jar;
14
17
  instance;
15
18
  maxRate;
@@ -18,19 +21,21 @@ class Client {
18
21
  options?.maxRate?.[0] ?? 100 * 1024,
19
22
  options?.maxRate?.[1] ?? 16 * 1024
20
23
  ];
21
- this.ctime = Math.floor(Date.now() / 1000).toString();
22
24
  this.jar = new Cookies();
23
25
  const axiosOptions = {
24
- baseURL: Client.BASE_URL,
26
+ baseURL: ZingClient.BASE_URL,
25
27
  params: {
26
- version: Client.VERSION_URL,
27
- apiKey: Client.API_KEY,
28
+ version: ZingClient.VERSION_URL_V1,
29
+ apiKey: ZingClient.API_KEY_V1,
28
30
  ctime: this.ctime
29
31
  },
30
32
  maxRate: [
31
33
  100 * 1024,
32
34
  this.maxRate[0]
33
- ]
35
+ ],
36
+ headers: {
37
+ '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'
38
+ }
34
39
  };
35
40
  this.instance = axios.create(axiosOptions);
36
41
  this.instance.interceptors.request.use((options) => {
@@ -54,21 +59,17 @@ class Client {
54
59
  throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
55
60
  const uri = '/api/v2/page/get/video';
56
61
  try {
57
- if (this.jar.getCookies(Client.BASE_URL).length === 0)
58
- await this.instance.get('/');
62
+ if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
63
+ void await this.instance.get('/');
59
64
  const response = await this.instance.get(uri, {
60
65
  params: {
61
66
  id: videoID,
62
- sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + Client.VERSION_URL, Client.SECRET_KEY)
63
- },
64
- maxRate: [
65
- 100 * 1024,
66
- this.maxRate[0]
67
- ]
67
+ sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + videoID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
68
+ }
68
69
  });
69
70
  const body = response.data;
70
71
  if (body.err !== 0)
71
- throw new Lapse(body.msg, 'ERROR_VIDEO_NOT_FOUND');
72
+ throw new Lapse('Video could not be found', 'ERROR_VIDEO_NOT_FOUND', response.status, body);
72
73
  const videoURL = body.data?.streaming?.hls?.['360p'];
73
74
  if (!videoURL || !videoURL.length)
74
75
  throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
@@ -111,24 +112,44 @@ class Client {
111
112
  async music(musicID) {
112
113
  if (typeof musicID !== 'string' || !musicID.trim().length)
113
114
  throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
115
+ let musicURL;
114
116
  const uri = '/api/v2/song/get/streaming';
115
117
  try {
116
- if (this.jar.getCookies(Client.BASE_URL).length === 0)
117
- await this.instance.get('/');
118
+ if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
119
+ void await this.instance.get('/');
118
120
  const response = await this.instance.get(uri, {
119
121
  params: {
120
122
  id: musicID,
121
- sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + Client.VERSION_URL, Client.SECRET_KEY)
122
- },
123
- maxRate: [
124
- 100 * 1024,
125
- this.maxRate[0]
126
- ]
123
+ sig: createSignature(uri, 'ctime=' + this.ctime + 'id=' + musicID + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
124
+ }
127
125
  });
128
126
  const body = response.data;
129
- if (body.err !== 0)
130
- throw new Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND');
131
- const musicURL = body.data?.[128];
127
+ if (body.err === -1150) {
128
+ let retrySuccess = false;
129
+ const uri_v2 = '/api/song/get-song-info';
130
+ for (let step = 0; step < 2; step++) {
131
+ const retry = await this.instance.get(uri_v2, {
132
+ params: {
133
+ id: musicID,
134
+ api_key: ZingClient.API_KEY_V2,
135
+ sig: createSignature('/song/get-song-info', 'ctime=' + this.ctime + 'id=' + musicID, ZingClient.SECRET_KEY_V2),
136
+ version: void 0,
137
+ apiKey: void 0
138
+ }
139
+ });
140
+ if (retry.data.err === 0) {
141
+ retrySuccess = true;
142
+ musicURL = retry.data.data?.streaming?.default?.[128];
143
+ break;
144
+ }
145
+ }
146
+ if (!retrySuccess)
147
+ throw new Lapse('Music requested by VIP, PRI', 'ERROR_MUSIC_VIP_ONLY', response.status, body);
148
+ }
149
+ else if (body.err === 0)
150
+ musicURL = body.data?.[128];
151
+ else
152
+ throw new Lapse('This song could not be found', 'ERROR_MUSIC_NOT_FOUND', response.status, body);
132
153
  if (!musicURL || !musicURL.length)
133
154
  throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
134
155
  const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });
@@ -167,6 +188,52 @@ class Client {
167
188
  });
168
189
  return music;
169
190
  }
191
+ async search(keyword) {
192
+ if (typeof keyword !== 'string' || !keyword.trim().length)
193
+ throw new Lapse('Keyword must be a non-empty string', 'ERROR_INVALID_KEYWORD');
194
+ const uri = '/api/v2/search/multi';
195
+ try {
196
+ if (this.jar.getCookies(ZingClient.BASE_URL).length === 0)
197
+ void await this.instance.get('/');
198
+ const response = await this.instance.get(uri, {
199
+ params: {
200
+ q: keyword,
201
+ sig: createSignature(uri, 'ctime=' + this.ctime + 'version=' + ZingClient.VERSION_URL_V1, ZingClient.SECRET_KEY_V1)
202
+ }
203
+ });
204
+ const body = response.data;
205
+ if (body.err !== 0)
206
+ throw new Lapse('Could not perform search', 'ERROR_SEARCH_FAILED', response.status, body);
207
+ const songs = body.data?.songs ?? [];
208
+ return songs.map((song) => ({
209
+ id: song.encodeId,
210
+ name: song.title,
211
+ alias: song.alias,
212
+ isOffical: song.isOffical,
213
+ username: song.username,
214
+ artists: song.artists.map((artist) => ({
215
+ id: artist.id,
216
+ name: artist.name,
217
+ alias: artist.alias,
218
+ thumbnail: {
219
+ w240: artist.thumbnailM,
220
+ w360: artist.thumbnail
221
+ }
222
+ })),
223
+ thumbnail: {
224
+ w94: song.thumbnailM,
225
+ w240: song.thumbnail
226
+ },
227
+ duration: song.duration,
228
+ releaseDate: song.releaseDate
229
+ }));
230
+ }
231
+ catch (error) {
232
+ if (error instanceof Lapse)
233
+ throw error;
234
+ throw new Lapse('Failed to perform search', 'ERROR_SEARCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
235
+ }
236
+ }
170
237
  }
171
238
  const clientOptions = {
172
239
  maxRate: [
@@ -174,6 +241,6 @@ const clientOptions = {
174
241
  16 * 1024
175
242
  ]
176
243
  };
177
- const client = new Client(clientOptions);
178
- export { client as default, client, Client };
244
+ const client = new ZingClient(clientOptions);
245
+ export { client as default, ZingClient };
179
246
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@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E_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 }
21
- export default client;
22
-
23
- export declare interface ClientOptions {
24
- maxRate?: [Download?: number, HighWaterMark?: number];
25
- }
26
-
27
- declare interface RequiredClientOptions {
28
- maxRate: [Download: number, HighWaterMark: number];
29
- }
30
-
31
- export declare type SearchCategory = 'artist' | 'music' | 'playlist' | 'video';
32
-
33
- export { }
1
+ import { Readable } from 'node:stream';
2
+ import type { ResponseSearch } from './types/fetch/response.js';
3
+ import type { ClientOptions, RequiredClientOptions } from './types/index.js';
4
+ export type { ResponseSearch, ClientOptions };
5
+ declare class ZingClient {
6
+ static readonly BASE_URL: string;
7
+ static readonly VERSION_URL_V1: string;
8
+ static readonly VERSION_URL_V2: string;
9
+ static readonly SECRET_KEY_V1: string;
10
+ static readonly SECRET_KEY_V2: string;
11
+ static readonly API_KEY_V1: string;
12
+ static readonly API_KEY_V2: string;
13
+ readonly ctime: string;
14
+ private readonly jar;
15
+ private readonly instance;
16
+ maxRate: RequiredClientOptions['maxRate'];
17
+ constructor(options?: ClientOptions);
18
+ video(videoID: string): Promise<Readable>;
19
+ videoSyncLike(videoID: string): Readable;
20
+ music(musicID: string): Promise<Readable>;
21
+ musicSyncLike(musicID: string): Readable;
22
+ search(keyword: string): Promise<ResponseSearch[]>;
23
+ }
24
+ declare const client: ZingClient;
25
+ export { client as default, ZingClient };
@@ -0,0 +1,22 @@
1
+ export interface ResponseSearch {
2
+ id: string;
3
+ name: string;
4
+ alias: string;
5
+ isOffical: boolean;
6
+ username: string;
7
+ artists: {
8
+ id: string;
9
+ name: string;
10
+ alias: string;
11
+ thumbnail: {
12
+ w240: string;
13
+ w360: string;
14
+ };
15
+ }[];
16
+ thumbnail: {
17
+ w94: string;
18
+ w240: string;
19
+ };
20
+ duration: number;
21
+ releaseDate: number;
22
+ }
@@ -0,0 +1,46 @@
1
+ export declare namespace Uri {
2
+ interface Music {
3
+ err: number;
4
+ data: {
5
+ 128?: string;
6
+ streaming?: {
7
+ default?: {
8
+ 128?: string;
9
+ };
10
+ };
11
+ };
12
+ }
13
+ interface Video {
14
+ err: number;
15
+ data: {
16
+ streaming?: {
17
+ hls?: {
18
+ '360p'?: string;
19
+ };
20
+ };
21
+ };
22
+ }
23
+ interface Search {
24
+ err: number;
25
+ data: {
26
+ songs?: {
27
+ encodeId: string;
28
+ title: string;
29
+ alias: string;
30
+ isOffical: boolean;
31
+ username: string;
32
+ artists: {
33
+ id: string;
34
+ name: string;
35
+ alias: string;
36
+ thumbnail: string;
37
+ thumbnailM: string;
38
+ }[];
39
+ thumbnailM: string;
40
+ thumbnail: string;
41
+ duration: number;
42
+ releaseDate: number;
43
+ }[];
44
+ };
45
+ }
46
+ }
@@ -1,8 +1,7 @@
1
- type SearchCategory = 'artist' | 'music' | 'playlist' | 'video';
2
1
  interface ClientOptions {
3
2
  maxRate?: [Download?: number, HighWaterMark?: number];
4
3
  }
5
4
  interface RequiredClientOptions {
6
5
  maxRate: [Download: number, HighWaterMark: number];
7
6
  }
8
- export type { ClientOptions, RequiredClientOptions, SearchCategory };
7
+ export type { ClientOptions, RequiredClientOptions };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@khang07/zing-mp3-api",
3
- "version": "1.0.0",
4
- "author": "Khang <ngkhang9a5lqc11@gmail.com>",
3
+ "version": "1.1.0",
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"
@@ -15,6 +15,21 @@
15
15
  "types": "./dist/types/index.d.ts",
16
16
  "import": "./dist/esm/index.js",
17
17
  "require": "./dist/cjs/index.cjs"
18
+ },
19
+ "./utils/cookies": {
20
+ "types": "./dist/types/utils/cookies.d.ts",
21
+ "import": "./dist/esm/utils/cookies.js",
22
+ "require": "./dist/cjs/utils/cookies.cjs"
23
+ },
24
+ "./utils/encrypt": {
25
+ "types": "./dist/types/utils/encrypt.d.ts",
26
+ "import": "./dist/esm/utils/encrypt.js",
27
+ "require": "./dist/cjs/utils/encrypt.cjs"
28
+ },
29
+ "./utils/lapse": {
30
+ "types": "./dist/types/utils/lapse.d.ts",
31
+ "import": "./dist/esm/utils/lapse.js",
32
+ "require": "./dist/cjs/utils/lapse.cjs"
18
33
  }
19
34
  },
20
35
  "bugs": {
@@ -33,12 +48,12 @@
33
48
  "scripts": {
34
49
  "build:esm": "tsc -p tsconfig.json",
35
50
  "build:cjs": "rollup -c",
36
- "build:types": "api-extractor run --local",
37
- "build": "rm -rf dist && bun run build:esm && bun run build:cjs && bun run build:types && rm -fr dist/esm/types dist/cjs/types"
51
+ "build": "rm -rf dist && bun run build:esm && bun run build:cjs && rm -fr dist/esm/types dist/cjs/types",
52
+ "test": "mocha"
38
53
  },
39
54
  "devDependencies": {
40
- "@microsoft/api-extractor": "^7.58.1",
41
55
  "@types/node": "^25.5.2",
56
+ "mocha": "^11.7.5",
42
57
  "rollup": "^4.60.1",
43
58
  "typescript": "^6.0.2"
44
59
  },
@@ -47,6 +62,8 @@
47
62
  "m3u8stream": "^0.8.6"
48
63
  },
49
64
  "files": [
50
- "dist"
65
+ "dist",
66
+ "README.md",
67
+ "LICENSE"
51
68
  ]
52
69
  }
@@ -1,20 +0,0 @@
1
- import { Readable } from 'node:stream';
2
- import type { ClientOptions, RequiredClientOptions, SearchCategory } from './types/index.js';
3
- export type { ClientOptions, SearchCategory };
4
- declare class Client {
5
- static readonly BASE_URL: string;
6
- static readonly VERSION_URL: string;
7
- static readonly SECRET_KEY: string;
8
- static readonly API_KEY: string;
9
- readonly ctime: string;
10
- private readonly jar;
11
- private readonly instance;
12
- maxRate: RequiredClientOptions['maxRate'];
13
- constructor(options?: ClientOptions);
14
- video(videoID: string): Promise<Readable>;
15
- videoSyncLike(videoID: string): Readable;
16
- music(musicID: string): Promise<Readable>;
17
- musicSyncLike(musicID: string): Readable;
18
- }
19
- declare const client: Client;
20
- export { client as default, client, Client };
@@ -1,17 +0,0 @@
1
- interface UriStreaming {
2
- err: number;
3
- msg: string;
4
- data: Partial<Record<128, string>>;
5
- }
6
- interface UriVideo {
7
- err: number;
8
- msg: string;
9
- data: {
10
- streaming: {
11
- hls: {
12
- '360p': string;
13
- };
14
- };
15
- };
16
- }
17
- export type { UriStreaming, UriVideo };
@@ -1,11 +0,0 @@
1
- // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
- // It should be published with your NPM package. It should not be tracked by Git.
3
- {
4
- "tsdocVersion": "0.12",
5
- "toolPackages": [
6
- {
7
- "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.1"
9
- }
10
- ]
11
- }
File without changes
File without changes
File without changes
File without changes