移除歌词文件分离

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)
}
const timeExp = /^\[([\d:.]*)\]{1}/
// const timeExp = /^\[([\d:.]*)\]{1}/
/**
*
* @param lrc
* @returns
*/
export const parseLyric = (lrc: string): LX.Music.LyricInfo => {
const lines = lrc.split(/\r\n|\r|\n/)
const lyrics: string[][] = []
const map = new Map<string, number>()
// export const parseLyric = (lrc: string): LX.Music.LyricInfo => {
// const lines = lrc.split(/\r\n|\r|\n/)
// const lyrics: string[][] = []
// const map = new Map<string, number>()
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim()
let result = timeExp.exec(line)
if (result) {
const index = map.get(result[1]) ?? 0
if (!lyrics[index]) lyrics[index] = []
lyrics[index].push(line)
map.set(result[1], index + 1)
} else {
if (!lyrics[0]) lyrics[0] = []
lyrics[0].push(line)
}
}
const lyricInfo: LX.Music.LyricInfo = {
lyric: lyrics[0].join('\n'),
tlyric: '',
}
if (lyrics[1]) lyricInfo.tlyric = lyrics[1].join('\n')
if (lyrics[2]) lyricInfo.rlyric = lyrics[2].join('\n')
// for (let i = 0; i < lines.length; i++) {
// const line = lines[i].trim()
// let result = timeExp.exec(line)
// if (result) {
// const index = map.get(result[1]) ?? 0
// if (!lyrics[index]) lyrics[index] = []
// lyrics[index].push(line)
// map.set(result[1], index + 1)
// } else {
// if (!lyrics[0]) lyrics[0] = []
// lyrics[0].push(line)
// }
// }
// const lyricInfo: LX.Music.LyricInfo = {
// lyric: lyrics[0].join('\n'),
// tlyric: '',
// }
// if (lyrics[1]) lyricInfo.tlyric = lyrics[1].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) => {
@ -10,5 +10,7 @@ export const getMusicFilePic = async(filePath: string) => {
export const getMusicFileLyric = async(filePath: string): Promise<LX.Music.LyricInfo | null> => {
const lyric = await getLocalMusicFileLyric(filePath)
if (!lyric) return null
return parseLyric(lyric)
return {
lyric,
}
}