From 4a0e1aa72c251109c07c5163f742a242ce7f38bb Mon Sep 17 00:00:00 2001 From: solidDoWant Date: Wed, 7 May 2025 15:51:43 -0500 Subject: [PATCH] Cleanly handle unsupported subtitles (#944) --- .../src/player/components/right-buttons.tsx | 20 ++++++++++--------- front/packages/ui/src/player/video.tsx | 14 +++++++------ transcoder/src/extract.go | 11 ++++++++-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/front/packages/ui/src/player/components/right-buttons.tsx b/front/packages/ui/src/player/components/right-buttons.tsx index 57c17fa5..74718a85 100644 --- a/front/packages/ui/src/player/components/right-buttons.tsx +++ b/front/packages/ui/src/player/components/right-buttons.tsx @@ -71,15 +71,17 @@ export const RightButtons = ({ selected={!selectedSubtitle} onSelect={() => setSubtitle(null)} /> - {subtitles.map((x, i) => ( - setSubtitle(x)} - /> - ))} + {subtitles + .filter((x) => !!x.link) + .map((x, i) => ( + setSubtitle(x)} + /> + ))} )} (function Video( } // when video file is invalid, audio is undefined selectedAudioTrack={{ type: SelectedTrackType.INDEX, value: audio?.index ?? 0 }} - textTracks={subtitles?.map((x) => ({ - type: MimeTypes.get(x.codec) as any, - uri: x.link!, - title: x.title ?? "Unknown", - language: x.language ?? ("Unknown" as any), - }))} + textTracks={subtitles + ?.filter((x) => !!x.link) + .map((x) => ({ + type: MimeTypes.get(x.codec) as any, + uri: x.link!, + title: x.title ?? "Unknown", + language: x.language ?? ("Unknown" as any), + }))} selectedTextTrack={ subtitle ? { diff --git a/transcoder/src/extract.go b/transcoder/src/extract.go index 2d225fb5..2fd3e479 100644 --- a/transcoder/src/extract.go +++ b/transcoder/src/extract.go @@ -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) { defer utils.PrintExecTime("extraction of %s", info.Path)() - // If there is no subtitles, there is nothing to extract (also fonts would be useless). - if len(info.Subtitles) == 0 { + // If there are no supported, embedded subtitles, there is nothing to extract. + hasSupportedSubtitle := false + for _, sub := range info.Subtitles { + if !sub.IsExternal && sub.Extension != nil { + hasSupportedSubtitle = true + break + } + } + if !hasSupportedSubtitle { return nil }