mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
fix(views/library): better lyric-picking logic (#1143)
* fix(views/library): better lyric-picking logic * feat(views/library): filter out lines with "作詞" and "作曲" included
This commit is contained in:
parent
c59a100d4c
commit
767e2073b3
1 changed files with 34 additions and 11 deletions
|
|
@ -183,6 +183,16 @@ import CoverRow from '@/components/CoverRow.vue';
|
||||||
import SvgIcon from '@/components/SvgIcon.vue';
|
import SvgIcon from '@/components/SvgIcon.vue';
|
||||||
import MvRow from '@/components/MvRow.vue';
|
import MvRow from '@/components/MvRow.vue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pick the lyric part from a string formed in `[timecode] lyric`.
|
||||||
|
*
|
||||||
|
* @param {string} rawLyric The raw lyric string formed in `[timecode] lyric`
|
||||||
|
* @returns {string} The lyric part
|
||||||
|
*/
|
||||||
|
function extractLyricPart(rawLyric) {
|
||||||
|
return rawLyric.split(']')[1].trim();
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Library',
|
name: 'Library',
|
||||||
components: { SvgIcon, CoverRow, TrackList, MvRow, ContextMenu },
|
components: { SvgIcon, CoverRow, TrackList, MvRow, ContextMenu },
|
||||||
|
|
@ -196,18 +206,31 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['data', 'liked']),
|
...mapState(['data', 'liked']),
|
||||||
|
/**
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
pickedLyric() {
|
pickedLyric() {
|
||||||
if (this.lyric === undefined) return '';
|
/** @type {string?} */
|
||||||
let lyric = this.lyric.split('\n');
|
const lyric = this.lyric;
|
||||||
let lineIndex = randomNum(0, lyric.length - 1);
|
|
||||||
while (lineIndex + 4 > lyric.length) {
|
// Returns [] if we got no lyrics.
|
||||||
lineIndex = randomNum(0, lyric.length - 1);
|
if (!lyric) return [];
|
||||||
}
|
|
||||||
return [
|
const lyricLine = lyric
|
||||||
lyric[lineIndex].split(']')[1],
|
.split('\n')
|
||||||
lyric[lineIndex + 1].split(']')[1],
|
.filter(line => !line.includes('作词') && !line.includes('作曲'));
|
||||||
lyric[lineIndex + 2].split(']')[1],
|
|
||||||
];
|
// Pick 3 or fewer lyrics based on the lyric lines.
|
||||||
|
const lyricsToPick = Math.min(lyricLine.length, 3);
|
||||||
|
|
||||||
|
// The upperbound of the lyric line to pick
|
||||||
|
const randomUpperBound = lyricLine.length - lyricsToPick;
|
||||||
|
const startLyricLineIndex = randomNum(0, randomUpperBound - 1);
|
||||||
|
|
||||||
|
// Pick lyric lines to render.
|
||||||
|
return lyricLine
|
||||||
|
.slice(startLyricLineIndex, startLyricLineIndex + lyricsToPick)
|
||||||
|
.map(extractLyricPart);
|
||||||
},
|
},
|
||||||
playlistFilter() {
|
playlistFilter() {
|
||||||
return this.data.libraryPlaylistFilter || 'all';
|
return this.data.libraryPlaylistFilter || 'all';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue