From 1026ccc47513539f5f0f049fe4c8bbea938f7179 Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Mon, 27 Mar 2023 01:13:35 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=B7=BB=E5=8A=A0=E7=BD=91?= =?UTF-8?q?=E6=98=93=E4=BA=91=E4=BA=91=E7=9B=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/neteasepro.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++ utils/netease.js | 30 +++++++++++++++++++++-- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/apps/neteasepro.js b/apps/neteasepro.js index a6960d3..0b1b432 100644 --- a/apps/neteasepro.js +++ b/apps/neteasepro.js @@ -12,6 +12,8 @@ import { getSong, getSongDetail, getUserRecord, + getCloud, + getCloudMusicDetail } from "../utils/netease.js"; import { ha12store, store2ha1 } from "../utils/encrypt.js"; import { downloadMp3 } from "../utils/common.js"; @@ -43,6 +45,10 @@ export class neteasepro extends plugin { reg: "^#网易云听歌排行$", fnc: "neteaseListenRank", }, + { + reg: "^#网易云云盘$", + fnc: "neteaseCloud", + }, { reg: "music.163.com", fnc: "netease", @@ -141,6 +147,31 @@ export class neteasepro extends plugin { await e.reply(await this.musicForwardPack(forwardMsg)); } + async neteaseCloud(e) { + const userInfo = await this.aopBefore(e); + const realCookie = userInfo.cookie; + if (realCookie === "") { + return true; + } + const cloudMusics = (await getCloud(realCookie)).map(async item => { + let music = await getSong(item.songId, realCookie) + let finalMusic; + if (music instanceof Array) { + music = music[0]; + finalMusic = await this.cloudMusicPack(item, music.url); + } else { + finalMusic = await this.musicPack(music); + } + return { + message: segment.json(finalMusic), + nickname: e.sender.card || e.user_id, + user_id: e.user_id, + } + }) + let forwardMsg = await Bot.makeForwardMsg(await Promise.all(cloudMusics)); + await e.reply(await this.musicForwardPack(forwardMsg)); + } + async netease(e) { const message = e.msg === undefined ? e.message.shift().data.replaceAll("\\", "") : e.msg.trim(); @@ -287,6 +318,36 @@ export class neteasepro extends plugin { }); } + async cloudMusicPack(item, url) { + return { + app: "com.tencent.structmsg", + desc: "音乐", + view: "music", + ver: "0.0.0.1", + prompt: "[分享]" + item.songName + "-" + item.album, + meta: { + music: { + app_type: 1, + appid: 100495085, + desc: item.artist, + jumpUrl: `https://y.music.163.com/m/song?id=${item.songId}`, + musicUrl: url, + preview: "https://i.gtimg.cn/open/app_icon/00/49/50/85/100495085_100_m.png", + sourceMsgId: "0", + source_icon: "https://i.gtimg.cn/open/app_icon/00/49/50/85/100495085_100_m.png", + source_url: "", + tag: "网易云音乐", + title: item.fileName, + }, + }, + config: { + type: "normal", + forward: true, + ctime: Date.now(), + }, + } + } + // 包装分享小程序数据 async musicPack(song) { const title = song.name; diff --git a/utils/netease.js b/utils/netease.js index 7876d22..7a70d32 100644 --- a/utils/netease.js +++ b/utils/netease.js @@ -2,7 +2,7 @@ import fetch from "node-fetch"; import axios from "axios"; -const BASE_URL = "http://cloud-music.pl-fe.cn"; +const BASE_URL = "http://127.0.0.1:3000"; /** * 获取cookie @@ -124,6 +124,30 @@ async function getSongDetail(ids) { }); } +async function getCloud(cookie) { + return axios({ + url: `${BASE_URL}/user/cloud?timestamp=${Date.now()}`, + method: "get", + data: { + cookie, + }, + }).then(resp => { + return resp.data.data; + }); +} + +async function getCloudMusicDetail(id, cookie) { + return axios({ + url: `${BASE_URL}/user/cloud/detail?id=${id}×tamp=${Date.now()}`, + method: "get", + data: { + cookie, + }, + }).then(resp => { + return resp.data; + }); +} + export { getCookies, getLoginStatus, @@ -133,5 +157,7 @@ export { getUserRecord, checkMusic, getSong, - getSongDetail + getSongDetail, + getCloud, + getCloudMusicDetail };