about summary refs log tree commit diff
path: root/src/app.rs
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2025-12-25 11:05:19 +0100
committerMalte Voos <git@mal.tc>2025-12-25 11:05:19 +0100
commitbb641f353c3dd81f5e3b16ecaf1fae669b3ac67b (patch)
tree51def81474c6cd861fa98519c2b20b6d9f892ded /src/app.rs
parentc347b6133365dcf1b7da4e77890b20d04d6cfba4 (diff)
downloadlleap-bb641f353c3dd81f5e3b16ecaf1fae669b3ac67b.tar.gz
lleap-bb641f353c3dd81f5e3b16ecaf1fae669b3ac67b.zip
fix whisper subtitles not appearing in subtitle selection menu
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/app.rs b/src/app.rs
index bdb2ef9..49efd49 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -13,6 +13,7 @@ use crate::{
     subtitle_view::{SubtitleView, SubtitleViewMsg, SubtitleViewOutput},
     subtitles::{
         MetadataCollection, SUBTITLE_TRACKS, StreamIndex, SubtitleCue, SubtitleTrack,
+        TrackMetadata,
         extraction::{SubtitleExtractor, SubtitleExtractorMsg, SubtitleExtractorOutput},
         state::SubtitleState,
     },
@@ -181,8 +182,8 @@ impl SimpleComponent for App {
             AppMsg::AddCue(stream_ix, cue) => {
                 SUBTITLE_TRACKS
                     .write()
-                    .get_mut(&stream_ix)
-                    .unwrap()
+                    .entry(stream_ix)
+                    .or_insert(SubtitleTrack::default())
                     .push_cue(cue.clone());
 
                 self.transcript
@@ -245,9 +246,23 @@ impl SimpleComponent for App {
             }
             AppMsg::Play {
                 url,
-                metadata,
+                mut metadata,
                 whisper_stream_index,
             } => {
+                if let Some(ix) = whisper_stream_index {
+                    let audio_metadata = metadata.audio.get(&ix).unwrap();
+                    let subs_metadata = TrackMetadata {
+                        language: audio_metadata.language,
+                        title: Some(match &audio_metadata.title {
+                            Some(title) => {
+                                format!("Auto-generated from audio (Whisper): {}", title)
+                            }
+                            None => "Auto-generated from audio (Whisper)".to_string(),
+                        }),
+                    };
+                    metadata.subtitles.insert(ix, subs_metadata);
+                }
+
                 self.player
                     .sender()
                     .send(PlayerMsg::SetUrl(url.clone()))