Skip to content

Commit 1f7d199

Browse files
committed
feat: add subtitle parsing error prompt
1 parent 0323d66 commit 1f7d199

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

electron-builder.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ afterPack: scripts/cleaned-unused-arch-deps.js
6868
afterSign: scripts/notarize.js
6969
releaseInfo:
7070
releaseNotes: |
71-
优化提示信息
72-
修复改变窗口大小字幕消失的问题
71+
优化导入字幕提示信息
72+
修复改变窗口大小后字幕消失的问题
7373

src/main/lib/ffmpeg.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,28 @@ export default class FFmpeg {
9696
.on('end', () => {
9797
resolve(outputPath)
9898
})
99-
.on('error', (err) => {
100-
reject(err)
99+
.on('error', async (ffmpegError) => {
100+
ffmpeg.ffprobe(this.ffmpeg._inputs[0].source, (err, metadata) => {
101+
if (err) {
102+
return reject(err)
103+
}
104+
105+
const subtitleStream = metadata.streams
106+
.filter((stream) => stream.codec_type === 'subtitle')
107+
.at(index)
108+
109+
if (!subtitleStream) {
110+
return reject(new Error('解析内嵌字幕发生错误'))
111+
}
112+
// 检查是否为 PGS 字幕
113+
if (
114+
subtitleStream.codec_name?.toLowerCase()?.includes('pgs') ||
115+
subtitleStream.codec_tag_string?.toLowerCase()?.includes('pgs')
116+
) {
117+
return reject(new Error('不支持加载「位图字幕」'))
118+
}
119+
reject(ffmpegError)
120+
})
101121
})
102122
})
103123
}

src/renderer/src/components/modules/player/setting/items/subtitle/hooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ export const useSubtitle = () => {
156156
})
157157
const subtitlePath = subtitleData?.data
158158
if (!subtitlePath || !data?.tags?.[index]) {
159+
const message = subtitleData?.message ?? '视频内嵌字幕加载失败'
159160
toast({
160-
title: '视频内嵌字幕加载失败',
161+
title: message
161162
})
162-
throw new Error(subtitleData?.message ?? '字幕加载失败')
163+
throw new Error(message)
163164
}
164165

165166
const newTags = [

0 commit comments

Comments
 (0)