@kuriyona/cecilia 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kuriyona
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Cecilia
2
+
3
+ 网易云音乐 API 的非官方 TypeScript 封装。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @kuriyona/cecilia
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```ts
14
+ import { getPlaylistDetail, getLyric, getSongsDetail } from '@kuriyona/cecilia'
15
+ ```
16
+
17
+ ### `getPlaylistDetail(id)`
18
+
19
+ 获取歌单详情。
20
+
21
+ ```ts
22
+ const detail = await getPlaylistDetail(123)
23
+ // {
24
+ // id: 123,
25
+ // name: '歌单名',
26
+ // coverImgId: 456,
27
+ // coverImgUrl: 'https://example.com/cover.jpg',
28
+ // userId: 789,
29
+ // createTime: 1000000,
30
+ // songs: [{ id: 1, addTime: 2000000 }, ...]
31
+ // }
32
+ ```
33
+
34
+ ### `getLyric(id)`
35
+
36
+ 获取歌词。
37
+
38
+ ```ts
39
+ const lyric = await getLyric(1)
40
+ // [
41
+ // { time: 1.5, text: 'Hello' },
42
+ // { time: 5, text: 'World' },
43
+ // ]
44
+ ```
45
+
46
+ ### `getSongsDetail(ids)`
47
+
48
+ 批量获取歌曲详情。
49
+
50
+ ```ts
51
+ const songs = await getSongsDetail([1, 2])
52
+ // [
53
+ // {
54
+ // id: 1,
55
+ // name: 'Song A',
56
+ // artists: [{ id: 10, name: 'Artist 1' }],
57
+ // album: { id: 100, name: 'Album A', picUrl: '...' },
58
+ // duration: 200000,
59
+ // },
60
+ // ]
61
+ ```
62
+
63
+ ## 开发
64
+
65
+ ```bash
66
+ pnpm test # 运行测试
67
+ pnpm test:watch # 监听模式
68
+ pnpm build # 构建
69
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,90 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ //#region src/utils/mergeLyricTimelines.ts
6
+ function mergeLyricTimelines(original, translation) {
7
+ const originalMap = /* @__PURE__ */ new Map();
8
+ for (const item of original) originalMap.set(item.time, item.text);
9
+ const translationMap = /* @__PURE__ */ new Map();
10
+ for (const item of translation) translationMap.set(item.time, item.text);
11
+ const allTimes = /* @__PURE__ */ new Set();
12
+ for (const item of original) allTimes.add(item.time);
13
+ for (const item of translation) allTimes.add(item.time);
14
+ const sortedTimes = [...allTimes].sort((a, b) => a - b);
15
+ const result = [];
16
+ let lastOriginal;
17
+ let lastTranslation;
18
+ for (const time of sortedTimes) {
19
+ if (originalMap.has(time)) lastOriginal = originalMap.get(time);
20
+ if (translationMap.has(time)) lastTranslation = translationMap.get(time);
21
+ result.push({
22
+ time,
23
+ text: lastOriginal ?? "",
24
+ ...lastTranslation !== void 0 ? { translation: lastTranslation } : {}
25
+ });
26
+ }
27
+ return result;
28
+ }
29
+ //#endregion
30
+ //#region src/index.ts
31
+ const BASE_URL = "https://music.163.com/api/";
32
+ const getPlaylistDetail = async (id) => {
33
+ const data = await (await fetch(`${BASE_URL}/v6/playlist/detail?id=${id}`)).json();
34
+ return {
35
+ id: data.playlist.id,
36
+ name: data.playlist.name,
37
+ coverImgId: data.playlist.coverImgId,
38
+ coverImgUrl: data.playlist.coverImgUrl,
39
+ userId: data.playlist.userId,
40
+ createTime: data.playlist.createTime,
41
+ songs: data.playlist.trackIds.map((t) => ({
42
+ id: t.id,
43
+ addTime: t.at
44
+ }))
45
+ };
46
+ };
47
+ const parseLrc = (lrc) => lrc.split("\n").filter((l) => l.startsWith("[")).map((l) => {
48
+ const match = l.match(/^\[(\d{2}):(\d{2}(?:\.\d{2,3})?)\](.*)/);
49
+ if (!match) return null;
50
+ const minutes = parseInt(match[1], 10);
51
+ const seconds = parseFloat(match[2]);
52
+ return {
53
+ time: minutes * 60 + seconds,
54
+ text: match[3].trim()
55
+ };
56
+ }).filter((e) => e !== null);
57
+ const getLyric = async (id) => {
58
+ const data = await (await fetch(`${BASE_URL}/song/lyric?id=${id}&lv=-1&tv=-1`)).json();
59
+ return {
60
+ lines: mergeLyricTimelines(parseLrc(data.lrc.lyric), data.tlyric?.lyric ? parseLrc(data.tlyric.lyric) : []),
61
+ ...data.transUser ? { translator: data.transUser } : {}
62
+ };
63
+ };
64
+ const getSongsDetail = async (ids) => {
65
+ const query = JSON.stringify(ids.map((id) => ({ id })));
66
+ return (await (await fetch(`${BASE_URL}/v3/song/detail?c=${query}`)).json()).songs.map((s) => ({
67
+ id: s.id,
68
+ name: s.name,
69
+ artists: s.ar.map((a) => ({
70
+ id: a.id,
71
+ name: a.name
72
+ })),
73
+ album: {
74
+ id: s.al.id,
75
+ name: s.al.name,
76
+ picUrl: s.al.picUrl
77
+ },
78
+ duration: s.dt
79
+ }));
80
+ };
81
+ var src_default = {
82
+ getPlaylistDetail,
83
+ getLyric,
84
+ getSongsDetail
85
+ };
86
+ //#endregion
87
+ exports.default = src_default;
88
+ exports.getLyric = getLyric;
89
+ exports.getPlaylistDetail = getPlaylistDetail;
90
+ exports.getSongsDetail = getSongsDetail;
@@ -0,0 +1,55 @@
1
+ //#region src/types/Lyric.d.ts
2
+ interface Lyric {
3
+ lines: LyricLine[];
4
+ translator?: {
5
+ id: number;
6
+ nickname: string;
7
+ };
8
+ }
9
+ type LyricLine = {
10
+ time: number;
11
+ text: string;
12
+ translation?: string;
13
+ };
14
+ //#endregion
15
+ //#region src/types/PlaylistDetail.d.ts
16
+ interface PlaylistDetails {
17
+ id: number;
18
+ name: string;
19
+ coverImgId: number;
20
+ coverImgUrl: string;
21
+ userId: number;
22
+ createTime: number;
23
+ songs: {
24
+ id: number;
25
+ addTime: number;
26
+ }[];
27
+ }
28
+ //#endregion
29
+ //#region src/types/SongDetails.d.ts
30
+ type SongDetail = {
31
+ id: number;
32
+ name: string;
33
+ artists: {
34
+ id: number;
35
+ name: string;
36
+ }[];
37
+ album: {
38
+ id: number;
39
+ name: string;
40
+ picUrl: string;
41
+ };
42
+ duration: number;
43
+ };
44
+ //#endregion
45
+ //#region src/index.d.ts
46
+ declare const getPlaylistDetail: (id: number) => Promise<PlaylistDetails>;
47
+ declare const getLyric: (id: number) => Promise<Lyric>;
48
+ declare const getSongsDetail: (ids: number[]) => Promise<SongDetail[]>;
49
+ declare const _default: {
50
+ getPlaylistDetail: (id: number) => Promise<PlaylistDetails>;
51
+ getLyric: (id: number) => Promise<Lyric>;
52
+ getSongsDetail: (ids: number[]) => Promise<SongDetail[]>;
53
+ };
54
+ //#endregion
55
+ export { _default as default, getLyric, getPlaylistDetail, getSongsDetail };
@@ -0,0 +1,55 @@
1
+ //#region src/types/Lyric.d.ts
2
+ interface Lyric {
3
+ lines: LyricLine[];
4
+ translator?: {
5
+ id: number;
6
+ nickname: string;
7
+ };
8
+ }
9
+ type LyricLine = {
10
+ time: number;
11
+ text: string;
12
+ translation?: string;
13
+ };
14
+ //#endregion
15
+ //#region src/types/PlaylistDetail.d.ts
16
+ interface PlaylistDetails {
17
+ id: number;
18
+ name: string;
19
+ coverImgId: number;
20
+ coverImgUrl: string;
21
+ userId: number;
22
+ createTime: number;
23
+ songs: {
24
+ id: number;
25
+ addTime: number;
26
+ }[];
27
+ }
28
+ //#endregion
29
+ //#region src/types/SongDetails.d.ts
30
+ type SongDetail = {
31
+ id: number;
32
+ name: string;
33
+ artists: {
34
+ id: number;
35
+ name: string;
36
+ }[];
37
+ album: {
38
+ id: number;
39
+ name: string;
40
+ picUrl: string;
41
+ };
42
+ duration: number;
43
+ };
44
+ //#endregion
45
+ //#region src/index.d.ts
46
+ declare const getPlaylistDetail: (id: number) => Promise<PlaylistDetails>;
47
+ declare const getLyric: (id: number) => Promise<Lyric>;
48
+ declare const getSongsDetail: (ids: number[]) => Promise<SongDetail[]>;
49
+ declare const _default: {
50
+ getPlaylistDetail: (id: number) => Promise<PlaylistDetails>;
51
+ getLyric: (id: number) => Promise<Lyric>;
52
+ getSongsDetail: (ids: number[]) => Promise<SongDetail[]>;
53
+ };
54
+ //#endregion
55
+ export { _default as default, getLyric, getPlaylistDetail, getSongsDetail };
package/dist/index.mjs ADDED
@@ -0,0 +1,83 @@
1
+ //#region src/utils/mergeLyricTimelines.ts
2
+ function mergeLyricTimelines(original, translation) {
3
+ const originalMap = /* @__PURE__ */ new Map();
4
+ for (const item of original) originalMap.set(item.time, item.text);
5
+ const translationMap = /* @__PURE__ */ new Map();
6
+ for (const item of translation) translationMap.set(item.time, item.text);
7
+ const allTimes = /* @__PURE__ */ new Set();
8
+ for (const item of original) allTimes.add(item.time);
9
+ for (const item of translation) allTimes.add(item.time);
10
+ const sortedTimes = [...allTimes].sort((a, b) => a - b);
11
+ const result = [];
12
+ let lastOriginal;
13
+ let lastTranslation;
14
+ for (const time of sortedTimes) {
15
+ if (originalMap.has(time)) lastOriginal = originalMap.get(time);
16
+ if (translationMap.has(time)) lastTranslation = translationMap.get(time);
17
+ result.push({
18
+ time,
19
+ text: lastOriginal ?? "",
20
+ ...lastTranslation !== void 0 ? { translation: lastTranslation } : {}
21
+ });
22
+ }
23
+ return result;
24
+ }
25
+ //#endregion
26
+ //#region src/index.ts
27
+ const BASE_URL = "https://music.163.com/api/";
28
+ const getPlaylistDetail = async (id) => {
29
+ const data = await (await fetch(`${BASE_URL}/v6/playlist/detail?id=${id}`)).json();
30
+ return {
31
+ id: data.playlist.id,
32
+ name: data.playlist.name,
33
+ coverImgId: data.playlist.coverImgId,
34
+ coverImgUrl: data.playlist.coverImgUrl,
35
+ userId: data.playlist.userId,
36
+ createTime: data.playlist.createTime,
37
+ songs: data.playlist.trackIds.map((t) => ({
38
+ id: t.id,
39
+ addTime: t.at
40
+ }))
41
+ };
42
+ };
43
+ const parseLrc = (lrc) => lrc.split("\n").filter((l) => l.startsWith("[")).map((l) => {
44
+ const match = l.match(/^\[(\d{2}):(\d{2}(?:\.\d{2,3})?)\](.*)/);
45
+ if (!match) return null;
46
+ const minutes = parseInt(match[1], 10);
47
+ const seconds = parseFloat(match[2]);
48
+ return {
49
+ time: minutes * 60 + seconds,
50
+ text: match[3].trim()
51
+ };
52
+ }).filter((e) => e !== null);
53
+ const getLyric = async (id) => {
54
+ const data = await (await fetch(`${BASE_URL}/song/lyric?id=${id}&lv=-1&tv=-1`)).json();
55
+ return {
56
+ lines: mergeLyricTimelines(parseLrc(data.lrc.lyric), data.tlyric?.lyric ? parseLrc(data.tlyric.lyric) : []),
57
+ ...data.transUser ? { translator: data.transUser } : {}
58
+ };
59
+ };
60
+ const getSongsDetail = async (ids) => {
61
+ const query = JSON.stringify(ids.map((id) => ({ id })));
62
+ return (await (await fetch(`${BASE_URL}/v3/song/detail?c=${query}`)).json()).songs.map((s) => ({
63
+ id: s.id,
64
+ name: s.name,
65
+ artists: s.ar.map((a) => ({
66
+ id: a.id,
67
+ name: a.name
68
+ })),
69
+ album: {
70
+ id: s.al.id,
71
+ name: s.al.name,
72
+ picUrl: s.al.picUrl
73
+ },
74
+ duration: s.dt
75
+ }));
76
+ };
77
+ var src_default = {
78
+ getPlaylistDetail,
79
+ getLyric,
80
+ getSongsDetail
81
+ };
82
+ //#endregion
83
+ export { src_default as default, getLyric, getPlaylistDetail, getSongsDetail };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@kuriyona/cecilia",
3
+ "version": "0.2.0",
4
+ "description": "网易云音乐 API 的非官方 TypeScript 封装",
5
+ "keywords": [
6
+ "api",
7
+ "music",
8
+ "netease",
9
+ "typescript"
10
+ ],
11
+ "homepage": "https://github.com/Kuriyona/Cecilia",
12
+ "bugs": {
13
+ "url": "https://github.com/Kuriyona/Cecilia/issues"
14
+ },
15
+ "license": "MIT",
16
+ "author": "Kuriyona <kuriyona@outlook.com>",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/Kuriyona/Cecilia.git"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.cjs",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.mjs",
29
+ "require": "./dist/index.cjs",
30
+ "types": "./dist/index.d.ts"
31
+ }
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "devDependencies": {
37
+ "tsdown": "^0.22.1",
38
+ "typescript": "^6.0.3",
39
+ "vitest": "^4.1.7"
40
+ },
41
+ "devEngines": {
42
+ "packageManager": {
43
+ "name": "pnpm",
44
+ "version": "^11.4.0",
45
+ "onFail": "download"
46
+ }
47
+ },
48
+ "email": "kuriyona@outlook.com",
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "test": "vitest run",
52
+ "test:watch": "vitest"
53
+ }
54
+ }