fix: handle playlist not found

This commit is contained in:
ThetaDev 2022-10-11 19:50:43 +02:00
parent de9e3c6ed9
commit 79b7fcf92c
5 changed files with 49 additions and 23 deletions

View file

@ -25,6 +25,7 @@ pub use channel_rss::ChannelRss;
use serde::Deserialize;
use serde_with::{json::JsonString, serde_as, DefaultOnError, VecSkipError};
use crate::error::ExtractionError;
use crate::serializer::{
ignore_any,
text::{Text, TextComponent},
@ -471,3 +472,16 @@ impl IsShort for Vec<TimeOverlay> {
})
}
}
pub fn alerts_to_err(alerts: Option<Vec<Alert>>) -> ExtractionError {
match alerts {
Some(alerts) => ExtractionError::ContentUnavailable(
alerts
.into_iter()
.map(|a| a.alert_renderer.text)
.collect::<Vec<_>>()
.join(" "),
),
None => ExtractionError::InvalidData("no contents".into()),
}
}

View file

@ -5,14 +5,17 @@ use serde_with::{DefaultOnError, VecSkipError};
use crate::serializer::text::{Text, TextComponent};
use crate::serializer::{MapResult, VecLogError};
use super::{ContentRenderer, ContentsRenderer, ThumbnailsWrap, VideoListItem};
use super::{Alert, ContentRenderer, ContentsRenderer, ThumbnailsWrap, VideoListItem};
#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Playlist {
pub contents: Contents,
pub header: Header,
pub contents: Option<Contents>,
pub header: Option<Header>,
pub sidebar: Option<Sidebar>,
#[serde_as(as = "Option<DefaultOnError>")]
pub alerts: Option<Vec<Alert>>,
}
#[serde_as]