fix(views/library): better lyric-picking logic (#1143)

* fix(views/library): better lyric-picking logic

* feat(views/library): filter out lines with "作詞" and "作曲" included
master
pan93412 4 years ago committed by GitHub
parent f5cdbea379
commit d153810205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save