cosmic_applet_avestruz/handlers/
video.rs1use cosmic::prelude::*;
11
12use crate::fl;
13use crate::messages::Message;
14use crate::state::AppModel;
15use crate::youtube::{self, FindError};
16
17impl AppModel {
18 pub fn handle_video_press(&mut self, url: String) -> Task<cosmic::Action<Message>> {
22 match self.videos.press(&url) {
23 Some(video) => Task::perform(youtube::find_stream(video), move |result| {
24 cosmic::Action::App(Message::VideoFound(url.clone(), result))
25 }),
26 None => Task::none(),
27 }
28 }
29
30 pub fn handle_video_found(&mut self, url: &str, result: Result<String, FindError>) {
34 let stream = result.map_err(|e| {
35 tracing::warn!("no stream of a YouTube video was found: {e:?}");
36 match e {
37 FindError::NotInstalled => fl!("video-ytdlp-missing"),
38 FindError::TimedOut => fl!("video-ytdlp-slow"),
39 FindError::NoRuntime => fl!("video-ytdlp-runtime"),
40 FindError::Failed(why) => fl!("video-ytdlp-failed", error = why),
41 }
42 });
43 self.videos.found(url, stream);
44 }
45}