migu-api-enhanced 2.25.0 → 2.27.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/dist/index.js CHANGED
@@ -34,6 +34,9 @@ __export(modules_exports, {
34
34
  getConcertInfo: () => getConcertInfo,
35
35
  getConcertRecommendMv: () => getConcertRecommendMv,
36
36
  getConcertUrl: () => getConcertUrl,
37
+ getDAlbumInfo: () => getDAlbumInfo,
38
+ getDAlbumPay: () => getDAlbumPay,
39
+ getDAlbumSong: () => getDAlbumSong,
37
40
  getDLUrlV1: () => getDLUrlV1,
38
41
  getEmojiNum: () => getEmojiNum,
39
42
  getFollowerList: () => getFollowerList,
@@ -329,8 +332,10 @@ var getSingerSong = async (singerId, page = 1) => {
329
332
  };
330
333
 
331
334
  // src/modules/singer_album.ts
332
- var getSingerAlbum = async (singerId) => {
333
- return await h5fetch(`http://app.c.nf.migu.cn/bmw/singer/album/v1.0?singerId=${singerId}`);
335
+ var getSingerAlbum = async (singerId, page = 1) => {
336
+ const res = await h5fetch(`http://app.c.nf.migu.cn/bmw/singer/album/v1.0?singerId=${singerId}&pageNo=${page}`);
337
+ res?.data?.header?.nextPageUrl ? res.data.header.hasNext = true : res.data.header.hasNext = false;
338
+ return res;
334
339
  };
335
340
 
336
341
  // src/modules/rank_index.ts
@@ -1363,31 +1368,236 @@ var getVrbtUrl = async (contentIds) => {
1363
1368
 
1364
1369
  // src/modules/lyric.ts
1365
1370
  import axios8 from "axios";
1366
- var getLyric = async (contentId) => {
1371
+
1372
+ // src/utils/decryptMrc.ts
1373
+ var DELTA = 2654435769n;
1374
+ var MIN_LENGTH = 32;
1375
+ var SPECIAL_CHAR = 48;
1376
+ function toLong(num) {
1377
+ const MAX = 9223372036854775807n;
1378
+ const MIN = -9223372036854775808n;
1379
+ if (num > MAX) return toLong(num - (1n << 64n));
1380
+ if (num < MIN) return toLong(num + (1n << 64n));
1381
+ return num;
1382
+ }
1383
+ function ToByteArray(data) {
1384
+ const arrayList = [];
1385
+ for (const j2 of data) {
1386
+ const bArrLong2bytes = long2bytes(j2);
1387
+ for (let i = 0; i < 8; i++) {
1388
+ arrayList.push(bArrLong2bytes[i]);
1389
+ }
1390
+ }
1391
+ while (arrayList[arrayList.length - 1] === SPECIAL_CHAR) {
1392
+ arrayList.pop();
1393
+ }
1394
+ return Buffer.from(arrayList);
1395
+ }
1396
+ function long2bytes(num) {
1397
+ const byteBufferOrder = Buffer.alloc(8);
1398
+ byteBufferOrder.writeBigInt64LE(num, 0);
1399
+ return byteBufferOrder;
1400
+ }
1401
+ function PadRight(source, length) {
1402
+ let result = source;
1403
+ while (result.length < length) {
1404
+ result += "0";
1405
+ }
1406
+ return result;
1407
+ }
1408
+ function ToLongArray(data) {
1409
+ const length = Math.floor(data.length / 16);
1410
+ const jArr = new Array(length);
1411
+ for (let i = 0; i < length; i++) {
1412
+ jArr[i] = toLong(BigInt("0x" + data.substring(i * 16, i * 16 + 16)));
1413
+ }
1414
+ return jArr;
1415
+ }
1416
+ function bytes2long(buf, index) {
1417
+ return buf.readBigInt64LE(index);
1418
+ }
1419
+ function ToLongArray2(data_) {
1420
+ const bArr = Buffer.alloc(data_.length * 2);
1421
+ for (let i = 0; i < data_.length; i++) {
1422
+ bArr[i * 2] = data_[i];
1423
+ bArr[i * 2 + 1] = 0;
1424
+ }
1425
+ const length = (bArr.length % 8 === 0 ? 0 : 1) + Math.floor(bArr.length / 8);
1426
+ const jArr = new Array(length);
1427
+ for (let i2 = 0; i2 < length - 1; i2++) {
1428
+ jArr[i2] = bytes2long(bArr, i2 * 8);
1429
+ }
1430
+ const bArr2 = Buffer.alloc(8);
1431
+ let i3 = 0;
1432
+ for (let i4 = (length - 1) * 8; i4 < bArr.length; i4++) {
1433
+ bArr2[i3] = bArr[i4];
1434
+ i3++;
1435
+ }
1436
+ jArr[length - 1] = bytes2long(bArr2, 0);
1437
+ return jArr;
1438
+ }
1439
+ function TEADecrypt(data, key) {
1440
+ const length = data.length;
1441
+ if (length >= 1) {
1442
+ let j3 = data[0];
1443
+ let j4 = toLong(
1444
+ (6n + BigInt(Math.floor(52 / length))) * DELTA
1445
+ );
1446
+ while (true) {
1447
+ const j5 = j4;
1448
+ if (j5 === 0n) {
1449
+ break;
1450
+ }
1451
+ const j6 = toLong(3n & j5 >> 2n);
1452
+ let j7 = length;
1453
+ while (true) {
1454
+ j7--;
1455
+ if (j7 > 0) {
1456
+ const j8 = data[j7 - 1];
1457
+ const i = j7;
1458
+ j3 = toLong(
1459
+ data[i] - toLong(
1460
+ toLong(
1461
+ toLong(j3 ^ j5) + toLong(j8 ^ key[Number(toLong(3n & BigInt(j7) ^ j6))])
1462
+ ) ^ toLong(
1463
+ toLong(
1464
+ toLong(j8 >> 5n) ^ toLong(j3 << 2n)
1465
+ ) + toLong(
1466
+ toLong(j3 >> 3n) ^ toLong(j8 << 4n)
1467
+ )
1468
+ )
1469
+ )
1470
+ );
1471
+ data[i] = j3;
1472
+ } else {
1473
+ break;
1474
+ }
1475
+ }
1476
+ const j9 = data[length - 1];
1477
+ j3 = toLong(
1478
+ data[0] - toLong(
1479
+ toLong(
1480
+ toLong(key[Number(toLong(BigInt(j7) & 3n ^ j6))] ^ j9) + toLong(j3 ^ j5)
1481
+ ) ^ toLong(
1482
+ toLong(
1483
+ toLong(j9 >> 5n) ^ toLong(j3 << 2n)
1484
+ ) + toLong(
1485
+ toLong(j3 >> 3n) ^ toLong(j9 << 4n)
1486
+ )
1487
+ )
1488
+ )
1489
+ );
1490
+ data[0] = j3;
1491
+ j4 = toLong(j5 - DELTA);
1492
+ }
1493
+ }
1494
+ return data;
1495
+ }
1496
+ function decryptMrc(data) {
1497
+ if (data == null || data.length < MIN_LENGTH) return data;
1498
+ const decrypted = TEADecrypt(
1499
+ ToLongArray(data),
1500
+ ToLongArray2(Buffer.from(PadRight("karakal@123Qcomyidongtiantianhaoting", MIN_LENGTH), "utf8"))
1501
+ );
1502
+ return ToByteArray(decrypted).toString("utf16le");
1503
+ }
1504
+ function toWordTime(times) {
1505
+ const type = times.startsWith("(") ? 1 : times.startsWith("[") ? 2 : 0;
1506
+ times = times.replace(/[()\[\]]/g, "").trim();
1507
+ const time = Number(times.split(",")[0]);
1508
+ const mm = Math.floor(time / 6e4).toString().padStart(2, "0");
1509
+ const ss = Math.floor(time / 1e3 % 60).toString().padStart(2, "0");
1510
+ const ms = Math.floor(time % 1e3).toString().padStart(3, "0");
1511
+ if (type === 1) {
1512
+ return `[${mm}:${ss}.${ms}]`;
1513
+ } else {
1514
+ return times;
1515
+ }
1516
+ }
1517
+ function formatMrc(data) {
1518
+ const line = data.split("\n");
1519
+ const formattedData = line.reduce((prev, cur, index) => {
1520
+ cur = cur.trim();
1521
+ if (cur === "") return prev;
1522
+ if (!"1234567890".split("").includes(String(cur[1]))) {
1523
+ prev.push(cur);
1524
+ return prev;
1525
+ }
1526
+ cur = cur.replace(/\[[^\]]*\]/g, "");
1527
+ let nextIndex = 0, partStart = 0;
1528
+ let lineStr = "";
1529
+ while (true) {
1530
+ if (nextIndex === -1) break;
1531
+ const leftPos = cur.indexOf("(", nextIndex);
1532
+ if (leftPos === -1) break;
1533
+ const rightPos = cur.indexOf(")", leftPos);
1534
+ if (rightPos === -1) break;
1535
+ const time = cur.substring(leftPos, rightPos + 1);
1536
+ const word = cur.substring(partStart, leftPos);
1537
+ if (!!word && !!time) {
1538
+ partStart = rightPos + 1;
1539
+ nextIndex = rightPos + 1;
1540
+ } else {
1541
+ break;
1542
+ }
1543
+ lineStr += `${toWordTime(time)}${word}`;
1544
+ }
1545
+ prev.push(lineStr + "\n");
1546
+ return prev;
1547
+ }, []);
1548
+ return formattedData.join("");
1549
+ }
1550
+
1551
+ // src/modules/lyric.ts
1552
+ var getLyric = async (contentId, type = "lrc") => {
1367
1553
  if (contentId === "") return { error: "contentId is empty!", success: false };
1368
- const res = await axios8.get(`https://app.c.nf.migu.cn/resource/song/by-contentids/v2.0?contentId=${contentId}`);
1554
+ const types = type.split(",");
1555
+ if (types.length === 0) return { error: "types is empty!", success: false };
1556
+ const res = await axios8.get(`https://app.u.nf.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceId=${contentId}&resourceType=2`);
1369
1557
  const code = res.data.code.toString() || "";
1370
- const data = res.data.data || [];
1558
+ const data = res.data.resource[0] || {};
1371
1559
  if (code !== "000000") return {
1372
1560
  success: false,
1373
1561
  status: res.status,
1374
1562
  error: res.data.info || res.data
1375
1563
  };
1376
1564
  if (data.length === 0) return { error: "data.length = 0 !", success: false, data };
1377
- const lrcUrl = data[0].lrcUrl || "";
1378
- if (lrcUrl === "") return { error: "lrcUrl is empty!", success: false, data };
1379
- const lrcRes = await axios8.get(lrcUrl);
1380
- if (lrcRes.status !== 200) return {
1381
- success: false,
1382
- status: lrcRes.status,
1383
- error: "lrcRes.status !== 200 !",
1384
- data
1385
- };
1386
- const lrc = lrcRes.data || "";
1565
+ let lrc, lrcUrl, mrc, mrcUrl, trc, trcUrl;
1566
+ if (types.includes("lrc")) {
1567
+ lrcUrl = data.lrcUrl || "";
1568
+ if (lrcUrl !== "") {
1569
+ const lrcRes = await axios8.get(lrcUrl);
1570
+ if (lrcRes.status === 200) {
1571
+ lrc = lrcRes.data || "";
1572
+ }
1573
+ }
1574
+ }
1575
+ if (types.includes("trc")) {
1576
+ trcUrl = data.trcUrl || "";
1577
+ if (trcUrl !== "") {
1578
+ const trcRes = await axios8.get(trcUrl);
1579
+ if (trcRes.status === 200) {
1580
+ trc = trcRes.data || "";
1581
+ }
1582
+ }
1583
+ }
1584
+ if (types.includes("mrc")) {
1585
+ mrcUrl = data.mrcUrl || "";
1586
+ if (mrcUrl !== "") {
1587
+ const mrcRes = await axios8.get(mrcUrl);
1588
+ if (mrcRes.status === 200) {
1589
+ mrc = formatMrc(decryptMrc(mrcRes.data || ""));
1590
+ }
1591
+ }
1592
+ }
1387
1593
  return {
1388
1594
  success: true,
1389
1595
  lrc,
1390
- lrcUrl
1596
+ lrcUrl,
1597
+ mrc,
1598
+ mrcUrl,
1599
+ trc,
1600
+ trcUrl
1391
1601
  };
1392
1602
  };
1393
1603
 
@@ -1873,7 +2083,7 @@ var shareCommon = async (resourceType, contentId, contentName, targetUserName, c
1873
2083
  contentName,
1874
2084
  targetUserName,
1875
2085
  copyrightId: copyrightId || void 0,
1876
- specialType: resourceType === "2003" ? "2" : void 0
2086
+ specialType: ["2003", "5"].includes(resourceType) ? "2" : void 0
1877
2087
  } }
1878
2088
  );
1879
2089
  };
@@ -2272,18 +2482,39 @@ var getUserOrdered = async (pacmtoken) => {
2272
2482
  return { data, newPacmToken: cookies.pacmtoken || "" };
2273
2483
  };
2274
2484
 
2485
+ // src/modules/dalbum_info.ts
2486
+ var getDAlbumInfo = async (dAlbumId) => {
2487
+ return await h5fetch(`https://app.c.nf.migu.cn/MIGUM3.0/resource/dalbum/v2.0?dAlbumId=${dAlbumId}`);
2488
+ };
2489
+
2490
+ // src/modules/dalbum_song.ts
2491
+ var getDAlbumSong = async (dAlbumId) => {
2492
+ return await h5fetch(`https://app.c.nf.migu.cn/MIGUM3.0/resource/dalbum/song/v2.0?dAlbumId=${dAlbumId}`);
2493
+ };
2494
+
2495
+ // src/modules/dalbum_pay.ts
2496
+ var getDAlbumPay = async (dAlbumId) => {
2497
+ return await h5fetch(
2498
+ `https://app.c.nf.migu.cn/MIGUM3.0/strategy/album-sub-rank/v1.0?queryType=01&resourceId=${dAlbumId}`,
2499
+ { headers: { "channel": "0146891" } }
2500
+ );
2501
+ };
2502
+
2275
2503
  // src/utils/index.ts
2276
2504
  var utils_exports = {};
2277
2505
  __export(utils_exports, {
2278
2506
  RSAKey: () => RSAKey,
2279
2507
  URLParams: () => URLParams,
2280
2508
  changeQuality: () => changeQuality,
2509
+ decryptMrc: () => decryptMrc,
2510
+ formatMrc: () => formatMrc,
2281
2511
  getDeviceId: () => getDeviceId,
2282
2512
  getPublicKey: () => getPublicKey,
2283
2513
  getQuality: () => getQuality,
2284
2514
  getResourceId: () => getResourceId,
2285
2515
  isQuality: () => isQuality,
2286
2516
  qualityList: () => qualityList,
2517
+ toWordTime: () => toWordTime,
2287
2518
  toneFormat: () => toneFormat,
2288
2519
  toneUrl: () => toneUrl
2289
2520
  });
@@ -2309,6 +2540,8 @@ var getResourceId = (name) => {
2309
2540
  return "6000";
2310
2541
  case "mv":
2311
2542
  return "D";
2543
+ case "dalbum":
2544
+ return "5";
2312
2545
  case "vrbt":
2313
2546
  return "M";
2314
2547
  default:
@@ -2333,11 +2566,13 @@ export {
2333
2566
  checkCanListen,
2334
2567
  checkToken,
2335
2568
  createClient,
2569
+ decryptMrc,
2336
2570
  deleteCloudMusic,
2337
2571
  deleteComment,
2338
2572
  dislikeSong,
2339
2573
  editUserMyList,
2340
2574
  emojiAction,
2575
+ formatMrc,
2341
2576
  getActivities,
2342
2577
  getAiBeanCount,
2343
2578
  getAiBeanSignStatus,
@@ -2353,6 +2588,9 @@ export {
2353
2588
  getConcertInfo,
2354
2589
  getConcertRecommendMv,
2355
2590
  getConcertUrl,
2591
+ getDAlbumInfo,
2592
+ getDAlbumPay,
2593
+ getDAlbumSong,
2356
2594
  getDLUrlV1,
2357
2595
  getDeviceId,
2358
2596
  getEmojiNum,
@@ -2467,6 +2705,7 @@ export {
2467
2705
  shareVideo,
2468
2706
  signAiBean,
2469
2707
  signNinan,
2708
+ toWordTime,
2470
2709
  toneFormat,
2471
2710
  toneUrl
2472
2711
  };