From 46a5db6f4be3daa64b61524d6561130d9c3ebb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Wed, 13 Apr 2022 23:55:58 +0800 Subject: [PATCH] Feat: Netease Music API Alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 网易云 API 增加别名字段,部分参数更正,文档说明内容更正 --- src/api/acgm.ts | 1 + src/api/netease.ts | 29 +++++++++++++++---- src/api/utils/netease.ts | 1 + src/pages/acgm.tsx | 61 ++++++++++++++++++++++++++++++--------- src/pages/bing.tsx | 10 +++---- src/pages/netease.tsx | 33 ++++++++++----------- src/pages/wallpaper.tsx | 62 +++++++--------------------------------- 7 files changed, 105 insertions(+), 92 deletions(-) diff --git a/src/api/acgm.ts b/src/api/acgm.ts index 77e9b31..b867740 100644 --- a/src/api/acgm.ts +++ b/src/api/acgm.ts @@ -31,6 +31,7 @@ export default Api( } } + // 直接播放 if ("play" in ctx.query) { ctx.status = 302; ctx.set("location", `https://music.163.com/song/media/outer/url?id=${id}`); diff --git a/src/api/netease.ts b/src/api/netease.ts index f2387c3..282d0e3 100644 --- a/src/api/netease.ts +++ b/src/api/netease.ts @@ -6,7 +6,7 @@ import { client } from './utils/redis'; export default Api( Get(), - Query<{ id?: string }>(), + Query<{ id?: string, play?: string }>(), async () => { const ctx = useContext(); @@ -15,6 +15,21 @@ export default Api( const { id } = ctx.query; + if (!id) { + return { + code: 0, + msg: "Failed, no id found" + } + } + + // 直接播放 + if ("play" in ctx.query) { + ctx.status = 302; + ctx.set("location", `https://music.163.com/song/media/outer/url?id=${id}`); + + return ""; + } + // 尝试使用缓存 const cached = await client.lRange(`api-next:163:${id}`, 0, 7); @@ -27,11 +42,12 @@ export default Api( title: cached[0], artist: cached[1], album: cached[2], - cover: cached[3], - lyric: cached[4], - sub_lyric: cached[5], - link: cached[6], - served: Boolean(cached[7]), + alias: cached[3], + cover: cached[4], + lyric: cached[5], + sub_lyric: cached[6], + link: cached[7], + served: Boolean(cached[8]), cached: true } }; @@ -45,6 +61,7 @@ export default Api( song.title, song.artist, song.album, + song.alias, song.cover, song.lyric, song.sub_lyric, diff --git a/src/api/utils/netease.ts b/src/api/utils/netease.ts index f671052..d269c2e 100644 --- a/src/api/utils/netease.ts +++ b/src/api/utils/netease.ts @@ -46,6 +46,7 @@ export const parseSongData = async (item: any) => { id: item.id, title: item.name, artist: item.artists ?. [0].name || "", + alias: item.alias ?. [0] || "", album: item.album.name || "", cover: `${item.album.picUrl.replace("http://", "https://")}?param=250y250"`, lyric, diff --git a/src/pages/acgm.tsx b/src/pages/acgm.tsx index fe9472d..e04a657 100644 --- a/src/pages/acgm.tsx +++ b/src/pages/acgm.tsx @@ -54,7 +54,7 @@ function ACGM() {

使用方法:

-

调用地址 https://api.paugram.com/acgm/,即可获得一段歌曲 JSON 信息。

+

调用地址 https://api.paugram.com/api/acgm,即可获得一段歌曲 JSON 信息。

如果您已开始使用本 API 服务,则默认视为遵守 本约定

音乐版权归网易云音乐所有,本站不为滥用本 API 进行违规操作者承担责任。部分歌曲可能因版权问题无法播放,敬请谅解!

为了防止多次出现随机到同一首歌的情况,请允许我们使用你的 Cookie 记录。

