ytextract/youtube/browse/
mod.rs

1use super::Text;
2use serde::Deserialize;
3
4pub mod channel;
5pub mod playlist;
6
7#[derive(Deserialize)]
8#[serde(rename_all = "camelCase", untagged)]
9pub enum Result<T> {
10    Error { alerts: (Alert,) },
11    Ok(T),
12}
13
14impl<T> Result<T> {
15    pub fn into_std(self) -> crate::Result<T> {
16        match self {
17            Self::Error { alerts } => {
18                assert_eq!(alerts.0.alert_renderer.r#type, "ERROR");
19
20                Err(crate::Error::Youtube(crate::error::Youtube(
21                    alerts.0.alert_renderer.text(),
22                )))
23            }
24            Self::Ok(ok) => Ok(ok),
25        }
26    }
27}
28
29#[derive(Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct Alert {
32    pub alert_renderer: AlertRenderer,
33}
34
35#[derive(Deserialize)]
36pub struct AlertRenderer {
37    pub r#type: String,
38    pub text: Text,
39}
40
41impl AlertRenderer {
42    fn text(self) -> String {
43        match self.text {
44            Text::SimpleText(simple_text) => simple_text.simple_text,
45            Text::Runs(mut runs) => runs.runs.swap_remove(0).text,
46        }
47    }
48}