migu-api-enhanced 1.2.4 → 1.2.5

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/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ YDRZ: () => YDRZ,
33
34
  checkCanListen: () => checkCanListen,
34
35
  checkToken: () => checkToken,
35
36
  createClient: () => createClient,
@@ -68,6 +69,7 @@ __export(index_exports, {
68
69
  getUserMyList: () => getUserMyList,
69
70
  getVersion: () => getVersion,
70
71
  loginNP: () => loginNP,
72
+ loginOneClick: () => loginOneClick,
71
73
  loginSim: () => loginSim,
72
74
  modules: () => modules_exports,
73
75
  queryUserInfo: () => queryUserInfo,
@@ -85,6 +87,7 @@ module.exports = __toCommonJS(index_exports);
85
87
  // src/modules/index.ts
86
88
  var modules_exports = {};
87
89
  __export(modules_exports, {
90
+ YDRZ: () => YDRZ,
88
91
  checkCanListen: () => checkCanListen,
89
92
  checkToken: () => checkToken,
90
93
  getAlbumInfo: () => getAlbumInfo,
@@ -122,6 +125,7 @@ __export(modules_exports, {
122
125
  getUserMyList: () => getUserMyList,
123
126
  getVersion: () => getVersion,
124
127
  loginNP: () => loginNP,
128
+ loginOneClick: () => loginOneClick,
125
129
  loginSim: () => loginSim,
126
130
  queryUserInfo: () => queryUserInfo,
127
131
  searchAlbum: () => searchAlbum,
@@ -267,10 +271,17 @@ var getRecommendPlaylist = async () => {
267
271
  };
268
272
 
269
273
  // src/utils/deviceID.ts
270
- function getDeviceId() {
271
- const random = Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
272
- const a = `${random.substring(0, 8)}-${random.substring(8, 12)}-${random.substring(12, 16)}-${random.substring(16, 20)}-${random.substring(20)}`;
273
- return a.toUpperCase();
274
+ function getDeviceId(a, b) {
275
+ var c, d = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), e = [];
276
+ if (b = b || d.length, a)
277
+ for (c = 0; a > c; c++)
278
+ e[c] = d[0 | Math.random() * b];
279
+ else {
280
+ var f;
281
+ for (e[8] = e[13] = e[18] = e[23] = "-", e[14] = "4", c = 0; 36 > c; c++)
282
+ e[c] || (f = 0 | 16 * Math.random(), e[c] = d[19 == c ? 3 & f | 8 : f]);
283
+ }
284
+ return e.join("");
274
285
  }
275
286
 
276
287
  // src/modules/recommend_song.ts
@@ -376,7 +387,9 @@ var getUrlV2 = async (contentId, copyrightId, resourceType = "2", pacmtoken = ""
376
387
  "timestamp": timestamp.toString(),
377
388
  "Content-Type": "application/json;charset=UTF-8",
378
389
  "referer": "https://music.migu.cn/",
379
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0"
390
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0",
391
+ "location-data": "30.6698676660,104.1229614820",
392
+ "location-info": ""
380
393
  };
381
394
  const res = await fetch(
382
395
  `https://app.c.nf.migu.cn/strategy/pc/listen/v2.0?contentId=${contentId}&copyrightId=${copyrightId}&scene=&netType=01&resourceType=${resourceType}&toneFlag=PQ`,
@@ -428,7 +441,9 @@ var getUrlH5V24 = async (contentId, copyrightId, resourceType = "2") => {
428
441
  const headers = {
429
442
  "birth": "h5page",
430
443
  "channel": "014X031",
431
- "Referer": "https://y.migu.cn/"
444
+ "Referer": "https://y.migu.cn/",
445
+ "location-data": "30.6698676660,104.1229614820",
446
+ "location-info": ""
432
447
  };
433
448
  const res = await fetch(
434
449
  `https://c.musicapp.migu.cn/strategy/listen-url/h5/v2.4?contentId=${contentId}&copyrightId=${copyrightId}&resourceType=${resourceType}&netType=01&toneFlag=PQ&scene=&lowerQualityContentId=${contentId}`,
@@ -502,30 +517,8 @@ var getVersion = async (channel = "0146921", version = "8.4.0", ua = "Android_mi
502
517
  };
503
518
 
504
519
  // src/modules/mv_info.ts
505
- var getMvInfo = async (mvIds, {
506
- needAbsoluteUrl = false
507
- }) => {
508
- const res = await h5fetch(`https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceId=${mvIds}&resourceType=D&needSimple=01`);
509
- if (!res) return { error: "\u8BF7\u6C42\u5931\u8D25" };
510
- if (res.error) return { error: res.error };
511
- const resource = res.resource || [];
512
- if (resource.length === 0) return { error: "resource\u4E0D\u5B58\u5728" };
513
- if (needAbsoluteUrl) {
514
- resource.forEach((item) => {
515
- if (!item.rateFormats) return;
516
- item.rateFormats.forEach((rateFormat) => {
517
- if (!rateFormat.url) return;
518
- if (!rateFormat.url.startsWith("http") && !rateFormat.url.startsWith("https")) {
519
- if (rateFormat.url[0] === "/" && rateFormat.url[1] !== "/") {
520
- rateFormat.absoluteUrl = `https://freevod.nf.migu.cn${rateFormat.url}`;
521
- }
522
- }
523
- });
524
- });
525
- res.resource = resource;
526
- return res;
527
- }
528
- return res;
520
+ var getMvInfo = async (mvIds) => {
521
+ return h5fetch(`https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceId=${mvIds}&resourceType=D&needSimple=01`);
529
522
  };
530
523
 
531
524
  // src/modules/mv_hls.ts
@@ -990,6 +983,15 @@ var getPublicKey = async () => {
990
983
  return { publicExponent, modulus };
991
984
  };
992
985
 
986
+ // src/utils/URLParams.ts
987
+ function URLParams($) {
988
+ const form = new URLSearchParams();
989
+ for (const [key, value] of Object.entries($)) {
990
+ form.append(key, String(value));
991
+ }
992
+ return form.toString();
993
+ }
994
+
993
995
  // src/modules/login_np.ts
994
996
  var RSAKey = rsalib_default.RSAKey;
995
997
  function randomString() {
@@ -997,8 +999,13 @@ function randomString() {
997
999
  return random.toLowerCase();
998
1000
  }
999
1001
  var loginNP = {
1002
+ /**
1003
+ * 账号密码登录
1004
+ * @param username 用户名
1005
+ * @param password 密码
1006
+ * @returns 登录成功后的 pacmtoken
1007
+ */
1000
1008
  async authn(username, password) {
1001
- var error = "";
1002
1009
  var $ = {
1003
1010
  "isAsync": true,
1004
1011
  "enpassword": "",
@@ -1014,8 +1021,7 @@ var loginNP = {
1014
1021
  const p = await getPublicKey();
1015
1022
  const { publicExponent, modulus } = p || {};
1016
1023
  if (!modulus || !publicExponent) {
1017
- error = "\u83B7\u53D6\u516C\u94A5\u5931\u8D25";
1018
- return { error };
1024
+ return { error: "\u83B7\u53D6\u516C\u94A5\u5931\u8D25" };
1019
1025
  }
1020
1026
  var rsa2 = new RSAKey();
1021
1027
  rsa2.setPublic(modulus, publicExponent);
@@ -1026,10 +1032,7 @@ var loginNP = {
1026
1032
  $.fingerPrintDetail = fakeFingerprint;
1027
1033
  $.enpassword = rsa_pwd;
1028
1034
  $.loginID = rsa_username;
1029
- const form = new URLSearchParams();
1030
- for (const [key, value] of Object.entries($)) {
1031
- form.append(key, String(value));
1032
- }
1035
+ const form = URLParams($);
1033
1036
  const res = await fetch(
1034
1037
  `https://passport.migu.cn/authn`,
1035
1038
  {
@@ -1040,7 +1043,7 @@ var loginNP = {
1040
1043
  body: form
1041
1044
  }
1042
1045
  );
1043
- if (!res.ok) return { error: ["\u8BF7\u6C42\u767B\u5F55\u5931\u8D25"] };
1046
+ if (!res.ok) return { error: "\u8BF7\u6C42\u767B\u5F55\u5931\u8D25" };
1044
1047
  const body = await res.json();
1045
1048
  return body;
1046
1049
  }
@@ -1214,10 +1217,7 @@ var loginSim = {
1214
1217
  $.fingerPrint = fakeFingerprint;
1215
1218
  $.fingerPrintDetail = fakeFingerprint;
1216
1219
  $.encMsisdn = encPhone;
1217
- const form = new URLSearchParams();
1218
- for (const [key, value] of Object.entries($)) {
1219
- form.append(key, String(value));
1220
- }
1220
+ const form = URLParams($);
1221
1221
  const send = await fetch(
1222
1222
  `https://passport.migu.cn/api/simauth/send`,
1223
1223
  {
@@ -1322,12 +1322,204 @@ var getSimilarSongRecommend = async (contentId = "") => {
1322
1322
  );
1323
1323
  };
1324
1324
 
1325
+ // src/modules/login_oneclick.ts
1326
+ var import_crypto2 = __toESM(require("crypto"), 1);
1327
+ var nav = {
1328
+ "platform": "iPhone",
1329
+ "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Mobile/15E148 Safari/604.1",
1330
+ "appVersion": "5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Mobile/15E148 Safari/604.1",
1331
+ "cookieEnabled": true,
1332
+ "empty": null,
1333
+ "hardwareConcurrency": 6,
1334
+ "language": "zh-CN",
1335
+ "plugins": "",
1336
+ "availWidth": 390,
1337
+ "availHeight": 844,
1338
+ "colorDepth": 24,
1339
+ "timezoneOffset": -480
1340
+ };
1341
+ var YDRZ = {
1342
+ "optparams": {
1343
+ "uuid": "",
1344
+ "msgId": "",
1345
+ "traceId": "",
1346
+ "businessType": "10",
1347
+ "appId": "",
1348
+ "timestamp": yTime(),
1349
+ "isimge": false,
1350
+ "expandParams": "",
1351
+ "userInformations": "",
1352
+ "CMRequestApi": ""
1353
+ },
1354
+ randomString(len, range = 32) {
1355
+ var i, bite = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), list = [];
1356
+ for (i = 0; i < len; i++)
1357
+ list[i] = bite[0 | Math.random() * range];
1358
+ return list.join("");
1359
+ },
1360
+ randomRange(min, max) {
1361
+ return Math.floor(Math.random() * (min - max) + max);
1362
+ },
1363
+ getUA() {
1364
+ const ua = nav.userAgent, l = [
1365
+ nav.platform,
1366
+ ua,
1367
+ nav.appVersion,
1368
+ nav.cookieEnabled,
1369
+ void 0,
1370
+ nav.hardwareConcurrency,
1371
+ nav.language,
1372
+ nav.plugins,
1373
+ nav.availWidth,
1374
+ nav.availHeight,
1375
+ nav.colorDepth,
1376
+ nav.timezoneOffset
1377
+ ], key = l.join("@@"), finalUA = ua.length > 100 ? ua.substring(0, 100) : ua;
1378
+ return nav.platform + "@@" + finalUA + "@@" + md5(key);
1379
+ },
1380
+ uaE(str) {
1381
+ var b, c, d, r4, r1, r2, r3, result = "", bite = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", i = 0;
1382
+ for (; i < str.length; )
1383
+ r4 = (b = str.charCodeAt(i++)) >> 2, r1 = (3 & b) << 4 | (c = str.charCodeAt(i++)) >> 4, r2 = (15 & c) << 2 | (d = str.charCodeAt(i++)) >> 6, r3 = 63 & d, isNaN(c) ? r2 = r3 = 64 : isNaN(d) && (r3 = 64), result = result + bite.charAt(r4) + bite.charAt(r1) + bite.charAt(r2) + bite.charAt(r3);
1384
+ return result;
1385
+ },
1386
+ getUserInfo() {
1387
+ return encodeURIComponent(this.uaE(this.getUA()));
1388
+ },
1389
+ getSign(appID, version) {
1390
+ const optparams = this.optparams;
1391
+ optparams.uuid = this.randomString(32, 32);
1392
+ optparams.msgId = this.randomString(32, 32);
1393
+ this.optparams = optparams;
1394
+ return appID + optparams.msgId + optparams.timestamp + optparams.uuid + version;
1395
+ },
1396
+ async getTokenInfo(data) {
1397
+ const optparams = this.optparams;
1398
+ const requestData = {
1399
+ "version": data.version,
1400
+ "appId": data.appId,
1401
+ "openType": data.openType,
1402
+ "expandParams": data.expandParams,
1403
+ "isTest": data.isTest,
1404
+ "sign": data.sign,
1405
+ "getNetworkType": data.getNetworkType,
1406
+ "getMsisdnMask": data.getMsisdnMask,
1407
+ "traceId": optparams.uuid,
1408
+ "msgId": optparams.msgId,
1409
+ "timestamp": optparams.timestamp,
1410
+ "uuid": optparams.uuid,
1411
+ "businessType": optparams.businessType,
1412
+ "userInformations": this.getUserInfo()
1413
+ };
1414
+ const res = await fetch(
1415
+ "https://verify.cmpassport.com/h5/getPreMobile",
1416
+ {
1417
+ method: "POST",
1418
+ headers: {
1419
+ "Referer": "https://passport.migu.cn/",
1420
+ "Origin": "https://passport.migu.cn"
1421
+ },
1422
+ body: JSON.stringify(requestData)
1423
+ }
1424
+ );
1425
+ if (!res.ok) return;
1426
+ const json = await res.json(), token = json.body?.token || "";
1427
+ if (!token) return;
1428
+ return token;
1429
+ }
1430
+ };
1431
+ function yTime() {
1432
+ const date = /* @__PURE__ */ new Date(), a = [
1433
+ date.getFullYear(),
1434
+ date.getMonth() + 1,
1435
+ date.getDate(),
1436
+ date.getHours(),
1437
+ date.getMinutes(),
1438
+ date.getSeconds(),
1439
+ date.getMilliseconds()
1440
+ ];
1441
+ const f = a.map((t) => {
1442
+ return t.toString().padStart(2, "0");
1443
+ });
1444
+ f[6] = f[6].toString().padStart(3, "0");
1445
+ return f.join("");
1446
+ }
1447
+ function md5(s) {
1448
+ return import_crypto2.default.createHash("md5").update(s, "utf-8").digest("hex");
1449
+ }
1450
+ var genInternetSign = async () => {
1451
+ const time = yTime(), e = time, c = "220029", msgId = getDeviceId(), d = msgId;
1452
+ const preSign = YDRZ.getSign("300012033963", "1.2"), b = preSign;
1453
+ let key = "interfacename=genInternetSign&sourceid=" + c + "&systemtime=" + e + "&msgid=" + d + "&preSign=" + b;
1454
+ key = encodeURIComponent(key);
1455
+ const signature = md5(key);
1456
+ const url = `https://passport.migu.cn/api/genInternetSign?preSign=${preSign}&msgid=${msgId}&systemtime=${time}&sourceid=220029&signature=${signature}`;
1457
+ const res = await fetch(url);
1458
+ if (!res.ok) return void 0;
1459
+ const data = await res.json();
1460
+ if (!data || data.status !== 2e3) return void 0;
1461
+ const rsaSign = data.result?.rsaSign || "";
1462
+ return rsaSign;
1463
+ };
1464
+ var getSTToken = async (uniToken) => {
1465
+ const $ = {
1466
+ "sourceID": "220029",
1467
+ "appType": 0,
1468
+ "relayState": "",
1469
+ "token": uniToken,
1470
+ "userInformation": YDRZ.getUserInfo(),
1471
+ "isFirst": 1
1472
+ };
1473
+ const form = URLParams($);
1474
+ const res = await fetch(
1475
+ "https://passport.migu.cn/authn/uniTokenValidate",
1476
+ {
1477
+ method: "POST",
1478
+ headers: {
1479
+ "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
1480
+ },
1481
+ body: form
1482
+ }
1483
+ );
1484
+ if (!res.ok) return { error: "fetch uni e" };
1485
+ const json = await res.json(), status = json.status?.toString() || "", token = json.result?.token || "", msisdn = json.result?.msisdn || "";
1486
+ if (status !== "2000") return { error: "status e" };
1487
+ return { token, msisdn, status };
1488
+ };
1489
+ var authn = async () => {
1490
+ const rsaSign = await genInternetSign();
1491
+ if (!rsaSign) return { error: "genInternetSign failed" };
1492
+ const uniToken = await YDRZ.getTokenInfo({
1493
+ version: "1.2",
1494
+ appId: "300012033963",
1495
+ sign: rsaSign,
1496
+ openType: "1",
1497
+ expandParams: "",
1498
+ isTest: false,
1499
+ getNetworkType: "",
1500
+ getMsisdnMask: ""
1501
+ });
1502
+ if (!uniToken) return { error: "getTokenInfo failed" };
1503
+ const result = await getSTToken(uniToken);
1504
+ if ("error" in result) return result;
1505
+ const { token, msisdn, status } = result;
1506
+ if (!token) return { error: "no token" };
1507
+ if (!msisdn) return { error: "no msisdn" };
1508
+ return { token, msisdn, status };
1509
+ };
1510
+ var loginOneClick = {
1511
+ genInternetSign,
1512
+ getSTToken,
1513
+ authn
1514
+ };
1515
+
1325
1516
  // src/index.ts
1326
1517
  function createClient() {
1327
1518
  return modules_exports;
1328
1519
  }
1329
1520
  // Annotate the CommonJS export names for ESM import in node:
1330
1521
  0 && (module.exports = {
1522
+ YDRZ,
1331
1523
  checkCanListen,
1332
1524
  checkToken,
1333
1525
  createClient,
@@ -1366,6 +1558,7 @@ function createClient() {
1366
1558
  getUserMyList,
1367
1559
  getVersion,
1368
1560
  loginNP,
1561
+ loginOneClick,
1369
1562
  loginSim,
1370
1563
  modules,
1371
1564
  queryUserInfo,