@khang07/zing-mp3-api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
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 };
@@ -0,0 +1,14 @@
1
+ type CookieSameSite = 'Strict' | 'Lax' | 'None';
2
+ interface CookieRecord {
3
+ name: string;
4
+ value: string;
5
+ domain: string;
6
+ path: string;
7
+ expiresAt?: number;
8
+ secure: boolean;
9
+ httpOnly: boolean;
10
+ sameSite?: CookieSameSite;
11
+ hostOnly: boolean;
12
+ }
13
+ type StoreCookie = Map<string, Map<string, Map<string, CookieRecord>>>;
14
+ export type { CookieRecord, CookieSameSite, StoreCookie };
@@ -0,0 +1,17 @@
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 };
@@ -0,0 +1,8 @@
1
+ type SearchCategory = 'artist' | 'music' | 'playlist' | 'video';
2
+ interface ClientOptions {
3
+ maxRate?: [Download?: number, HighWaterMark?: number];
4
+ }
5
+ interface RequiredClientOptions {
6
+ maxRate: [Download: number, HighWaterMark: number];
7
+ }
8
+ export type { ClientOptions, RequiredClientOptions, SearchCategory };
@@ -0,0 +1,13 @@
1
+ import type { CookieRecord } from '../types/cookie.js';
2
+ export declare class Cookies {
3
+ private readonly store;
4
+ setCookie(setCookie: string, requestUrl: string): void;
5
+ setCookies(setCookies: string[] | undefined, requestUrl: string): void;
6
+ getCookies(requestUrl: string): CookieRecord[];
7
+ getCookieHeader(requestUrl: string): string;
8
+ applyToHeaders(requestUrl: string, headers?: Record<string, string>): Record<string, string>;
9
+ deleteCookie(domain: string, path: string, name: string): void;
10
+ cleanup(): void;
11
+ toJSON(): CookieRecord[];
12
+ fromJSON(cookies: CookieRecord[]): void;
13
+ }
@@ -0,0 +1 @@
1
+ export declare function createSignature(uri: string, params: string, secret: string): string;
@@ -0,0 +1,6 @@
1
+ export declare class Lapse extends Error {
2
+ readonly code: string;
3
+ status?: number;
4
+ cause?: unknown;
5
+ constructor(message: string, code: string, status?: number, cause?: unknown);
6
+ }
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var axios = require('axios');
6
+ var m3u8stream = require('m3u8stream');
7
+ var node_stream = require('node:stream');
8
+ var cookies = require('./utils/cookies.cjs');
9
+ var encrypt = require('./utils/encrypt.cjs');
10
+ var lapse = require('./utils/lapse.cjs');
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;
18
+ jar;
19
+ instance;
20
+ maxRate;
21
+ constructor(options = {}) {
22
+ this.maxRate = [
23
+ options?.maxRate?.[0] ?? 100 * 1024,
24
+ options?.maxRate?.[1] ?? 16 * 1024
25
+ ];
26
+ this.ctime = Math.floor(Date.now() / 1000).toString();
27
+ this.jar = new cookies.Cookies();
28
+ const axiosOptions = {
29
+ baseURL: Client.BASE_URL,
30
+ params: {
31
+ version: Client.VERSION_URL,
32
+ apiKey: Client.API_KEY,
33
+ ctime: this.ctime
34
+ },
35
+ maxRate: [
36
+ 100 * 1024,
37
+ this.maxRate[0]
38
+ ]
39
+ };
40
+ this.instance = axios.create(axiosOptions);
41
+ this.instance.interceptors.request.use((options) => {
42
+ const base = options.baseURL ?? '';
43
+ const url = new URL(options.url ?? '/', base).toString();
44
+ const additionalHeaders = this.jar.applyToHeaders(url);
45
+ for (const [key, value] of Object.entries(additionalHeaders))
46
+ options.headers.set(key, value);
47
+ return options;
48
+ });
49
+ this.instance.interceptors.response.use((response) => {
50
+ const setCookie = response.headers['set-cookie'];
51
+ const requestUrl = response.request?.res?.responseUrl ?? response.config.url;
52
+ if (requestUrl && Array.isArray(setCookie))
53
+ this.jar.setCookies(setCookie, requestUrl);
54
+ return response;
55
+ });
56
+ }
57
+ async video(videoID) {
58
+ if (typeof videoID !== 'string' || !videoID.length)
59
+ throw new lapse.Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
60
+ const uri = '/api/v2/page/get/video';
61
+ try {
62
+ if (this.jar.getCookies(Client.BASE_URL).length === 0)
63
+ await this.instance.get('/');
64
+ const response = await this.instance.get(uri, {
65
+ params: {
66
+ 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
+ ]
73
+ });
74
+ const body = response.data;
75
+ if (body.err !== 0)
76
+ throw new lapse.Lapse(body.msg, 'ERROR_VIDEO_NOT_FOUND');
77
+ const videoURL = body.data?.streaming?.hls?.['360p'];
78
+ if (!videoURL || !videoURL.length)
79
+ throw new lapse.Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
80
+ const streamVideo = m3u8stream(videoURL);
81
+ streamVideo.once('error', (error) => {
82
+ const lapse$1 = new lapse.Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);
83
+ streamVideo.destroy(lapse$1);
84
+ });
85
+ return streamVideo;
86
+ }
87
+ catch (error) {
88
+ if (error instanceof lapse.Lapse)
89
+ throw error;
90
+ throw new lapse.Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
91
+ }
92
+ }
93
+ videoSyncLike(videoID) {
94
+ const video = new node_stream.PassThrough({ highWaterMark: this.maxRate[1] });
95
+ void this.video(videoID)
96
+ .then((source) => {
97
+ source.once('error', (error) => {
98
+ const lapse$1 = error instanceof lapse.Lapse ? error : new lapse.Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);
99
+ video.destroy(lapse$1);
100
+ });
101
+ const destroy = () => {
102
+ if (!source.destroyed)
103
+ source.destroy();
104
+ };
105
+ video.once('close', destroy);
106
+ video.once('error', destroy);
107
+ source.pipe(video);
108
+ })
109
+ .catch((error) => {
110
+ if (error instanceof lapse.Lapse)
111
+ throw error;
112
+ throw new lapse.Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
113
+ });
114
+ return video;
115
+ }
116
+ async music(musicID) {
117
+ if (typeof musicID !== 'string' || !musicID.trim().length)
118
+ throw new lapse.Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
119
+ const uri = '/api/v2/song/get/streaming';
120
+ try {
121
+ if (this.jar.getCookies(Client.BASE_URL).length === 0)
122
+ await this.instance.get('/');
123
+ const response = await this.instance.get(uri, {
124
+ params: {
125
+ 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
+ ]
132
+ });
133
+ 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];
137
+ if (!musicURL || !musicURL.length)
138
+ throw new lapse.Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
139
+ const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });
140
+ streamMusic.data.once('error', (error) => {
141
+ const lapse$1 = new lapse.Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', streamMusic.status, error);
142
+ streamMusic.data.destroy(lapse$1);
143
+ });
144
+ return streamMusic.data;
145
+ }
146
+ catch (error) {
147
+ if (error instanceof lapse.Lapse)
148
+ throw error;
149
+ throw new lapse.Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
150
+ }
151
+ }
152
+ musicSyncLike(musicID) {
153
+ const music = new node_stream.PassThrough({ highWaterMark: this.maxRate[1] });
154
+ void this.music(musicID)
155
+ .then((source) => {
156
+ source.once('error', (error) => {
157
+ const lapse$1 = error instanceof lapse.Lapse ? error : new lapse.Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);
158
+ music.destroy(lapse$1);
159
+ });
160
+ const destroy = () => {
161
+ if (!source.destroyed)
162
+ source.destroy();
163
+ };
164
+ music.once('close', destroy);
165
+ music.once('error', destroy);
166
+ source.pipe(music);
167
+ })
168
+ .catch((error) => {
169
+ if (error instanceof lapse.Lapse)
170
+ throw error;
171
+ throw new lapse.Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
172
+ });
173
+ return music;
174
+ }
175
+ }
176
+ const clientOptions = {
177
+ maxRate: [
178
+ 100 * 1024,
179
+ 16 * 1024
180
+ ]
181
+ };
182
+ const client = new Client(clientOptions);
183
+
184
+ exports.Client = Client;
185
+ exports.client = client;
186
+ exports.default = client;
187
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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;AAC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,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,MAAM,CAAC,aAAa;;;;;;"}
@@ -0,0 +1,251 @@
1
+ 'use strict';
2
+
3
+ function normalizeDomain(domain) {
4
+ return domain.trim().toLowerCase().replace(/^\./, '');
5
+ }
6
+ function slash(pathname) {
7
+ if (!pathname || pathname[0] !== '/')
8
+ return '/';
9
+ if (pathname === '/')
10
+ return '/';
11
+ const lastSlash = pathname.lastIndexOf('/');
12
+ return lastSlash <= 0 ? '/' : pathname.slice(0, lastSlash);
13
+ }
14
+ function isExpired(cookie, time) {
15
+ return cookie.expiresAt !== undefined && cookie.expiresAt <= time;
16
+ }
17
+ function domainMatches(hostname, cookieDomain, hostOnly) {
18
+ const host = hostname.toLowerCase();
19
+ const domain = cookieDomain.toLowerCase();
20
+ if (hostOnly)
21
+ return host === domain;
22
+ return host === domain || host.endsWith('.' + domain);
23
+ }
24
+ function pathMatches(requestPath, cookiePath) {
25
+ if (requestPath === cookiePath)
26
+ return true;
27
+ if (!requestPath.startsWith(cookiePath))
28
+ return false;
29
+ if (cookiePath.endsWith('/'))
30
+ return true;
31
+ return requestPath[cookiePath.length] === '/';
32
+ }
33
+ function parseExpires(value) {
34
+ const time = Date.parse(value);
35
+ return Number.isNaN(time) ? undefined : time;
36
+ }
37
+ function stripQuotes(value) {
38
+ if (value.length >= 2 && value.startsWith('"') && value.endsWith('"'))
39
+ return value.slice(1, -1);
40
+ return value;
41
+ }
42
+ class Cookies {
43
+ store = new Map();
44
+ setCookie(setCookie, requestUrl) {
45
+ const url = new URL(requestUrl);
46
+ const parts = setCookie.split(';').map((part) => part.trim()).filter(Boolean);
47
+ if (parts.length === 0)
48
+ return;
49
+ const [nameValue, ...attributes] = parts;
50
+ const equalsIndex = nameValue.indexOf('=');
51
+ if (equalsIndex <= 0)
52
+ return;
53
+ const name = nameValue.slice(0, equalsIndex).trim();
54
+ const value = stripQuotes(nameValue.slice(equalsIndex + 1).trim());
55
+ let domain = normalizeDomain(url.hostname);
56
+ let path = slash(url.pathname);
57
+ let expiresAt;
58
+ let secure = false;
59
+ let httpOnly = false;
60
+ let sameSite;
61
+ let hostOnly = true;
62
+ let maxAge;
63
+ for (const attribute of attributes) {
64
+ const [rawKey, ...rawRest] = attribute.split('=');
65
+ const key = rawKey.trim().toLowerCase();
66
+ const attrValue = rawRest.join('=').trim();
67
+ switch (key) {
68
+ case 'domain': {
69
+ if (!attrValue)
70
+ break;
71
+ const normalized = normalizeDomain(attrValue);
72
+ if (!normalized)
73
+ break;
74
+ domain = normalized;
75
+ hostOnly = false;
76
+ break;
77
+ }
78
+ case 'path': {
79
+ path = attrValue && attrValue.startsWith('/') ? attrValue : '/';
80
+ break;
81
+ }
82
+ case 'expires': {
83
+ const parsed = parseExpires(attrValue);
84
+ if (parsed !== undefined)
85
+ expiresAt = parsed;
86
+ break;
87
+ }
88
+ case 'max-age': {
89
+ const parsed = Number.parseInt(attrValue, 10);
90
+ if (!Number.isNaN(parsed))
91
+ maxAge = parsed;
92
+ break;
93
+ }
94
+ case 'secure': {
95
+ secure = true;
96
+ break;
97
+ }
98
+ case 'httponly': {
99
+ httpOnly = true;
100
+ break;
101
+ }
102
+ case 'samesite': {
103
+ const normalized = attrValue.toLowerCase();
104
+ if (normalized === 'strict')
105
+ sameSite = 'Strict';
106
+ else if (normalized === 'lax')
107
+ sameSite = 'Lax';
108
+ else if (normalized === 'none')
109
+ sameSite = 'None';
110
+ break;
111
+ }
112
+ default:
113
+ break;
114
+ }
115
+ }
116
+ if (!domainMatches(url.hostname, domain, hostOnly))
117
+ return;
118
+ if (maxAge !== undefined)
119
+ expiresAt = maxAge <= 0 ? 0 : Date.now() + maxAge * 1000;
120
+ const cookie = {
121
+ name,
122
+ value,
123
+ domain,
124
+ path,
125
+ expiresAt,
126
+ secure,
127
+ httpOnly,
128
+ sameSite,
129
+ hostOnly
130
+ };
131
+ if (isExpired(cookie, Date.now())) {
132
+ this.deleteCookie(cookie.domain, cookie.path, cookie.name);
133
+ return;
134
+ }
135
+ let byPath = this.store.get(cookie.domain);
136
+ if (!byPath) {
137
+ byPath = new Map();
138
+ this.store.set(cookie.domain, byPath);
139
+ }
140
+ let byName = byPath.get(cookie.path);
141
+ if (!byName) {
142
+ byName = new Map();
143
+ byPath.set(cookie.path, byName);
144
+ }
145
+ byName.set(cookie.name, cookie);
146
+ }
147
+ setCookies(setCookies, requestUrl) {
148
+ if (!setCookies?.length)
149
+ return;
150
+ for (const line of setCookies)
151
+ this.setCookie(line, requestUrl);
152
+ }
153
+ getCookies(requestUrl) {
154
+ const url = new URL(requestUrl);
155
+ const hostname = url.hostname.toLowerCase();
156
+ const pathname = url.pathname || '/';
157
+ const isHttps = url.protocol === 'https:';
158
+ const out = [];
159
+ for (const [, byPath] of this.store) {
160
+ for (const [, byName] of byPath) {
161
+ for (const [, cookie] of byName) {
162
+ if (isExpired(cookie, Date.now()))
163
+ continue;
164
+ if (cookie.secure && !isHttps)
165
+ continue;
166
+ if (!domainMatches(hostname, cookie.domain, cookie.hostOnly))
167
+ continue;
168
+ if (!pathMatches(pathname, cookie.path))
169
+ continue;
170
+ out.push(cookie);
171
+ }
172
+ }
173
+ }
174
+ out.sort((a, b) => b.path.length - a.path.length || a.name.localeCompare(b.name));
175
+ return out;
176
+ }
177
+ getCookieHeader(requestUrl) {
178
+ return this.getCookies(requestUrl)
179
+ .map(cookie => cookie.name + '=' + cookie.value)
180
+ .join('; ');
181
+ }
182
+ applyToHeaders(requestUrl, headers = {}) {
183
+ const cookie = this.getCookieHeader(requestUrl);
184
+ if (!cookie)
185
+ return headers;
186
+ return {
187
+ ...headers,
188
+ Cookie: cookie
189
+ };
190
+ }
191
+ deleteCookie(domain, path, name) {
192
+ const byPath = this.store.get(normalizeDomain(domain));
193
+ if (!byPath)
194
+ return;
195
+ const byName = byPath.get(path);
196
+ if (!byName)
197
+ return;
198
+ byName.delete(name);
199
+ if (byName.size === 0)
200
+ byPath.delete(path);
201
+ if (byPath.size === 0)
202
+ this.store.delete(normalizeDomain(domain));
203
+ }
204
+ cleanup() {
205
+ const time = Date.now();
206
+ for (const [domain, byPath] of this.store) {
207
+ for (const [path, byName] of byPath) {
208
+ for (const [name, cookie] of byName) {
209
+ if (isExpired(cookie, time))
210
+ byName.delete(name);
211
+ }
212
+ if (byName.size === 0)
213
+ byPath.delete(path);
214
+ }
215
+ if (byPath.size === 0)
216
+ this.store.delete(domain);
217
+ }
218
+ }
219
+ toJSON() {
220
+ this.cleanup();
221
+ const out = [];
222
+ for (const [, byPath] of this.store) {
223
+ for (const [, byName] of byPath) {
224
+ for (const [, cookie] of byName)
225
+ out.push({ ...cookie });
226
+ }
227
+ }
228
+ return out;
229
+ }
230
+ fromJSON(cookies) {
231
+ this.store.clear();
232
+ for (const cookie of cookies) {
233
+ if (isExpired(cookie, Date.now()))
234
+ continue;
235
+ let byPath = this.store.get(cookie.domain);
236
+ if (!byPath) {
237
+ byPath = new Map();
238
+ this.store.set(cookie.domain, byPath);
239
+ }
240
+ let byName = byPath.get(cookie.path);
241
+ if (!byName) {
242
+ byName = new Map();
243
+ byPath.set(cookie.path, byName);
244
+ }
245
+ byName.set(cookie.name, { ...cookie });
246
+ }
247
+ }
248
+ }
249
+
250
+ exports.Cookies = Cookies;
251
+ //# sourceMappingURL=cookies.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.cjs","sources":["../../esm/utils/cookies.js"],"sourcesContent":["function normalizeDomain(domain) {\n return domain.trim().toLowerCase().replace(/^\\./, '');\n}\nfunction slash(pathname) {\n if (!pathname || pathname[0] !== '/')\n return '/';\n if (pathname === '/')\n return '/';\n const lastSlash = pathname.lastIndexOf('/');\n return lastSlash <= 0 ? '/' : pathname.slice(0, lastSlash);\n}\nfunction isExpired(cookie, time) {\n return cookie.expiresAt !== undefined && cookie.expiresAt <= time;\n}\nfunction domainMatches(hostname, cookieDomain, hostOnly) {\n const host = hostname.toLowerCase();\n const domain = cookieDomain.toLowerCase();\n if (hostOnly)\n return host === domain;\n return host === domain || host.endsWith('.' + domain);\n}\nfunction pathMatches(requestPath, cookiePath) {\n if (requestPath === cookiePath)\n return true;\n if (!requestPath.startsWith(cookiePath))\n return false;\n if (cookiePath.endsWith('/'))\n return true;\n return requestPath[cookiePath.length] === '/';\n}\nfunction parseExpires(value) {\n const time = Date.parse(value);\n return Number.isNaN(time) ? undefined : time;\n}\nfunction stripQuotes(value) {\n if (value.length >= 2 && value.startsWith('\"') && value.endsWith('\"'))\n return value.slice(1, -1);\n return value;\n}\nexport class Cookies {\n store = new Map();\n setCookie(setCookie, requestUrl) {\n const url = new URL(requestUrl);\n const parts = setCookie.split(';').map((part) => part.trim()).filter(Boolean);\n if (parts.length === 0)\n return;\n const [nameValue, ...attributes] = parts;\n const equalsIndex = nameValue.indexOf('=');\n if (equalsIndex <= 0)\n return;\n const name = nameValue.slice(0, equalsIndex).trim();\n const value = stripQuotes(nameValue.slice(equalsIndex + 1).trim());\n let domain = normalizeDomain(url.hostname);\n let path = slash(url.pathname);\n let expiresAt;\n let secure = false;\n let httpOnly = false;\n let sameSite;\n let hostOnly = true;\n let maxAge;\n for (const attribute of attributes) {\n const [rawKey, ...rawRest] = attribute.split('=');\n const key = rawKey.trim().toLowerCase();\n const attrValue = rawRest.join('=').trim();\n switch (key) {\n case 'domain': {\n if (!attrValue)\n break;\n const normalized = normalizeDomain(attrValue);\n if (!normalized)\n break;\n domain = normalized;\n hostOnly = false;\n break;\n }\n case 'path': {\n path = attrValue && attrValue.startsWith('/') ? attrValue : '/';\n break;\n }\n case 'expires': {\n const parsed = parseExpires(attrValue);\n if (parsed !== undefined)\n expiresAt = parsed;\n break;\n }\n case 'max-age': {\n const parsed = Number.parseInt(attrValue, 10);\n if (!Number.isNaN(parsed))\n maxAge = parsed;\n break;\n }\n case 'secure': {\n secure = true;\n break;\n }\n case 'httponly': {\n httpOnly = true;\n break;\n }\n case 'samesite': {\n const normalized = attrValue.toLowerCase();\n if (normalized === 'strict')\n sameSite = 'Strict';\n else if (normalized === 'lax')\n sameSite = 'Lax';\n else if (normalized === 'none')\n sameSite = 'None';\n break;\n }\n default:\n break;\n }\n }\n if (!domainMatches(url.hostname, domain, hostOnly))\n return;\n if (maxAge !== undefined)\n expiresAt = maxAge <= 0 ? 0 : Date.now() + maxAge * 1000;\n const cookie = {\n name,\n value,\n domain,\n path,\n expiresAt,\n secure,\n httpOnly,\n sameSite,\n hostOnly\n };\n if (isExpired(cookie, Date.now())) {\n this.deleteCookie(cookie.domain, cookie.path, cookie.name);\n return;\n }\n let byPath = this.store.get(cookie.domain);\n if (!byPath) {\n byPath = new Map();\n this.store.set(cookie.domain, byPath);\n }\n let byName = byPath.get(cookie.path);\n if (!byName) {\n byName = new Map();\n byPath.set(cookie.path, byName);\n }\n byName.set(cookie.name, cookie);\n }\n setCookies(setCookies, requestUrl) {\n if (!setCookies?.length)\n return;\n for (const line of setCookies)\n this.setCookie(line, requestUrl);\n }\n getCookies(requestUrl) {\n const url = new URL(requestUrl);\n const hostname = url.hostname.toLowerCase();\n const pathname = url.pathname || '/';\n const isHttps = url.protocol === 'https:';\n const out = [];\n for (const [, byPath] of this.store) {\n for (const [, byName] of byPath) {\n for (const [, cookie] of byName) {\n if (isExpired(cookie, Date.now()))\n continue;\n if (cookie.secure && !isHttps)\n continue;\n if (!domainMatches(hostname, cookie.domain, cookie.hostOnly))\n continue;\n if (!pathMatches(pathname, cookie.path))\n continue;\n out.push(cookie);\n }\n }\n }\n out.sort((a, b) => b.path.length - a.path.length || a.name.localeCompare(b.name));\n return out;\n }\n getCookieHeader(requestUrl) {\n return this.getCookies(requestUrl)\n .map(cookie => cookie.name + '=' + cookie.value)\n .join('; ');\n }\n applyToHeaders(requestUrl, headers = {}) {\n const cookie = this.getCookieHeader(requestUrl);\n if (!cookie)\n return headers;\n return {\n ...headers,\n Cookie: cookie\n };\n }\n deleteCookie(domain, path, name) {\n const byPath = this.store.get(normalizeDomain(domain));\n if (!byPath)\n return;\n const byName = byPath.get(path);\n if (!byName)\n return;\n byName.delete(name);\n if (byName.size === 0)\n byPath.delete(path);\n if (byPath.size === 0)\n this.store.delete(normalizeDomain(domain));\n }\n cleanup() {\n const time = Date.now();\n for (const [domain, byPath] of this.store) {\n for (const [path, byName] of byPath) {\n for (const [name, cookie] of byName) {\n if (isExpired(cookie, time))\n byName.delete(name);\n }\n if (byName.size === 0)\n byPath.delete(path);\n }\n if (byPath.size === 0)\n this.store.delete(domain);\n }\n }\n toJSON() {\n this.cleanup();\n const out = [];\n for (const [, byPath] of this.store) {\n for (const [, byName] of byPath) {\n for (const [, cookie] of byName)\n out.push({ ...cookie });\n }\n }\n return out;\n }\n fromJSON(cookies) {\n this.store.clear();\n for (const cookie of cookies) {\n if (isExpired(cookie, Date.now()))\n continue;\n let byPath = this.store.get(cookie.domain);\n if (!byPath) {\n byPath = new Map();\n this.store.set(cookie.domain, byPath);\n }\n let byName = byPath.get(cookie.path);\n if (!byName) {\n byName = new Map();\n byPath.set(cookie.path, byName);\n }\n byName.set(cookie.name, { ...cookie });\n }\n }\n}\n//# sourceMappingURL=cookies.js.map"],"names":[],"mappings":";;AAAA,SAAS,eAAe,CAAC,MAAM,EAAE;AACjC,IAAI,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AACzD;AACA,SAAS,KAAK,CAAC,QAAQ,EAAE;AACzB,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG;AACxC,QAAQ,OAAO,GAAG;AAClB,IAAI,IAAI,QAAQ,KAAK,GAAG;AACxB,QAAQ,OAAO,GAAG;AAClB,IAAI,MAAM,SAAS,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC;AAC/C,IAAI,OAAO,SAAS,IAAI,CAAC,GAAG,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC;AAC9D;AACA,SAAS,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE;AACjC,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI;AACrE;AACA,SAAS,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE;AACzD,IAAI,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,EAAE;AACvC,IAAI,MAAM,MAAM,GA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AC,IAAI,MAAM,EAAE;AAC7C,gBAAgB,KAAK,MAAM,GAAG,MAAM,CAAC,IAAI,MAAM;AAC/C,oBAAoB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC;AAC3C,YAAY;AACZ,QAAQ;AACR,QAAQ,OAAO,GAAG;AAClB,IAAI;AACJ,IAAI,QAAQ,CAAC,OAAO,EAAE;AACtB,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;AAC1B,QAAQ,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;AACtC,YAAY,IAAI,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;AAC7C,gBAAgB;AAChB,YAAY,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;AACtD,YAAY,IAAI,CAAC,MAAM,EAAE;AACzB,gBAAgB,MAAM,GAAG,IAAI,GAAG,EAAE;AAClC,gBAAgB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;AACrD,YAAY;AACZ,YAAY,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;AAChD,YAAY,IAAI,CAAC,MAAM,EAAE;AACzB,gBAAgB,MAAM,GAAG,IAAI,GAAG,EAAE;AAClC,gBAAgB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;AAC/C,YAAY;AACZ,YAAY,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC;AAClD,QAAQ;AACR,IAAI;AACJ;;;;"}
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var node_crypto = require('node:crypto');
4
+
5
+ function createHash256(value) {
6
+ return node_crypto.createHash('sha256')
7
+ .update(value)
8
+ .digest('hex');
9
+ }
10
+ function createHmac512(value, secret) {
11
+ return node_crypto.createHmac('sha512', secret)
12
+ .update(Buffer.from(value, 'utf8'))
13
+ .digest('hex');
14
+ }
15
+ function createSignature(uri, params, secret) {
16
+ const hash = createHash256(params);
17
+ return createHmac512(uri + hash, secret);
18
+ }
19
+
20
+ exports.createSignature = createSignature;
21
+ //# sourceMappingURL=encrypt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypt.cjs","sources":["../../esm/utils/encrypt.js"],"sourcesContent":["import { createHash, createHmac } from 'node:crypto';\nfunction createHash256(value) {\n return createHash('sha256')\n .update(value)\n .digest('hex');\n}\nfunction createHmac512(value, secret) {\n return createHmac('sha512', secret)\n .update(Buffer.from(value, 'utf8'))\n .digest('hex');\n}\nexport function createSignature(uri, params, secret) {\n const hash = createHash256(params);\n return createHmac512(uri + hash, secret);\n}\n//# sourceMappingURL=encrypt.js.map"],"names":["createHash","createHmac"],"mappings":";;;;AACA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,IAAI,OAAOA,sBAAU,CAAC,QAAQ;AAC9B,SAAS,MAAM,CAAC,KAAK;AACrB,SAAS,MAAM,CAAC,KAAK,CAAC;AACtB;AACA,SAAS,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE;AACtC,IAAI,OAAOC,sBAAU,CAAC,QAAQ,EAAE,MAAM;AACtC,SAAS,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;AAC1C,SAAS,MAAM,CAAC,KAAK,CAAC;AACtB;AACO,SAAS,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE;AACrD,IAAI,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC;AACtC,IAAI,OAAO,aAAa,CAAC,GAAG,GAAG,IAAI,EAAE,MAAM,CAAC;AAC5C;;;;"}
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ class Lapse extends Error {
4
+ code;
5
+ status;
6
+ cause;
7
+ constructor(message, code, status, cause) {
8
+ super(message);
9
+ this.name = 'ZING_MP3_ERROR';
10
+ this.code = code;
11
+ this.status = status;
12
+ this.cause = cause;
13
+ Object.setPrototypeOf(this, new.target.prototype);
14
+ }
15
+ }
16
+
17
+ exports.Lapse = Lapse;
18
+ //# sourceMappingURL=lapse.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lapse.cjs","sources":["../../esm/utils/lapse.js"],"sourcesContent":["export class Lapse extends Error {\n code;\n status;\n cause;\n constructor(message, code, status, cause) {\n super(message);\n this.name = 'ZING_MP3_ERROR';\n this.code = code;\n this.status = status;\n this.cause = cause;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n//# sourceMappingURL=lapse.js.map"],"names":[],"mappings":";;AAAO,MAAM,KAAK,SAAS,KAAK,CAAC;AACjC,IAAI,IAAI;AACR,IAAI,MAAM;AACV,IAAI,KAAK;AACT,IAAI,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;AAC9C,QAAQ,KAAK,CAAC,OAAO,CAAC;AACtB,QAAQ,IAAI,CAAC,IAAI,GAAG,gBAAgB;AACpC,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI;AACxB,QAAQ,IAAI,CAAC,MAAM,GAAG,MAAM;AAC5B,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK;AAC1B,QAAQ,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC;AACzD,IAAI;AACJ;;;;"}
@@ -0,0 +1,179 @@
1
+ import axios from 'axios';
2
+ import m3u8stream from 'm3u8stream';
3
+ import { Readable, PassThrough } from 'node:stream';
4
+ import { Cookies } from './utils/cookies.js';
5
+ import { createSignature } from './utils/encrypt.js';
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;
13
+ jar;
14
+ instance;
15
+ maxRate;
16
+ constructor(options = {}) {
17
+ this.maxRate = [
18
+ options?.maxRate?.[0] ?? 100 * 1024,
19
+ options?.maxRate?.[1] ?? 16 * 1024
20
+ ];
21
+ this.ctime = Math.floor(Date.now() / 1000).toString();
22
+ this.jar = new Cookies();
23
+ const axiosOptions = {
24
+ baseURL: Client.BASE_URL,
25
+ params: {
26
+ version: Client.VERSION_URL,
27
+ apiKey: Client.API_KEY,
28
+ ctime: this.ctime
29
+ },
30
+ maxRate: [
31
+ 100 * 1024,
32
+ this.maxRate[0]
33
+ ]
34
+ };
35
+ this.instance = axios.create(axiosOptions);
36
+ this.instance.interceptors.request.use((options) => {
37
+ const base = options.baseURL ?? '';
38
+ const url = new URL(options.url ?? '/', base).toString();
39
+ const additionalHeaders = this.jar.applyToHeaders(url);
40
+ for (const [key, value] of Object.entries(additionalHeaders))
41
+ options.headers.set(key, value);
42
+ return options;
43
+ });
44
+ this.instance.interceptors.response.use((response) => {
45
+ const setCookie = response.headers['set-cookie'];
46
+ const requestUrl = response.request?.res?.responseUrl ?? response.config.url;
47
+ if (requestUrl && Array.isArray(setCookie))
48
+ this.jar.setCookies(setCookie, requestUrl);
49
+ return response;
50
+ });
51
+ }
52
+ async video(videoID) {
53
+ if (typeof videoID !== 'string' || !videoID.length)
54
+ throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
55
+ const uri = '/api/v2/page/get/video';
56
+ try {
57
+ if (this.jar.getCookies(Client.BASE_URL).length === 0)
58
+ await this.instance.get('/');
59
+ const response = await this.instance.get(uri, {
60
+ params: {
61
+ 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
+ ]
68
+ });
69
+ const body = response.data;
70
+ if (body.err !== 0)
71
+ throw new Lapse(body.msg, 'ERROR_VIDEO_NOT_FOUND');
72
+ const videoURL = body.data?.streaming?.hls?.['360p'];
73
+ if (!videoURL || !videoURL.length)
74
+ throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
75
+ const streamVideo = m3u8stream(videoURL);
76
+ streamVideo.once('error', (error) => {
77
+ const lapse = new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);
78
+ streamVideo.destroy(lapse);
79
+ });
80
+ return streamVideo;
81
+ }
82
+ catch (error) {
83
+ if (error instanceof Lapse)
84
+ throw error;
85
+ throw new Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
86
+ }
87
+ }
88
+ videoSyncLike(videoID) {
89
+ const video = new PassThrough({ highWaterMark: this.maxRate[1] });
90
+ void this.video(videoID)
91
+ .then((source) => {
92
+ source.once('error', (error) => {
93
+ const lapse = error instanceof Lapse ? error : new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);
94
+ video.destroy(lapse);
95
+ });
96
+ const destroy = () => {
97
+ if (!source.destroyed)
98
+ source.destroy();
99
+ };
100
+ video.once('close', destroy);
101
+ video.once('error', destroy);
102
+ source.pipe(video);
103
+ })
104
+ .catch((error) => {
105
+ if (error instanceof Lapse)
106
+ throw error;
107
+ throw new Lapse('Failed to fetch video stream', 'ERROR_VIDEO_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
108
+ });
109
+ return video;
110
+ }
111
+ async music(musicID) {
112
+ if (typeof musicID !== 'string' || !musicID.trim().length)
113
+ throw new Lapse('ID must be a non-empty string', 'ERROR_INVALID_ID');
114
+ const uri = '/api/v2/song/get/streaming';
115
+ try {
116
+ if (this.jar.getCookies(Client.BASE_URL).length === 0)
117
+ await this.instance.get('/');
118
+ const response = await this.instance.get(uri, {
119
+ params: {
120
+ 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
+ ]
127
+ });
128
+ 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];
132
+ if (!musicURL || !musicURL.length)
133
+ throw new Lapse('Streaming URL not found', 'ERROR_STREAM_URL_NOT_FOUND');
134
+ const streamMusic = await this.instance.get(musicURL, { responseType: 'stream' });
135
+ streamMusic.data.once('error', (error) => {
136
+ const lapse = new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', streamMusic.status, error);
137
+ streamMusic.data.destroy(lapse);
138
+ });
139
+ return streamMusic.data;
140
+ }
141
+ catch (error) {
142
+ if (error instanceof Lapse)
143
+ throw error;
144
+ throw new Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
145
+ }
146
+ }
147
+ musicSyncLike(musicID) {
148
+ const music = new PassThrough({ highWaterMark: this.maxRate[1] });
149
+ void this.music(musicID)
150
+ .then((source) => {
151
+ source.once('error', (error) => {
152
+ const lapse = error instanceof Lapse ? error : new Lapse('Stream download failed', 'ERROR_STREAM_DOWNLOAD', void 0, error);
153
+ music.destroy(lapse);
154
+ });
155
+ const destroy = () => {
156
+ if (!source.destroyed)
157
+ source.destroy();
158
+ };
159
+ music.once('close', destroy);
160
+ music.once('error', destroy);
161
+ source.pipe(music);
162
+ })
163
+ .catch((error) => {
164
+ if (error instanceof Lapse)
165
+ throw error;
166
+ throw new Lapse('Failed to fetch music stream', 'ERROR_MUSIC_FETCH', axios.isAxiosError(error) ? error.response?.status : void 0, error);
167
+ });
168
+ return music;
169
+ }
170
+ }
171
+ const clientOptions = {
172
+ maxRate: [
173
+ 100 * 1024,
174
+ 16 * 1024
175
+ ]
176
+ };
177
+ const client = new Client(clientOptions);
178
+ export { client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;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,MAAM,CAAC,aAAa,CAAC,CAAC;AAEzC,OAAO,EACH,MAAM,IAAI,OAAO,EACjB,MAAM,EACN,MAAM,EACT,CAAA"}
@@ -0,0 +1,247 @@
1
+ function normalizeDomain(domain) {
2
+ return domain.trim().toLowerCase().replace(/^\./, '');
3
+ }
4
+ function slash(pathname) {
5
+ if (!pathname || pathname[0] !== '/')
6
+ return '/';
7
+ if (pathname === '/')
8
+ return '/';
9
+ const lastSlash = pathname.lastIndexOf('/');
10
+ return lastSlash <= 0 ? '/' : pathname.slice(0, lastSlash);
11
+ }
12
+ function isExpired(cookie, time) {
13
+ return cookie.expiresAt !== undefined && cookie.expiresAt <= time;
14
+ }
15
+ function domainMatches(hostname, cookieDomain, hostOnly) {
16
+ const host = hostname.toLowerCase();
17
+ const domain = cookieDomain.toLowerCase();
18
+ if (hostOnly)
19
+ return host === domain;
20
+ return host === domain || host.endsWith('.' + domain);
21
+ }
22
+ function pathMatches(requestPath, cookiePath) {
23
+ if (requestPath === cookiePath)
24
+ return true;
25
+ if (!requestPath.startsWith(cookiePath))
26
+ return false;
27
+ if (cookiePath.endsWith('/'))
28
+ return true;
29
+ return requestPath[cookiePath.length] === '/';
30
+ }
31
+ function parseExpires(value) {
32
+ const time = Date.parse(value);
33
+ return Number.isNaN(time) ? undefined : time;
34
+ }
35
+ function stripQuotes(value) {
36
+ if (value.length >= 2 && value.startsWith('"') && value.endsWith('"'))
37
+ return value.slice(1, -1);
38
+ return value;
39
+ }
40
+ export class Cookies {
41
+ store = new Map();
42
+ setCookie(setCookie, requestUrl) {
43
+ const url = new URL(requestUrl);
44
+ const parts = setCookie.split(';').map((part) => part.trim()).filter(Boolean);
45
+ if (parts.length === 0)
46
+ return;
47
+ const [nameValue, ...attributes] = parts;
48
+ const equalsIndex = nameValue.indexOf('=');
49
+ if (equalsIndex <= 0)
50
+ return;
51
+ const name = nameValue.slice(0, equalsIndex).trim();
52
+ const value = stripQuotes(nameValue.slice(equalsIndex + 1).trim());
53
+ let domain = normalizeDomain(url.hostname);
54
+ let path = slash(url.pathname);
55
+ let expiresAt;
56
+ let secure = false;
57
+ let httpOnly = false;
58
+ let sameSite;
59
+ let hostOnly = true;
60
+ let maxAge;
61
+ for (const attribute of attributes) {
62
+ const [rawKey, ...rawRest] = attribute.split('=');
63
+ const key = rawKey.trim().toLowerCase();
64
+ const attrValue = rawRest.join('=').trim();
65
+ switch (key) {
66
+ case 'domain': {
67
+ if (!attrValue)
68
+ break;
69
+ const normalized = normalizeDomain(attrValue);
70
+ if (!normalized)
71
+ break;
72
+ domain = normalized;
73
+ hostOnly = false;
74
+ break;
75
+ }
76
+ case 'path': {
77
+ path = attrValue && attrValue.startsWith('/') ? attrValue : '/';
78
+ break;
79
+ }
80
+ case 'expires': {
81
+ const parsed = parseExpires(attrValue);
82
+ if (parsed !== undefined)
83
+ expiresAt = parsed;
84
+ break;
85
+ }
86
+ case 'max-age': {
87
+ const parsed = Number.parseInt(attrValue, 10);
88
+ if (!Number.isNaN(parsed))
89
+ maxAge = parsed;
90
+ break;
91
+ }
92
+ case 'secure': {
93
+ secure = true;
94
+ break;
95
+ }
96
+ case 'httponly': {
97
+ httpOnly = true;
98
+ break;
99
+ }
100
+ case 'samesite': {
101
+ const normalized = attrValue.toLowerCase();
102
+ if (normalized === 'strict')
103
+ sameSite = 'Strict';
104
+ else if (normalized === 'lax')
105
+ sameSite = 'Lax';
106
+ else if (normalized === 'none')
107
+ sameSite = 'None';
108
+ break;
109
+ }
110
+ default:
111
+ break;
112
+ }
113
+ }
114
+ if (!domainMatches(url.hostname, domain, hostOnly))
115
+ return;
116
+ if (maxAge !== undefined)
117
+ expiresAt = maxAge <= 0 ? 0 : Date.now() + maxAge * 1000;
118
+ const cookie = {
119
+ name,
120
+ value,
121
+ domain,
122
+ path,
123
+ expiresAt,
124
+ secure,
125
+ httpOnly,
126
+ sameSite,
127
+ hostOnly
128
+ };
129
+ if (isExpired(cookie, Date.now())) {
130
+ this.deleteCookie(cookie.domain, cookie.path, cookie.name);
131
+ return;
132
+ }
133
+ let byPath = this.store.get(cookie.domain);
134
+ if (!byPath) {
135
+ byPath = new Map();
136
+ this.store.set(cookie.domain, byPath);
137
+ }
138
+ let byName = byPath.get(cookie.path);
139
+ if (!byName) {
140
+ byName = new Map();
141
+ byPath.set(cookie.path, byName);
142
+ }
143
+ byName.set(cookie.name, cookie);
144
+ }
145
+ setCookies(setCookies, requestUrl) {
146
+ if (!setCookies?.length)
147
+ return;
148
+ for (const line of setCookies)
149
+ this.setCookie(line, requestUrl);
150
+ }
151
+ getCookies(requestUrl) {
152
+ const url = new URL(requestUrl);
153
+ const hostname = url.hostname.toLowerCase();
154
+ const pathname = url.pathname || '/';
155
+ const isHttps = url.protocol === 'https:';
156
+ const out = [];
157
+ for (const [, byPath] of this.store) {
158
+ for (const [, byName] of byPath) {
159
+ for (const [, cookie] of byName) {
160
+ if (isExpired(cookie, Date.now()))
161
+ continue;
162
+ if (cookie.secure && !isHttps)
163
+ continue;
164
+ if (!domainMatches(hostname, cookie.domain, cookie.hostOnly))
165
+ continue;
166
+ if (!pathMatches(pathname, cookie.path))
167
+ continue;
168
+ out.push(cookie);
169
+ }
170
+ }
171
+ }
172
+ out.sort((a, b) => b.path.length - a.path.length || a.name.localeCompare(b.name));
173
+ return out;
174
+ }
175
+ getCookieHeader(requestUrl) {
176
+ return this.getCookies(requestUrl)
177
+ .map(cookie => cookie.name + '=' + cookie.value)
178
+ .join('; ');
179
+ }
180
+ applyToHeaders(requestUrl, headers = {}) {
181
+ const cookie = this.getCookieHeader(requestUrl);
182
+ if (!cookie)
183
+ return headers;
184
+ return {
185
+ ...headers,
186
+ Cookie: cookie
187
+ };
188
+ }
189
+ deleteCookie(domain, path, name) {
190
+ const byPath = this.store.get(normalizeDomain(domain));
191
+ if (!byPath)
192
+ return;
193
+ const byName = byPath.get(path);
194
+ if (!byName)
195
+ return;
196
+ byName.delete(name);
197
+ if (byName.size === 0)
198
+ byPath.delete(path);
199
+ if (byPath.size === 0)
200
+ this.store.delete(normalizeDomain(domain));
201
+ }
202
+ cleanup() {
203
+ const time = Date.now();
204
+ for (const [domain, byPath] of this.store) {
205
+ for (const [path, byName] of byPath) {
206
+ for (const [name, cookie] of byName) {
207
+ if (isExpired(cookie, time))
208
+ byName.delete(name);
209
+ }
210
+ if (byName.size === 0)
211
+ byPath.delete(path);
212
+ }
213
+ if (byPath.size === 0)
214
+ this.store.delete(domain);
215
+ }
216
+ }
217
+ toJSON() {
218
+ this.cleanup();
219
+ const out = [];
220
+ for (const [, byPath] of this.store) {
221
+ for (const [, byName] of byPath) {
222
+ for (const [, cookie] of byName)
223
+ out.push({ ...cookie });
224
+ }
225
+ }
226
+ return out;
227
+ }
228
+ fromJSON(cookies) {
229
+ this.store.clear();
230
+ for (const cookie of cookies) {
231
+ if (isExpired(cookie, Date.now()))
232
+ continue;
233
+ let byPath = this.store.get(cookie.domain);
234
+ if (!byPath) {
235
+ byPath = new Map();
236
+ this.store.set(cookie.domain, byPath);
237
+ }
238
+ let byName = byPath.get(cookie.path);
239
+ if (!byName) {
240
+ byName = new Map();
241
+ byPath.set(cookie.path, byName);
242
+ }
243
+ byName.set(cookie.name, { ...cookie });
244
+ }
245
+ }
246
+ }
247
+ //# sourceMappingURL=cookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.js","sourceRoot":"source/","sources":["utils/cookies.ts"],"names":[],"mappings":"AAEA,SAAS,eAAe,CAAC,MAAc;IACnC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,KAAK,CAAC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AG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QAC3C,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,16 @@
1
+ import { createHash, createHmac } from 'node:crypto';
2
+ function createHash256(value) {
3
+ return createHash('sha256')
4
+ .update(value)
5
+ .digest('hex');
6
+ }
7
+ function createHmac512(value, secret) {
8
+ return createHmac('sha512', secret)
9
+ .update(Buffer.from(value, 'utf8'))
10
+ .digest('hex');
11
+ }
12
+ export function createSignature(uri, params, secret) {
13
+ const hash = createHash256(params);
14
+ return createHmac512(uri + hash, secret);
15
+ }
16
+ //# sourceMappingURL=encrypt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypt.js","sourceRoot":"source/","sources":["utils/encrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,SAAS,aAAa,CAAC,KAAa;IAChC,OAAO,UAAU,CAAC,QAAQ,CAAC;SACtB,MAAM,CAAC,KAAK,CAAC;SACb,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,aAAa,CAAC,KAAa,EAAE,MAAc;IAChD,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;SAC9B,MAAM,CACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAC7B;SACA,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,MAAc,EAAE,MAAc;IACvE,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO,aAAa,CAAC,GAAG,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,14 @@
1
+ export class Lapse extends Error {
2
+ code;
3
+ status;
4
+ cause;
5
+ constructor(message, code, status, cause) {
6
+ super(message);
7
+ this.name = 'ZING_MP3_ERROR';
8
+ this.code = code;
9
+ this.status = status;
10
+ this.cause = cause;
11
+ Object.setPrototypeOf(this, new.target.prototype);
12
+ }
13
+ }
14
+ //# sourceMappingURL=lapse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lapse.js","sourceRoot":"source/","sources":["utils/lapse.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAM,SAAQ,KAAK;IACZ,IAAI,CAAS;IACtB,MAAM,CAAU;IACP,KAAK,CAAW;IAEhC,YAAmB,OAAe,EAAE,IAAY,EAAE,MAAe,EAAE,KAAe;QAC9E,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACJ"}
@@ -0,0 +1,33 @@
1
+ import { Readable } from 'node:stream';
2
+
3
+ export declare class Client {
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 }
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 { }
@@ -0,0 +1,11 @@
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
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@khang07/zing-mp3-api",
3
+ "version": "1.0.0",
4
+ "author": "Khang <ngkhang9a5lqc11@gmail.com>",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/GiaKhang1810/zing-mp3-api.git"
8
+ },
9
+ "type": "module",
10
+ "main": "./dist/cjs/index.cjs",
11
+ "module": "./dist/esm/index.js",
12
+ "types": "./dist/types/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/types/index.d.ts",
16
+ "import": "./dist/esm/index.js",
17
+ "require": "./dist/cjs/index.cjs"
18
+ }
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/GiaKhang1810/zing-mp3-api/issues"
22
+ },
23
+ "description": "The basic APIs provide the features of ZingMp3.",
24
+ "homepage": "https://github.com/GiaKhang1810/zing-mp3-api#readme",
25
+ "keywords": [
26
+ "zingmp3",
27
+ "zing",
28
+ "mp3",
29
+ "zing-api",
30
+ "zing-mp3-api"
31
+ ],
32
+ "license": "MIT",
33
+ "scripts": {
34
+ "build:esm": "tsc -p tsconfig.json",
35
+ "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"
38
+ },
39
+ "devDependencies": {
40
+ "@microsoft/api-extractor": "^7.58.1",
41
+ "@types/node": "^25.5.2",
42
+ "rollup": "^4.60.1",
43
+ "typescript": "^6.0.2"
44
+ },
45
+ "dependencies": {
46
+ "axios": "^1.14.0",
47
+ "m3u8stream": "^0.8.6"
48
+ },
49
+ "files": [
50
+ "dist"
51
+ ]
52
+ }