From 16a3f488d32c3c4f054826cead940a7a20a5c220 Mon Sep 17 00:00:00 2001 From: TRAE Bot Date: Sun, 5 Jul 2026 12:21:54 +0000 Subject: [PATCH] feat(wy): cookie support, songList/singer/album real impl, ext homePage+share --- 聆澜/Koneko_聆澜_网易云音乐_v0.1.0_QZv2.js | 267 +++++++++++++++++++-- 1 file changed, 249 insertions(+), 18 deletions(-) diff --git a/聆澜/Koneko_聆澜_网易云音乐_v0.1.0_QZv2.js b/聆澜/Koneko_聆澜_网易云音乐_v0.1.0_QZv2.js index 13c418a..679436d 100644 --- a/聆澜/Koneko_聆澜_网易云音乐_v0.1.0_QZv2.js +++ b/聆澜/Koneko_聆澜_网易云音乐_v0.1.0_QZv2.js @@ -1,6 +1,7 @@ var env = global.env || {}; var CERU_KEY = env.ceru_key || ''; +var WY_COOKIE = env.cookie || ''; var https = require('https'); var http = require('http'); var crypto = require('crypto'); @@ -138,7 +139,8 @@ function musicSearch(str, page, limit) { return requestUrl('http://interface3.music.163.com/eapi/search/song/list/page', 'POST', { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36', 'Origin': 'https://music.163.com', - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE }, querystring.stringify(form)).then(function(res) { return res.body; }); @@ -218,7 +220,8 @@ function getPic(songInfo) { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', 'Referer': 'https://music.163.com/song?id=' + songInfo.id, 'Origin': 'https://music.163.com', - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE }, querystring.stringify(weapi({ c: '[{"id":' + songInfo.id + '}]', ids: '[' + songInfo.id + ']' }))) .then(function(res) { if (res.body && res.body.songs && res.body.songs.length) return res.body.songs[0].al.picUrl; @@ -232,7 +235,8 @@ function getLyric(songInfo) { var songmid = songInfo.id || ''; return requestUrl('https://music.163.com/api/song/lyric?id=' + songmid + '&lv=1&kv=1&tv=-1', 'GET', { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', - 'Referer': 'https://music.163.com/song?id=' + songmid + 'Referer': 'https://music.163.com/song?id=' + songmid, + 'Cookie': WY_COOKIE }).then(function(res) { if (res.body && res.body.lrc && res.body.lrc.lyric) return res.body.lrc.lyric; return ''; @@ -244,7 +248,8 @@ function musicDetail(songmid) { return requestUrl('https://music.163.com/weapi/v3/song/detail', 'POST', { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', 'Origin': 'https://music.163.com', - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE }, querystring.stringify(weapi({ c: '[{"id":' + songmid + '}]', ids: '[' + songmid + ']' }))) .then(function(res) { if (res.body && res.body.songs && res.body.songs.length) { @@ -278,7 +283,8 @@ function hotSearch() { return requestUrl('https://music.163.com/weapi/search/hot', 'POST', { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', 'Origin': 'https://music.163.com', - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE }, querystring.stringify(weapi({ type: 1111 }))) .then(function(res) { var list = []; @@ -295,7 +301,8 @@ function tipSearch(str) { return requestUrl('https://music.163.com/weapi/search/suggest/web', 'POST', { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', 'Origin': 'https://music.163.com', - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE }, querystring.stringify(weapi({ s: str, limit: 10 }))) .then(function(res) { var result = { order: [], songs: [], artists: [], albums: [], playlists: [] }; @@ -339,7 +346,8 @@ function leaderboardGetList(id, page) { return requestUrl('https://music.163.com/weapi/v3/playlist/detail', 'POST', { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', 'Origin': 'https://music.163.com', - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE }, querystring.stringify(form)).then(function(res) { if (!res.body || !res.body.playlist) return { list: [], total: 0, source: 'wy' }; var tracks = res.body.playlist.tracks || []; @@ -366,19 +374,236 @@ function leaderboardGetList(id, page) { } // ===== 歌单 ===== -function songList() { - return Promise.resolve({ list: [], total: 0, page: 1, source: 'wy' }); +function formatPlayCount(count) { + if (!count && count !== 0) return ''; + if (count >= 100000000) return (count / 100000000).toFixed(1) + '亿'; + if (count >= 10000) return (count / 10000).toFixed(1) + '万'; + return String(count); } +var songList = { + limit_list: 30, + sortList: [ + { name: '最热', id: 'hot' } + ], + getTags: function() { + return requestUrl('https://music.163.com/weapi/playlist/catalogue', 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Origin': 'https://music.163.com', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE + }, querystring.stringify(weapi({}))).then(function(res) { + if (!res.body || res.body.code !== 200) return { tags: [], hotTag: [], source: 'wy' }; + var categories = res.body.categories || {}; + var sub = res.body.sub || []; + var subList = {}; + for (var i = 0; i < sub.length; i++) { + var item = sub[i]; + if (!subList[item.category]) subList[item.category] = []; + subList[item.category].push({ parent_name: categories[item.category], name: item.name, id: item.name, source: 'wy' }); + } + var tags = []; + var keys = Object.keys(categories); + for (var j = 0; j < keys.length; j++) { + tags.push({ name: categories[keys[j]], list: subList[keys[j]] || [], source: 'wy' }); + } + return { tags: tags, hotTag: [], source: 'wy' }; + }).catch(function() { return { tags: [], hotTag: [], source: 'wy' }; }); + }, + getList: function(sortId, tagId, page) { + if (!page) page = 1; + var limit = this.limit_list; + return requestUrl('https://music.163.com/weapi/playlist/list', 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Origin': 'https://music.163.com', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE + }, querystring.stringify(weapi({ + cat: tagId || '全部', + order: sortId || 'hot', + limit: limit, + offset: limit * (page - 1), + total: true + }))).then(function(res) { + if (!res.body || res.body.code !== 200) return { list: [], total: 0, page: page, limit: limit, source: 'wy' }; + var playlists = res.body.playlists || []; + var list = []; + for (var i = 0; i < playlists.length; i++) { + var p = playlists[i]; + list.push({ + id: String(p.id), + name: p.name, + author: p.creator && p.creator.nickname ? p.creator.nickname : '', + img: p.coverImgUrl || '', + play_count: formatPlayCount(p.playCount), + total: p.trackCount || 0, + desc: p.description || '', + source: 'wy' + }); + } + return { list: list, total: res.body.total || 0, page: page, limit: limit, source: 'wy' }; + }).catch(function() { return { list: [], total: 0, page: page, limit: limit, source: 'wy' }; }); + }, + getListDetail: function(id, page) { + if (!page) page = 1; + var limit = 1000; + return requestUrl('https://music.163.com/weapi/v3/playlist/detail', 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Origin': 'https://music.163.com', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE + }, querystring.stringify(weapi({ id: id, n: limit, s: 8 }))).then(function(res) { + if (!res.body || !res.body.playlist) return { list: [], total: 0, source: 'wy' }; + var playlist = res.body.playlist; + var tracks = playlist.tracks || []; + var list = []; + for (var i = 0; i < tracks.length; i++) { + var item = tracks[i]; + var picUrl = item.al && item.al.picUrl ? item.al.picUrl : ''; + list.push({ + id: item.id, + name: item.name, + artists: formatSingerName(item.ar, 'name'), + source: 'wy', + pic: picUrl, mPic: picUrl, sPic: picUrl, + albumName: item.al && item.al.name ? item.al.name : '', + albumId: item.al && item.al.id ? item.al.id : '', + interval: formatPlayTime((item.dt || 0) / 1000), + qualities: {} + }); + } + return { + list: list, page: page, limit: limit, + total: playlist.trackIds ? playlist.trackIds.length : list.length, + source: 'wy', + info: { name: playlist.name, img: playlist.coverImgUrl, desc: playlist.description, author: playlist.creator && playlist.creator.nickname ? playlist.creator.nickname : '' } + }; + }).catch(function() { return { list: [], total: 0, source: 'wy' }; }); + }, + search: function(text, page, limit) { + if (!page) page = 1; + if (!limit) limit = 20; + var form = eapi('/api/cloudsearch/pc', { s: text, type: 1000, limit: limit, total: page == 1, offset: limit * (page - 1) }); + return requestUrl('http://interface3.music.163.com/eapi/cloudsearch/pc', 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Origin': 'https://music.163.com', + 'Cookie': WY_COOKIE + }, querystring.stringify(form)).then(function(res) { + if (!res.body || res.body.code !== 200) return { list: [], total: 0, source: 'wy' }; + var playlists = res.body.result && res.body.result.playlists ? res.body.result.playlists : []; + var list = []; + for (var i = 0; i < playlists.length; i++) { + var p = playlists[i]; + list.push({ id: String(p.id), name: p.name, author: p.creator && p.creator.nickname ? p.creator.nickname : '', img: p.coverImgUrl || '', play_count: formatPlayCount(p.playCount), total: p.trackCount || 0, source: 'wy' }); + } + return { list: list, total: res.body.result.playlistCount || 0, page: page, limit: limit, source: 'wy' }; + }).catch(function() { return { list: [], total: 0, source: 'wy' }; }); + } +}; + // ===== 歌手 ===== -function singer() { - return Promise.resolve({ source: 'wy', list: [], total: 0 }); -} +var singer = { + getInfo: function(id) { + var form = eapi('/api/artist/head/info/get', { id: id }); + return requestUrl('http://interface3.music.163.com/eapi/artist/head/info/get', 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Cookie': WY_COOKIE + }, querystring.stringify(form)).then(function(res) { + if (!res.body || res.body.code !== 200) return null; + return { + source: 'wy', id: res.body.artist.id, + info: { name: res.body.artist.name, desc: res.body.artist.briefDesc, avatar: res.body.user && res.body.user.avatarUrl ? res.body.user.avatarUrl : '' }, + count: { music: res.body.artist.musicSize, album: res.body.artist.albumSize } + }; + }).catch(function() { return null; }); + }, + getSongList: function(id, page, limit) { + if (!page) page = 1; + if (!limit) limit = 100; + var offset = (page - 1) * limit; + var form = eapi('/api/v2/artist/songs', { id: id, limit: limit, offset: offset }); + return requestUrl('http://interface3.music.163.com/eapi/v2/artist/songs', 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Cookie': WY_COOKIE + }, querystring.stringify(form)).then(function(res) { + if (!res.body || !res.body.songs) return { list: [], total: 0, source: 'wy' }; + var list = []; + for (var i = 0; i < res.body.songs.length; i++) { + var item = res.body.songs[i]; + var picUrl = item.al && item.al.picUrl ? item.al.picUrl : ''; + list.push({ + id: item.id, name: item.name, artists: formatSingerName(item.artists, 'name'), + source: 'wy', pic: picUrl, mPic: picUrl, sPic: picUrl, + albumName: item.album && item.album.name ? item.album.name : '', + albumId: item.album && item.album.id ? item.album.id : '', + interval: formatPlayTime((item.duration || 0) / 1000), qualities: {} + }); + } + return { list: list, total: res.body.total || 0, page: page, limit: limit, source: 'wy' }; + }).catch(function() { return { list: [], total: 0, source: 'wy' }; }); + }, + getAlbumList: function(id, page, limit) { + if (!page) page = 1; + if (!limit) limit = 10; + var offset = (page - 1) * limit; + var form = eapi('/api/artist/albums/' + id, { limit: limit, offset: offset }); + return requestUrl('http://interface3.music.163.com/eapi/artist/albums/' + id, 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Cookie': WY_COOKIE + }, querystring.stringify(form)).then(function(res) { + if (!res.body || !res.body.hotAlbums) return { list: [], total: 0, source: 'wy' }; + var list = []; + for (var i = 0; i < res.body.hotAlbums.length; i++) { + var item = res.body.hotAlbums[i]; + list.push({ id: item.id, count: item.size, info: { name: item.name, author: formatSingerName(item.artists), img: item.picUrl, desc: null } }); + } + return { list: list, total: res.body.artist && res.body.artist.albumSize ? res.body.artist.albumSize : 0, page: page, limit: limit, source: 'wy' }; + }).catch(function() { return { list: [], total: 0, source: 'wy' }; }); + } +}; // ===== 专辑 ===== -function album() { - return Promise.resolve({ source: 'wy', list: [], total: 0 }); -} +var album = { + getInfo: function(id) { + var form = weapi({ id: id }); + return requestUrl('https://music.163.com/weapi/v1/album/' + id, 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Origin': 'https://music.163.com', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE + }, querystring.stringify(form)).then(function(res) { + if (!res.body || !res.body.album) return null; + var a = res.body.album; + return { source: 'wy', id: a.id, info: { name: a.name, author: formatSingerName(a.artists), img: a.picUrl, desc: a.description || '' }, count: { song: a.size } }; + }).catch(function() { return null; }); + }, + getSongList: function(id, page, limit) { + if (!page) page = 1; + if (!limit) limit = 100; + var form = weapi({ id: id }); + return requestUrl('https://music.163.com/weapi/v1/album/' + id, 'POST', { + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36', + 'Origin': 'https://music.163.com', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': WY_COOKIE + }, querystring.stringify(form)).then(function(res) { + if (!res.body || !res.body.songs) return { list: [], total: 0, source: 'wy' }; + var list = []; + for (var i = 0; i < res.body.songs.length; i++) { + var item = res.body.songs[i]; + var picUrl = item.al && item.al.picUrl ? item.al.picUrl : ''; + list.push({ + id: item.id, name: item.name, artists: formatSingerName(item.ar, 'name'), + source: 'wy', pic: picUrl, mPic: picUrl, sPic: picUrl, + albumName: item.al && item.al.name ? item.al.name : '', + albumId: item.al && item.al.id ? item.al.id : '', + interval: formatPlayTime((item.dt || 0) / 1000), qualities: {} + }); + } + return { list: list, total: list.length, page: page, limit: limit, source: 'wy' }; + }).catch(function() { return { list: [], total: 0, source: 'wy' }; }); + } +}; // ===== 插件信息 ===== var pluginInfo = { @@ -389,14 +614,20 @@ var pluginInfo = { source: 'wy', description: '网易云音乐音源,基于 CeruMusic musicSdk 搜索 + Ceru 播放接口' }, - ext: [], - env: [{ key: 'ceru_key', name: 'Ceru API Key', description: '聆澜播放接口密钥' }], + ext: [ + { type: 'homePage', url: 'https://music.163.com/', name: '网易云音乐主页' }, + { type: 'share', url: 'https://music.163.com/song/media/outer/url?id={id}.mp3', name: '外链分享' } + ], + env: [ + { key: 'ceru_key', name: 'Ceru API Key', description: '聆澜播放接口密钥' }, + { key: 'cookie', name: '网易云Cookie', description: '网易云音乐登录Cookie(需包含MUSIC_U=),用于个人歌单、收藏等功能' } + ], quality: [ { name: '标准', ui: '标', id: '128k' }, { name: '高品', ui: 'HQ', id: '320k' }, { name: '无损', ui: 'SQ', id: 'flac' } ], - supportFunc: [] + supportFunc: ['musicSearch', 'tipSearch', 'hotSearch', 'leaderboard', 'songList', 'singer', 'album', 'getLyric', 'getPic', 'getUrl', 'musicDetail', 'musicInfo'] } module.exports = {