feat: open selected YouTube video in browser

This commit is contained in:
2026-10-17 16:54:23 +02:00
parent f8334716af
commit ba04cbe158
4 changed files with 94 additions and 0 deletions
+32
View File
@@ -948,6 +948,7 @@ struct App {
description_viewport: Option<(u16, u16)>,
job: Option<Job>,
player_launch: Option<PlayerLaunch>,
browser_launch: Option<std::sync::mpsc::Receiver<Result<(), String>>>,
status: String,
}
@@ -1023,6 +1024,7 @@ impl App {
description_viewport: None,
job: None,
player_launch: None,
browser_launch: None,
status: "Enter a query to search YouTube.".into(),
}
}
@@ -2553,6 +2555,24 @@ impl App {
}
}
fn open_video_in_browser(&mut self) {
let view = &self.views[self.view_index];
let Some(video) = view
.selection
.selected()
.and_then(|index| view.videos.get(index))
else {
return;
};
match youtube::open_in_browser(&video.id) {
Ok(launch) => {
self.browser_launch = Some(launch);
self.status = format!("Opening {} in the default browser...", video.title);
}
Err(error) => self.status = error.to_string(),
}
}
fn finish_description(&mut self, id: String, result: Result<String, String>) {
match result.and_then(|output| youtube::full_description(&output, &id)) {
Ok(description) => self.remember_description(id, description),
@@ -2601,6 +2621,17 @@ impl App {
Err(error) => error,
};
}
if let Some(result) = self
.browser_launch
.as_ref()
.and_then(|launch| launch.try_recv().ok())
{
self.browser_launch = None;
self.status = match result {
Ok(()) => "Video handed to the default browser.".into(),
Err(error) => error,
};
}
match self.video_state.poll_progress() {
Ok(true) => {
self.rebuild_collections();
@@ -2869,6 +2900,7 @@ impl App {
self.browse_category_collection(CollectionKind::Saved)
}
Some(Action::VideoPlay) => self.play(),
Some(Action::VideoOpen) => self.open_video_in_browser(),
Some(Action::VideoNext) => {
self.views[self.view_index].prefetch_requested = true;
self.views[self.view_index].selection.select_next();