Skip to content

Commit c1e98b2

Browse files
authored
feat: 云盘歌曲显示内嵌歌词 (#2419)
1 parent e6933bd commit c1e98b2

4 files changed

Lines changed: 68 additions & 4 deletions

File tree

src/api/track.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,39 @@ export function getLyric(id) {
9494
});
9595
}
9696

97+
/**
98+
* 获取云盘歌曲内嵌歌词 * 说明 : 调用此接口 , 传入音乐 id 可获得云盘歌曲的内嵌歌词
99+
* @param {number} songId - 音乐 id
100+
* @param {number} userId - 用户 id
101+
*/
102+
export function getCloudLyric(songId, userId) {
103+
const fetchLatest = () => {
104+
return request({
105+
url: '/api',
106+
method: 'get',
107+
params: {
108+
uri: `/api/cloud/lyric/get`,
109+
data: {
110+
songId,
111+
userId,
112+
lv: '-1',
113+
kv: '-1',
114+
},
115+
crypto: 'eapi',
116+
},
117+
}).then(result => {
118+
cacheLyric(songId, result);
119+
return result;
120+
});
121+
};
122+
123+
fetchLatest();
124+
125+
return getLyricFromCache(songId).then(result => {
126+
return result ?? fetchLatest();
127+
});
128+
}
129+
97130
/**
98131
* 新歌速递
99132
* 说明 : 调用此接口 , 可获取新歌速递

src/ncmModDef.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,4 +614,9 @@ module.exports = [
614614
route: '/activate/init/profile',
615615
module: require('@neteaseapireborn/api/module/activate_init_profile'),
616616
},
617+
{
618+
identifier: 'api',
619+
route: '/api',
620+
module: require('@neteaseapireborn/api/module/api'),
621+
},
617622
];

src/utils/lyrics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const extractTimestampRegex =
2525
* @returns {ParsedLyric[]} The parsed lyric.
2626
* @example parseLyric("[00:00.00] Hello, World!\n[00:00.10] Test\n");
2727
*/
28-
function parseLyric(lrc) {
28+
export function parseLyric(lrc) {
2929
/**
3030
* A sorted list of parsed lyric and its timestamp.
3131
*

src/views/lyrics.vue

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ import { mapState, mapMutations, mapActions } from 'vuex';
306306
import VueSlider from 'vue-slider-component';
307307
import ContextMenu from '@/components/ContextMenu.vue';
308308
import { formatTrackTime } from '@/utils/common';
309-
import { getLyric } from '@/api/track';
310-
import { lyricParser, copyLyric } from '@/utils/lyrics';
309+
import { getLyric, getCloudLyric } from '@/api/track';
310+
import { lyricParser, copyLyric, parseLyric } from '@/utils/lyrics';
311311
import ButtonIcon from '@/components/ButtonIcon.vue';
312312
import * as Vibrant from 'node-vibrant/dist/vibrant.worker.min.js';
313313
import Color from 'color';
@@ -544,6 +544,23 @@ export default {
544544
},
545545
getLyric() {
546546
if (!this.currentTrack.id) return;
547+
if (
548+
this.currentTrack.pc !== null &&
549+
this.currentTrack.cd === null &&
550+
this.$store.state.data.user?.userId
551+
) {
552+
//云盘未设置关联的歌曲获取其内置歌词
553+
return getCloudLyric(
554+
this.currentTrack.id,
555+
this.$store.state.data.user?.userId
556+
).then(data => {
557+
this.tlyric = [];
558+
this.romalyric = [];
559+
this.lyric = data?.lrc?.length > 0 ? parseLyric(data.lrc) : [];
560+
this.lyricType = 'translation';
561+
return true;
562+
});
563+
}
547564
return getLyric(this.currentTrack.id).then(data => {
548565
if (!data?.lrc?.lyric) {
549566
this.lyric = [];
@@ -708,6 +725,7 @@ export default {
708725
position: absolute;
709726
height: 100vh;
710727
width: 100vw;
728+
711729
.top-right,
712730
.bottom-left {
713731
z-index: 0;
@@ -740,6 +758,7 @@ export default {
740758
0% {
741759
transform: rotate(0deg);
742760
}
761+
743762
100% {
744763
transform: rotate(360deg);
745764
}
@@ -814,6 +833,7 @@ export default {
814833
margin: 0 10px;
815834
display: flex;
816835
align-items: center;
836+
817837
.volume-bar {
818838
width: 84px;
819839
}
@@ -895,6 +915,7 @@ export default {
895915
width: 22px;
896916
}
897917
}
918+
898919
.lyric-switch-icon {
899920
color: var(--color-text);
900921
font-size: 14px;
@@ -990,6 +1011,7 @@ export default {
9901011
9911012
.highlight div.content {
9921013
transform: scale(1);
1014+
9931015
span {
9941016
opacity: 0.98;
9951017
display: inline-block;
@@ -1054,6 +1076,7 @@ export default {
10541076
.left-side {
10551077
display: none;
10561078
}
1079+
10571080
.right-side .lyrics-container {
10581081
max-width: 100%;
10591082
}
@@ -1070,7 +1093,10 @@ export default {
10701093
transition: all 0.4s;
10711094
}
10721095
1073-
.slide-up-enter, .slide-up-leave-to /* .fade-leave-active below version 2.1.8 */ {
1096+
.slide-up-enter,
1097+
.slide-up-leave-to
1098+
1099+
/* .fade-leave-active below version 2.1.8 */ {
10741100
transform: translateY(100%);
10751101
}
10761102

0 commit comments

Comments
 (0)