移除歌词文件分离
parent
358b93fb70
commit
72418194e9
|
@ -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
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue