fix!: parse full video info from playlist items, remove PlaylistVideo model
This commit is contained in:
parent
54f42bcb54
commit
bf80db8a9a
21 changed files with 105688 additions and 42159 deletions
|
|
@ -1,16 +1,10 @@
|
|||
use serde::Deserialize;
|
||||
use serde_with::{
|
||||
json::JsonString, rust::deserialize_ignore_any, serde_as, DefaultOnError, VecSkipError,
|
||||
};
|
||||
use serde_with::{serde_as, DefaultOnError};
|
||||
|
||||
use crate::serializer::{
|
||||
text::{Text, TextComponent},
|
||||
MapResult,
|
||||
};
|
||||
use crate::util::MappingError;
|
||||
use crate::serializer::text::{Text, TextComponent};
|
||||
|
||||
use super::{
|
||||
Alert, ContentsRenderer, ContinuationEndpoint, ResponseContext, SectionList, Tab, Thumbnails,
|
||||
video_item::YouTubeListRenderer, Alert, ContentsRenderer, ResponseContext, SectionList, Tab,
|
||||
ThumbnailsWrap, TwoColumnBrowseResults,
|
||||
};
|
||||
|
||||
|
|
@ -26,15 +20,6 @@ pub(crate) struct Playlist {
|
|||
pub response_context: ResponseContext,
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct PlaylistCont {
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "VecSkipError<_>")]
|
||||
pub on_response_received_actions: Vec<OnResponseReceivedAction>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ItemSection {
|
||||
|
|
@ -44,13 +29,7 @@ pub(crate) struct ItemSection {
|
|||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct PlaylistVideoListRenderer {
|
||||
pub playlist_video_list_renderer: PlaylistVideoList,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct PlaylistVideoList {
|
||||
pub contents: MapResult<Vec<PlaylistItem>>,
|
||||
pub playlist_video_list_renderer: YouTubeListRenderer,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
@ -130,63 +109,3 @@ pub(crate) struct PlaylistThumbnailRenderer {
|
|||
#[serde(alias = "playlistCustomThumbnailRenderer")]
|
||||
pub playlist_video_thumbnail_renderer: ThumbnailsWrap,
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) enum PlaylistItem {
|
||||
/// Video in playlist
|
||||
PlaylistVideoRenderer(PlaylistVideoRenderer),
|
||||
/// Continauation items are located at the end of a list
|
||||
/// and contain the continuation token for progressive loading
|
||||
#[serde(rename_all = "camelCase")]
|
||||
ContinuationItemRenderer {
|
||||
continuation_endpoint: ContinuationEndpoint,
|
||||
},
|
||||
/// No video list item (e.g. ad) or unimplemented item
|
||||
#[serde(other, deserialize_with = "deserialize_ignore_any")]
|
||||
None,
|
||||
}
|
||||
|
||||
/// Video displayed in a playlist
|
||||
#[serde_as]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct PlaylistVideoRenderer {
|
||||
pub video_id: String,
|
||||
pub thumbnail: Thumbnails,
|
||||
#[serde_as(as = "Text")]
|
||||
pub title: String,
|
||||
#[serde(rename = "shortBylineText")]
|
||||
pub channel: TextComponent,
|
||||
#[serde_as(as = "JsonString")]
|
||||
pub length_seconds: u32,
|
||||
}
|
||||
|
||||
impl TryFrom<PlaylistVideoRenderer> for crate::model::PlaylistVideo {
|
||||
type Error = MappingError;
|
||||
|
||||
fn try_from(video: PlaylistVideoRenderer) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
id: video.video_id,
|
||||
name: video.title,
|
||||
length: video.length_seconds,
|
||||
thumbnail: video.thumbnail.into(),
|
||||
channel: crate::model::ChannelId::try_from(video.channel)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Continuation
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct OnResponseReceivedAction {
|
||||
pub append_continuation_items_action: AppendAction,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct AppendAction {
|
||||
pub continuation_items: MapResult<Vec<PlaylistItem>>,
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue