fix: fetching comment count

This commit is contained in:
ThetaDev 2022-09-20 17:24:16 +02:00
parent e800e16c68
commit 8c1e7bf6ac
8 changed files with 113 additions and 46 deletions

View file

@ -75,6 +75,12 @@ pub enum VideoListItem<T> {
None,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ContinuationItemRenderer {
pub continuation_endpoint: ContinuationEndpoint,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ContinuationEndpoint {

View file

@ -12,8 +12,8 @@ use crate::serializer::{
};
use super::{
ChannelBadge, ContentsRenderer, ContinuationEndpoint, Icon, Thumbnails, VideoBadge,
VideoListItem, VideoOwner,
ChannelBadge, ContentsRenderer, ContinuationEndpoint, ContinuationItemRenderer, Icon,
Thumbnails, VideoBadge, VideoListItem, VideoOwner,
};
/*
@ -92,18 +92,11 @@ pub enum VideoResultsItem {
#[serde_as(deserialize_as = "DefaultOnError")]
metadata_row_container: Option<MetadataRowContainer>,
},
/*
/// The comment section consists of 2 ItemSectionRenderers:
///
/// 1. sectionIdentifier: "comments-entry-point", contains number of comments
/// 2. sectionIdentifier: "comment-item-section", contains continuation token
#[serde(rename_all = "camelCase")]
ItemSectionRenderer {
#[serde_as(as = "VecSkipError<_>")]
contents: Vec<ItemSection>,
section_identifier: String,
},
*/
ItemSectionRenderer(ItemSection),
#[serde(other, deserialize_with = "ignore_any")]
None,
}
@ -211,6 +204,47 @@ pub struct CurrentVideoWatchEndpoint {
pub video_id: String,
}
/// The comment section consists of 2 ItemSections:
///
/// 1. CommentsEntryPointHeaderRenderer: contains number of comments
/// 2. ContinuationItemRenderer: contains continuation token
#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "kebab-case", tag = "sectionIdentifier")]
pub enum ItemSection {
CommentsEntryPoint {
#[serde_as(as = "VecSkipError<_>")]
contents: Vec<ItemSectionCommentCount>,
},
CommentItemSection {
#[serde_as(as = "VecSkipError<_>")]
contents: Vec<ItemSectionComments>,
},
}
/// Item section containing comment count
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ItemSectionCommentCount {
pub comments_entry_point_header_renderer: CommentsEntryPointHeaderRenderer,
}
/// Renderer of item section containing comment count
#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CommentsEntryPointHeaderRenderer {
#[serde_as(as = "Text")]
pub comment_count: String,
}
/// Item section containing comments ctoken
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ItemSectionComments {
pub continuation_item_renderer: ContinuationItemRenderer,
}
/// Video recommendations
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
@ -461,10 +495,7 @@ pub enum CommentListItem {
rendering_priority: CommentPriority,
},
/// Reply comment
CommentRenderer {
#[serde(flatten)]
comment: CommentRenderer,
},
CommentRenderer(CommentRenderer),
/// Continuation token to fetch more comments
#[serde(rename_all = "camelCase")]
ContinuationItemRenderer {