@@ -71,7 +71,7 @@ function ACGM() { - list + list(施工中) 可选的音乐列表 详见下方,默认 随机 音乐类别 @@ -116,32 +116,59 @@ function ACGM() { 参数名称 描述 + 值 id 音乐 ID + string title 音乐名称 + string artist 音乐艺术家 + string album 音乐专辑名称 + string + + + alias + 音乐别称 + string cover - 音乐专辑图片(https) + 音乐专辑图片链接(https) + string link - 音乐源地址(https) + 音乐源地址链接 + string + + + lyric + 音乐 LRC 歌词内容 + string + + + sub_lyric + 翻译版 LRC 歌词内容(如果有) + string + + + served + 是否为 VIP 或无版权歌曲(测试功能) + true false @@ -149,23 +176,31 @@ function ACGM() {

示例:

获得一首随机动漫音乐的信息

-
{`https://api.paugram.com/acgm/
+
{`https://api.paugram.com/api/acgm
 
 // 返回的是:
 
 {
-    "id": 517567145,
-    "title": "初登校",
-    "artist": "橋本由香利",
-    "album": "ひなこのーと COMPLETE SOUNDTRACK",
-    "cover": 封面地址,
-    "link": 音乐地址
+  "code": 1,
+  "msg": "Success",
+  "data": {
+    "id": 435289265,
+    "title": "問題がある人たち",
+    "artist": "吟",
+    "alias": "",
+    "album": "この美術部には問題がある! オリジナルサウンドトラックCD vol.1",
+    "cover": "封面地址",
+    "lyric": "歌词内容",
+    "sub_lyric": "翻译歌词内容",
+    "link": "音乐地址",
+    "served": false
+  }
 }
 `}

通过 List 获得一首随机动漫歌曲的信息,并跳转到实际地址

-
https://api.paugram.com/acgm/?list=1&play=true
+
https://api.paugram.com/api/acgm/?list=1&play=true

建立一个 Audio 播放器,并使用本 API

-
<audio src="https://api.paugram.com/acgm/?play=true" controls></audio>
+
<audio src="https://api.paugram.com/api/acgm/?play=true" controls></audio>

测试小工具:

来一首随机动漫音乐吧!刷新或点击按钮即可切歌

diff --git a/src/pages/bing.tsx b/src/pages/bing.tsx index 57acfe9..dcd36fb 100644 --- a/src/pages/bing.tsx +++ b/src/pages/bing.tsx @@ -18,7 +18,7 @@ function Bing() {

使用方法:

-

调用地址 https://api.paugram.com/bing/ 可自动跳转到对应的壁纸

+

调用地址 https://api.paugram.com/api/bing 可自动跳转到对应的壁纸

如果您已开始使用本 API 服务,则默认视为遵守 本约定

图片版权归原作者所有,本站不为滥用本 API 进行违规操作者承担责任。

@@ -42,9 +42,9 @@ function Bing() {

示例:

调用一张当天的图片

-
https://api.paugram.com/bing
+
https://api.paugram.com/api/bing

调用一张当天的图片,并使用 JSON 形式返回资料

-
{`https://api.paugram.com/bing/?info
+
{`https://api.paugram.com/api/bing/?info
 
 // 返回的是:
 
@@ -54,7 +54,7 @@ function Bing() {
 }`}

在网页背景上使用本 API

{`body{
-  background: url("https://api.paugram.com/bing/") center/cover no-repeat;
+  background: url("https://api.paugram.com/api/bing") center/cover no-repeat;
 }`}
 

在网页背景上使用本 API(伪元素半透明版)

@@ -67,7 +67,7 @@ function Bing() { z-index: -1; content: ""; position: fixed; - background: url(https://api.paugram.com/bing/) center/cover; + background: url(https://api.paugram.com/api/bing) center/cover; }`}
diff --git a/src/pages/netease.tsx b/src/pages/netease.tsx index 6cc3dc4..79fdced 100644 --- a/src/pages/netease.tsx +++ b/src/pages/netease.tsx @@ -18,12 +18,11 @@ function Netease() {

使用方法:

-

调用地址 https://api.paugram.com/netease/ 并输入参数 idtitle,即可获得一段歌曲 JSON 信息。

+

调用地址 https://api.paugram.com/netease 并输入参数 idtitle,即可获得一段歌曲 JSON 信息。

如果您已开始使用本 API 服务,则默认视为遵守 本约定

音乐版权归网易云音乐所有,本站不为滥用本 API 进行违规操作者承担责任。

参数:

-

建议使用 id 的方式获得歌曲信息,性能相对较好。

@@ -39,11 +38,6 @@ function Netease() { - - - - - @@ -84,6 +78,11 @@ function Netease() { + + + + + @@ -115,7 +114,7 @@ function Netease() {

示例:

通过 ID 获得一首歌的信息

-
{`https://api.paugram.com/netease/?id=517567145
+
{`https://api.paugram.com/netease/?id=448143347
 
 // 返回的是:
 
@@ -123,14 +122,16 @@ function Netease() {
   "code": 1,
   "msg": "Success",
   "data": {
-    "id": 517567145,
-    "title": "初登校",
-    "artist": "橋本由香利",
-    "album": "ひなこのーと COMPLETE SOUNDTRACK",
-    "cover": 封面地址,
-    "lyric": 歌词内容,
-    "sub_lyric": 翻译歌词内容,
-    "link": 音乐地址
+    "id": 448143347,
+    "title": "STARTING NOW!",
+    "artist": "水樹奈々",
+    "album": "NEOGENE CREATION",
+    "alias": "TV动画《这个美术社大有问题!》片头曲",
+    "cover": "封面地址",
+    "lyric": "歌词内容",
+    "sub_lyric": "翻译歌词内容",
+    "link": "音乐地址",
+    "served": false
   }
 }
 `}
diff --git a/src/pages/wallpaper.tsx b/src/pages/wallpaper.tsx index 186416d..3aadf0f 100644 --- a/src/pages/wallpaper.tsx +++ b/src/pages/wallpaper.tsx @@ -41,7 +41,7 @@ function Wallpaper() {

使用方法:

-

调用地址 https://api.paugram.com/wallpaper/ 可自动跳转到对应的壁纸(由于运营成本限制,目前本 API 借助 图床/CDN 等平台托管图片。欢迎给予资源赞助~)

+

调用地址 https://api.paugram.com/api/wallpaper 可自动跳转到对应的壁纸(由于运营成本限制,目前本 API 借助 图床/CDN 等平台托管图片。欢迎给予资源赞助~)

如果您已开始使用本 API 服务,则默认视为遵守 本约定

图片版权归原作者所有,本站不为滥用本 API 进行违规操作者承担责任。

@@ -58,14 +58,9 @@ function Wallpaper() { - + - - - - -
有效的音乐 ID,例:517567145 音乐 ID
playlist(施工中)有多首音乐的音乐列表音乐列表
play 参数值为 true 则启用跳转音乐专辑名称 string
alias音乐别称string
cover 音乐专辑图片链接(https)
sourcesm cp sina paulgt gh jsd 图片源,如留空则默认采用 sm.ms 源
category(施工中)us jp cn图片分类,可按不同国家和类别选择
@@ -81,68 +76,31 @@ function Wallpaper() { - - sm - 可用 - 资源较少!sm.ms 图床,国外速度较快,部分浏览器会阻止访问 - gt 可用 Gitee Pages 服务托管,服务器位于国内,速度稳定 - - sina - 可用 - 资源较少!新浪微博相册,国内速度较快,已更换新地址 - gh 可用 - 存放在 GitHub 上的图片资源,基于 JSDelivr 托管,速度非常理想 - - - - - -

图片分类(施工中):

-
- - - - - - - - - - - - - + - - - - - - - - + + +
参数名称状态分类描述
1不可用白底动漫插图GitHub Pages 服务托管,大多数节点都位于国外(可能会遇到 JP 节点)
2不可用透明底动漫插图
3不可用随机底动漫壁纸jsd可用与存放在 GitHub 上的图片资源同步,基于 JSDelivr 托管,使用 Fastly CDN 宿主

示例:

-

使用 sm.ms 图片源

-
https://api.paugram.com/wallpaper/?source=sm
-

使用新浪图片源,并选择美漫图片分类

-
https://api.paugram.com/wallpaper/?source=sina&category=us
+

使用 GitHub 图片源

+
https://api.paugram.com/api/wallpaper/?source=gh

在网页背景上使用本 API

{`body{
-  background: url("https://api.paugram.com/wallpaper/") center/cover no-repeat;
+  background: url("https://api.paugram.com/api/wallpaper") center/cover no-repeat;
 }`}
 

在网页背景上使用本 API(伪元素半透明版)

@@ -155,7 +113,7 @@ function Wallpaper() { z-index: -1; content: ""; position: fixed; - background: url(https://api.paugram.com/wallpaper/) center/cover; + background: url(https://api.paugram.com/api/wallpaper) center/cover; }`}