移除歌词文件分离

pull/1050/head
lyswhut 2022-10-29 13:20:11 +08:00
parent 358b93fb70
commit 72418194e9
2 changed files with 30 additions and 28 deletions

View File

@ -118,39 +118,39 @@ export const getLocalMusicFilePic = async(path: string) => {
return selectCover(metadata.common.picture) return selectCover(metadata.common.picture)
} }
const timeExp = /^\[([\d:.]*)\]{1}/ // const timeExp = /^\[([\d:.]*)\]{1}/
/** /**
* *
* @param lrc * @param lrc
* @returns * @returns
*/ */
export const parseLyric = (lrc: string): LX.Music.LyricInfo => { // export const parseLyric = (lrc: string): LX.Music.LyricInfo => {
const lines = lrc.split(/\r\n|\r|\n/) // const lines = lrc.split(/\r\n|\r|\n/)
const lyrics: string[][] = [] // const lyrics: string[][] = []
const map = new Map<string, number>() // const map = new Map<string, number>()
for (let i = 0; i < lines.length; i++) { // for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim() // const line = lines[i].trim()
let result = timeExp.exec(line) // let result = timeExp.exec(line)
if (result) { // if (result) {
const index = map.get(result[1]) ?? 0 // const index = map.get(result[1]) ?? 0
if (!lyrics[index]) lyrics[index] = [] // if (!lyrics[index]) lyrics[index] = []
lyrics[index].push(line) // lyrics[index].push(line)
map.set(result[1], index + 1) // map.set(result[1], index + 1)
} else { // } else {
if (!lyrics[0]) lyrics[0] = [] // if (!lyrics[0]) lyrics[0] = []
lyrics[0].push(line) // lyrics[0].push(line)
} // }
} // }
const lyricInfo: LX.Music.LyricInfo = { // const lyricInfo: LX.Music.LyricInfo = {
lyric: lyrics[0].join('\n'), // lyric: lyrics[0].join('\n'),
tlyric: '', // tlyric: '',
} // }
if (lyrics[1]) lyricInfo.tlyric = lyrics[1].join('\n') // if (lyrics[1]) lyricInfo.tlyric = lyrics[1].join('\n')
if (lyrics[2]) lyricInfo.rlyric = lyrics[2].join('\n') // if (lyrics[2]) lyricInfo.rlyric = lyrics[2].join('\n')
return lyricInfo // return lyricInfo
} // }
/** /**

View File

@ -1,4 +1,4 @@
import { getLocalMusicFileLyric, getLocalMusicFilePic, parseLyric } from '@renderer/utils/music' import { getLocalMusicFileLyric, getLocalMusicFilePic } from '@renderer/utils/music'
export const getMusicFilePic = async(filePath: string) => { export const getMusicFilePic = async(filePath: string) => {
@ -10,5 +10,7 @@ export const getMusicFilePic = async(filePath: string) => {
export const getMusicFileLyric = async(filePath: string): Promise<LX.Music.LyricInfo | null> => { export const getMusicFileLyric = async(filePath: string): Promise<LX.Music.LyricInfo | null> => {
const lyric = await getLocalMusicFileLyric(filePath) const lyric = await getLocalMusicFileLyric(filePath)
if (!lyric) return null if (!lyric) return null
return parseLyric(lyric) return {
lyric,
}
} }