Cleanly handle unsupported subtitles (#944)

This commit is contained in:
solidDoWant 2025-05-07 15:51:43 -05:00 committed by GitHub
parent 27a4fc328e
commit 4a0e1aa72c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 17 deletions

View File

@ -71,15 +71,17 @@ export const RightButtons = ({
selected={!selectedSubtitle} selected={!selectedSubtitle}
onSelect={() => setSubtitle(null)} onSelect={() => setSubtitle(null)}
/> />
{subtitles.map((x, i) => ( {subtitles
<Menu.Item .filter((x) => !!x.link)
key={x.index ?? i} .map((x, i) => (
label={x.link ? getSubtitleName(x) : `${getSubtitleName(x)} (${x.codec})`} <Menu.Item
selected={selectedSubtitle === x} key={x.index ?? i}
disabled={!x.link} label={x.link ? getSubtitleName(x) : `${getSubtitleName(x)} (${x.codec})`}
onSelect={() => setSubtitle(x)} selected={selectedSubtitle === x}
/> disabled={!x.link}
))} onSelect={() => setSubtitle(x)}
/>
))}
</Menu> </Menu>
)} )}
<AudiosMenu <AudiosMenu

View File

@ -109,12 +109,14 @@ const Video = forwardRef<VideoRef, VideoProps>(function Video(
} }
// when video file is invalid, audio is undefined // when video file is invalid, audio is undefined
selectedAudioTrack={{ type: SelectedTrackType.INDEX, value: audio?.index ?? 0 }} selectedAudioTrack={{ type: SelectedTrackType.INDEX, value: audio?.index ?? 0 }}
textTracks={subtitles?.map((x) => ({ textTracks={subtitles
type: MimeTypes.get(x.codec) as any, ?.filter((x) => !!x.link)
uri: x.link!, .map((x) => ({
title: x.title ?? "Unknown", type: MimeTypes.get(x.codec) as any,
language: x.language ?? ("Unknown" as any), uri: x.link!,
}))} title: x.title ?? "Unknown",
language: x.language ?? ("Unknown" as any),
}))}
selectedTextTrack={ selectedTextTrack={
subtitle subtitle
? { ? {

View File

@ -63,8 +63,15 @@ func (s *MetadataService) GetSubtitle(ctx context.Context, sha string, name stri
func (s *MetadataService) extractSubs(ctx context.Context, info *MediaInfo) (err error) { func (s *MetadataService) extractSubs(ctx context.Context, info *MediaInfo) (err error) {
defer utils.PrintExecTime("extraction of %s", info.Path)() defer utils.PrintExecTime("extraction of %s", info.Path)()
// If there is no subtitles, there is nothing to extract (also fonts would be useless). // If there are no supported, embedded subtitles, there is nothing to extract.
if len(info.Subtitles) == 0 { hasSupportedSubtitle := false
for _, sub := range info.Subtitles {
if !sub.IsExternal && sub.Extension != nil {
hasSupportedSubtitle = true
break
}
}
if !hasSupportedSubtitle {
return nil return nil
} }