记录添加失败的歌曲文件名

This commit is contained in:
lyswhut 2023-12-13 16:07:07 +08:00
parent 6214318d1c
commit f5a4784bb2
3 changed files with 20 additions and 10 deletions

View File

@ -87,7 +87,8 @@
"list_select_local_file": "add local songs", "list_select_local_file": "add local songs",
"list_select_local_file_desc": "Select local song folder", "list_select_local_file_desc": "Select local song folder",
"list_select_local_file_empty_tip": "No songs found in current directory", "list_select_local_file_empty_tip": "No songs found in current directory",
"list_select_local_file_result_tip": "A total of {total} songs were found, {success} were successfully added, and {failed} were added", "list_select_local_file_result_failed_tip": "A total of {total} songs were found, {success} were added successfully, and {failed} were added. You can go to the error log to view the songs that failed to be added.",
"list_select_local_file_result_tip": "{Total} songs found, all added!",
"list_select_range": "range", "list_select_range": "range",
"list_select_single": "Single Select", "list_select_single": "Single Select",
"list_select_unall": "Reverse Selection", "list_select_unall": "Reverse Selection",

View File

@ -87,7 +87,8 @@
"list_select_local_file": "添加本地歌曲", "list_select_local_file": "添加本地歌曲",
"list_select_local_file_desc": "选择本地歌曲文件夹", "list_select_local_file_desc": "选择本地歌曲文件夹",
"list_select_local_file_empty_tip": "没有在当前目录中发现歌曲", "list_select_local_file_empty_tip": "没有在当前目录中发现歌曲",
"list_select_local_file_result_tip": "共发现 {total} 首歌曲,成功添加 {success} 首,失败 {failed} 首", "list_select_local_file_result_failed_tip": "共发现 {total} 首歌曲,成功添加 {success} 首,失败 {failed} 首,可到错误日志查看添加失败的歌曲",
"list_select_local_file_result_tip": "共发现 {total} 首歌曲,已全部添加!",
"list_select_range": "区间", "list_select_range": "区间",
"list_select_single": "单选", "list_select_single": "单选",
"list_select_unall": "反选", "list_select_unall": "反选",

View File

@ -105,27 +105,35 @@ const buildLocalMusicInfo = (filePath: string, metadata: MusicMetadata): LX.Musi
}, },
} }
} }
const createLocalMusicInfos = async(filePaths: string[]): Promise<LX.Music.MusicInfoLocal[]> => { const createLocalMusicInfos = async(filePaths: string[], errorPath: string[]): Promise<LX.Music.MusicInfoLocal[]> => {
const list: LX.Music.MusicInfoLocal[] = [] const list: LX.Music.MusicInfoLocal[] = []
for await (const path of filePaths) { for await (const path of filePaths) {
const musicInfo = await readMetadata(path) const musicInfo = await readMetadata(path)
if (!musicInfo) continue if (!musicInfo) {
errorPath.push(path)
continue
}
list.push(buildLocalMusicInfo(path, musicInfo)) list.push(buildLocalMusicInfo(path, musicInfo))
} }
return list return list
} }
const handleAddMusics = async(listId: string, filePaths: string[], index: number = -1, total: number = 0, successNum = 0) => { const handleAddMusics = async(listId: string, filePaths: string[], index: number = -1, total: number = 0, errorPath: string[] = []) => {
// console.log(index + 1, index + 201) // console.log(index + 1, index + 201)
if (!total) total = filePaths.length if (!total) total = filePaths.length
const paths = filePaths.slice(index + 1, index + 201) const paths = filePaths.slice(index + 1, index + 201)
const musicInfos = await createLocalMusicInfos(paths) const musicInfos = await createLocalMusicInfos(paths, errorPath)
successNum += musicInfos.length
if (musicInfos.length) await addListMusics(listId, musicInfos, settingState.setting['list.addMusicLocationType']) if (musicInfos.length) await addListMusics(listId, musicInfos, settingState.setting['list.addMusicLocationType'])
index += 200 index += 200
if (filePaths.length - 1 > index) await handleAddMusics(listId, filePaths, index, total, successNum) if (filePaths.length - 1 > index) await handleAddMusics(listId, filePaths, index, total, errorPath)
else {
toast(global.i18n.t('list_select_local_file_result_tip', { total, success: successNum, failed: total - successNum }), 'long') if (errorPath.length) {
log.warn('Parse metadata failed:\n' + errorPath.map(p => p.split('/').at(-1)).join('\n'))
toast(global.i18n.t('list_select_local_file_result_failed_tip', { total, success: total - errorPath.length, failed: errorPath.length }), 'long')
} else {
toast(global.i18n.t('list_select_local_file_result_tip', { total }), 'long')
}
}
} }
export const handleImportMediaFile = async(listInfo: LX.List.MyListInfo, path: string) => { export const handleImportMediaFile = async(listInfo: LX.List.MyListInfo, path: string) => {
setFetchingListStatus(listInfo.id, true) setFetchingListStatus(listInfo.id, true)