migu-api-enhanced 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -96
- package/dist/index.cjs +163 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +157 -30
- package/dist/index.js.map +1 -1
- package/package.json +62 -62
package/dist/index.js
CHANGED
|
@@ -18,11 +18,12 @@ __export(modules_exports, {
|
|
|
18
18
|
getPacmToken: () => getPacmToken,
|
|
19
19
|
getPlaylistInfo: () => getPlaylistInfo,
|
|
20
20
|
getPlaylistSong: () => getPlaylistSong,
|
|
21
|
+
getRadioRecommend: () => getRadioRecommend,
|
|
21
22
|
getRankIndex: () => getRankIndex,
|
|
22
23
|
getRankInfo: () => getRankInfo,
|
|
23
24
|
getRecommendPlaylist: () => getRecommendPlaylist,
|
|
24
|
-
getRecommendSong: () => getRecommendSong,
|
|
25
25
|
getResourceInfo: () => getResourceInfo,
|
|
26
|
+
getSceneRecommend: () => getSceneRecommend,
|
|
26
27
|
getSearchDefault: () => getSearchDefault,
|
|
27
28
|
getSearchHot: () => getSearchHot,
|
|
28
29
|
getSearchSingerTab: () => getSearchSingerTab,
|
|
@@ -31,11 +32,15 @@ __export(modules_exports, {
|
|
|
31
32
|
getSingerIndex: () => getSingerIndex,
|
|
32
33
|
getSingerSong: () => getSingerSong,
|
|
33
34
|
getTicketInfo: () => getTicketInfo,
|
|
35
|
+
getTodayRecommend: () => getTodayRecommend,
|
|
34
36
|
getUrlH5V24: () => getUrlH5V24,
|
|
35
37
|
getUrlV1: () => getUrlV1,
|
|
36
38
|
getUrlV2: () => getUrlV2,
|
|
39
|
+
getUserBadge: () => getUserBadge,
|
|
40
|
+
getUserHomePage: () => getUserHomePage,
|
|
37
41
|
getVersion: () => getVersion,
|
|
38
42
|
loginNP: () => loginNP,
|
|
43
|
+
queryUserInfo: () => queryUserInfo,
|
|
39
44
|
searchAlbum: () => searchAlbum,
|
|
40
45
|
searchConcert: () => searchConcert,
|
|
41
46
|
searchRbt: () => searchRbt,
|
|
@@ -178,9 +183,50 @@ var getRecommendPlaylist = async () => {
|
|
|
178
183
|
return await h5fetch(`http://app.c.nf.migu.cn/bmw/index-show/recommend-playlist/v3.0`);
|
|
179
184
|
};
|
|
180
185
|
|
|
186
|
+
// src/utils/deviceID.ts
|
|
187
|
+
function getDeviceId() {
|
|
188
|
+
const random = Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
|
|
189
|
+
const a = `${random.substring(0, 8)}-${random.substring(8, 12)}-${random.substring(12, 16)}-${random.substring(16, 20)}-${random.substring(20)}`;
|
|
190
|
+
return a.toUpperCase();
|
|
191
|
+
}
|
|
192
|
+
|
|
181
193
|
// src/modules/recommend_song.ts
|
|
182
|
-
var
|
|
183
|
-
|
|
194
|
+
var getSceneRecommend = async (scene = "TODAY_RECOMMEND", size = 10) => {
|
|
195
|
+
let params = "";
|
|
196
|
+
if (scene === "PRIVATE_FM") {
|
|
197
|
+
params = "scene=PRIVATE_FM&algorithm=v1&action=1";
|
|
198
|
+
} else if (scene === "TODAY_RECOMMEND") {
|
|
199
|
+
params = `scene=TODAY_RECOMMEND&action=1&size=${size}`;
|
|
200
|
+
} else {
|
|
201
|
+
return { error: "scene\u53C2\u6570\u9519\u8BEF" };
|
|
202
|
+
}
|
|
203
|
+
return await h5fetch(
|
|
204
|
+
`https://app.c.nf.migu.cn/pc/resource-dataloader/recommend-song/v1.0?${params}`,
|
|
205
|
+
{
|
|
206
|
+
headers: {
|
|
207
|
+
"deviceId": getDeviceId()
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/modules/recommend_radio.ts
|
|
214
|
+
var getRadioRecommend = async (type = 1) => {
|
|
215
|
+
if (type !== 1 && type !== 2) {
|
|
216
|
+
return { error: "type must be 1 or 2" };
|
|
217
|
+
}
|
|
218
|
+
return await h5fetch(
|
|
219
|
+
`https://app.c.nf.migu.cn/pc/column/music-radio/recommend/song/v2.0?remain=0&actionId=1&type=${type}`,
|
|
220
|
+
{
|
|
221
|
+
method: "GET",
|
|
222
|
+
headers: {
|
|
223
|
+
"Referer": "https://music.migu.cn/",
|
|
224
|
+
"channel": "014X031",
|
|
225
|
+
"deviceId": getDeviceId(),
|
|
226
|
+
"recommendstatus": "1"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
);
|
|
184
230
|
};
|
|
185
231
|
|
|
186
232
|
// src/modules/comment.ts
|
|
@@ -224,13 +270,6 @@ var getUrlV1 = async (contentId, copyrightId, resourceType = "2") => {
|
|
|
224
270
|
);
|
|
225
271
|
};
|
|
226
272
|
|
|
227
|
-
// src/utils/deviceID.ts
|
|
228
|
-
function getDeviceId() {
|
|
229
|
-
const random = Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
|
|
230
|
-
const a = `${random.substring(0, 8)}-${random.substring(8, 12)}-${random.substring(12, 16)}-${random.substring(16, 20)}-${random.substring(20)}`;
|
|
231
|
-
return a.toUpperCase();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
273
|
// src/modules/url_v2.ts
|
|
235
274
|
var getUrlV2 = async (contentId, copyrightId, resourceType = "2", pacmtoken = "") => {
|
|
236
275
|
const deviceId = getDeviceId();
|
|
@@ -937,6 +976,32 @@ var checkToken = async (token = "") => {
|
|
|
937
976
|
);
|
|
938
977
|
};
|
|
939
978
|
|
|
979
|
+
// src/utils/setCookie.ts
|
|
980
|
+
var parseSetCookies = (headers) => {
|
|
981
|
+
if (typeof headers.getSetCookie === "function") {
|
|
982
|
+
return headers.getSetCookie() || [];
|
|
983
|
+
}
|
|
984
|
+
const setCookieHeader = headers.get("set-cookie");
|
|
985
|
+
if (!setCookieHeader) {
|
|
986
|
+
return [];
|
|
987
|
+
}
|
|
988
|
+
return setCookieHeader.split(",").map((c) => c.trim());
|
|
989
|
+
};
|
|
990
|
+
var getCookieValue = (cookies, key) => {
|
|
991
|
+
for (const item of cookies) {
|
|
992
|
+
const prefix = `${key}=`;
|
|
993
|
+
if (item.includes(prefix)) {
|
|
994
|
+
const mainPart = item.split(";")[0];
|
|
995
|
+
return mainPart.split("=")[1] || "";
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return "";
|
|
999
|
+
};
|
|
1000
|
+
var getSetCookieValue = (headers, key) => {
|
|
1001
|
+
const cookies = parseSetCookies(headers);
|
|
1002
|
+
return getCookieValue(cookies, key);
|
|
1003
|
+
};
|
|
1004
|
+
|
|
940
1005
|
// src/modules/passport_pacmToken.ts
|
|
941
1006
|
var getPacmToken = async (token = "", type = "2", sourceId = "220029", activityId = "MUSIC-WWW") => {
|
|
942
1007
|
const res = await fetch(
|
|
@@ -944,7 +1009,6 @@ var getPacmToken = async (token = "", type = "2", sourceId = "220029", activityI
|
|
|
944
1009
|
{
|
|
945
1010
|
headers: {
|
|
946
1011
|
"Cookie": "idmpauth=true@passport.migu.cn",
|
|
947
|
-
//?
|
|
948
1012
|
"Origin": "https://music.migu.cn",
|
|
949
1013
|
"Pragma": "no-cache",
|
|
950
1014
|
"Referer": "https://music.migu.cn/"
|
|
@@ -952,24 +1016,8 @@ var getPacmToken = async (token = "", type = "2", sourceId = "220029", activityI
|
|
|
952
1016
|
method: "GET"
|
|
953
1017
|
}
|
|
954
1018
|
);
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
if (typeof headers.getSetCookie === "function") {
|
|
958
|
-
cookie = headers.getSetCookie() || [];
|
|
959
|
-
} else {
|
|
960
|
-
const setCookieHeader = headers.get("set-cookie");
|
|
961
|
-
if (setCookieHeader) {
|
|
962
|
-
cookie = setCookieHeader.split(",").map((c) => c.trim());
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
let pacmToken = "";
|
|
966
|
-
cookie.forEach((item) => {
|
|
967
|
-
if (item.includes("pacmtoken=")) {
|
|
968
|
-
pacmToken = item.split(";")[0];
|
|
969
|
-
pacmToken = pacmToken.split("=")[1];
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
});
|
|
1019
|
+
const cookie = parseSetCookies(res.headers);
|
|
1020
|
+
const pacmToken = getCookieValue(cookie, "pacmtoken");
|
|
973
1021
|
const body = await res.json();
|
|
974
1022
|
return { pacmToken, cookie, body };
|
|
975
1023
|
};
|
|
@@ -979,6 +1027,80 @@ var getTicketInfo = async (page = 1, pageCount = 20) => {
|
|
|
979
1027
|
return await h5fetch(`https://app.c.nf.migu.cn/MIGUM3.0/v1.0/ticket/home/ticket?pageNum=${page}&pageCount=${pageCount}`);
|
|
980
1028
|
};
|
|
981
1029
|
|
|
1030
|
+
// src/modules/user_badge.ts
|
|
1031
|
+
var getUserBadge = async (pacmtoken) => {
|
|
1032
|
+
const res = await fetch(
|
|
1033
|
+
`https://app.c.nf.migu.cn/pc/open/api/member/icon/v1.0`,
|
|
1034
|
+
{
|
|
1035
|
+
method: "GET",
|
|
1036
|
+
headers: {
|
|
1037
|
+
"Cookie": `pacmtoken=${pacmtoken}`,
|
|
1038
|
+
"Referer": "https://music.migu.cn/",
|
|
1039
|
+
"channel": "014X031",
|
|
1040
|
+
"timestamp": Date.now().toString()
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
);
|
|
1044
|
+
const newPacmToken = getSetCookieValue(res.headers, "pacmtoken");
|
|
1045
|
+
const data = await res.json();
|
|
1046
|
+
return { data, pacmtoken: newPacmToken };
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
// src/modules/user_queryInfo.ts
|
|
1050
|
+
var queryUserInfo = async (pacmtoken) => {
|
|
1051
|
+
const res = await fetch(
|
|
1052
|
+
`https://app.c.nf.migu.cn/pc/user/h5/queryUserInfo/v1.0`,
|
|
1053
|
+
{
|
|
1054
|
+
method: "GET",
|
|
1055
|
+
headers: {
|
|
1056
|
+
"Cookie": `pacmtoken=${pacmtoken}`,
|
|
1057
|
+
"channel": "014X031",
|
|
1058
|
+
"Referer": `https://music.migu.cn/`
|
|
1059
|
+
//可不用
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
);
|
|
1063
|
+
const newPacmToken = getSetCookieValue(res.headers, "pacmtoken");
|
|
1064
|
+
const data = await res.json();
|
|
1065
|
+
return { data, pacmtoken: newPacmToken };
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
// src/modules/user_homePage.ts
|
|
1069
|
+
var getUserHomePage = async (pacmtoken) => {
|
|
1070
|
+
const res = await fetch(
|
|
1071
|
+
`https://app.c.nf.migu.cn/pc/user/home-page/v2.0`,
|
|
1072
|
+
{
|
|
1073
|
+
method: "GET",
|
|
1074
|
+
headers: {
|
|
1075
|
+
"Cookie": `pacmtoken=${pacmtoken}`
|
|
1076
|
+
//"channel": "014X031",
|
|
1077
|
+
//"Referer": `https://music.migu.cn/`
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
);
|
|
1081
|
+
const newPacmToken = getSetCookieValue(res.headers, "pacmtoken");
|
|
1082
|
+
const data = await res.json();
|
|
1083
|
+
return { data, pacmtoken: newPacmToken };
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
// src/modules/user_recom_today.ts
|
|
1087
|
+
var getTodayRecommend = async (pacmtoken) => {
|
|
1088
|
+
const res = await fetch(
|
|
1089
|
+
`https://app.c.nf.migu.cn/pc/v1.0/template/todayRecommendList/release?actionId=1&index=1&templateVersion=5`,
|
|
1090
|
+
{
|
|
1091
|
+
method: "GET",
|
|
1092
|
+
headers: {
|
|
1093
|
+
"Cookie": `pacmtoken=${pacmtoken}`
|
|
1094
|
+
//"channel": "014X031",
|
|
1095
|
+
//"Referer": `https://music.migu.cn/`
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
);
|
|
1099
|
+
const newPacmToken = getSetCookieValue(res.headers, "pacmtoken");
|
|
1100
|
+
const data = await res.json();
|
|
1101
|
+
return { data, pacmtoken: newPacmToken };
|
|
1102
|
+
};
|
|
1103
|
+
|
|
982
1104
|
// src/index.ts
|
|
983
1105
|
function createClient() {
|
|
984
1106
|
return modules_exports;
|
|
@@ -996,11 +1118,12 @@ export {
|
|
|
996
1118
|
getPacmToken,
|
|
997
1119
|
getPlaylistInfo,
|
|
998
1120
|
getPlaylistSong,
|
|
1121
|
+
getRadioRecommend,
|
|
999
1122
|
getRankIndex,
|
|
1000
1123
|
getRankInfo,
|
|
1001
1124
|
getRecommendPlaylist,
|
|
1002
|
-
getRecommendSong,
|
|
1003
1125
|
getResourceInfo,
|
|
1126
|
+
getSceneRecommend,
|
|
1004
1127
|
getSearchDefault,
|
|
1005
1128
|
getSearchHot,
|
|
1006
1129
|
getSearchSingerTab,
|
|
@@ -1009,12 +1132,16 @@ export {
|
|
|
1009
1132
|
getSingerIndex,
|
|
1010
1133
|
getSingerSong,
|
|
1011
1134
|
getTicketInfo,
|
|
1135
|
+
getTodayRecommend,
|
|
1012
1136
|
getUrlH5V24,
|
|
1013
1137
|
getUrlV1,
|
|
1014
1138
|
getUrlV2,
|
|
1139
|
+
getUserBadge,
|
|
1140
|
+
getUserHomePage,
|
|
1015
1141
|
getVersion,
|
|
1016
1142
|
loginNP,
|
|
1017
1143
|
modules_exports as modules,
|
|
1144
|
+
queryUserInfo,
|
|
1018
1145
|
searchAlbum,
|
|
1019
1146
|
searchConcert,
|
|
1020
1147
|
searchRbt,
|