fix: a/b test 20: music continuation item renderer
This commit is contained in:
parent
e91541629d
commit
9c67f8f85b
8 changed files with 88 additions and 21 deletions
|
|
@ -196,13 +196,15 @@ impl MapResponse<MusicPlaylist> for response::MusicPlaylist {
|
|||
|
||||
let mut mapper = MusicListMapper::new(ctx.lang);
|
||||
mapper.map_response(shelf.contents);
|
||||
let map_res = mapper.conv_items();
|
||||
|
||||
let ctoken = shelf
|
||||
.continuations
|
||||
.into_iter()
|
||||
.next()
|
||||
.map(|cont| cont.next_continuation_data.continuation);
|
||||
let ctoken = mapper.ctoken.clone().or_else(|| {
|
||||
shelf
|
||||
.continuations
|
||||
.into_iter()
|
||||
.next()
|
||||
.map(|cont| cont.next_continuation_data.continuation)
|
||||
});
|
||||
let map_res = mapper.conv_items();
|
||||
|
||||
let track_count = if ctoken.is_some() {
|
||||
header.as_ref().and_then(|h| {
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ impl<T: FromYtItem> MapResponse<MusicSearchResult<T>> for response::MusicSearch
|
|||
response::music_search::ItemSection::None => {}
|
||||
});
|
||||
|
||||
let ctoken = ctoken.or(mapper.ctoken.clone());
|
||||
let map_res = mapper.conv_items();
|
||||
|
||||
Ok(MapResult {
|
||||
|
|
|
|||
|
|
@ -199,11 +199,17 @@ impl MapResponse<Paginator<MusicItem>> for response::MusicContinuation {
|
|||
None => {}
|
||||
}
|
||||
|
||||
for a in self.on_response_received_actions {
|
||||
mapper.map_response(a.append_continuation_items_action.continuation_items);
|
||||
}
|
||||
|
||||
let ctoken = mapper.ctoken.clone().or_else(|| {
|
||||
continuations
|
||||
.into_iter()
|
||||
.next()
|
||||
.map(|cont| cont.next_continuation_data.continuation)
|
||||
});
|
||||
let map_res = mapper.items();
|
||||
let ctoken = continuations
|
||||
.into_iter()
|
||||
.next()
|
||||
.map(|cont| cont.next_continuation_data.continuation);
|
||||
|
||||
Ok(MapResult {
|
||||
c: Paginator::new_ext(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ use super::{
|
|||
url_endpoint::{
|
||||
BrowseEndpointWrap, MusicPage, MusicPageType, MusicVideoType, NavigationEndpoint, PageType,
|
||||
},
|
||||
ContentsRenderer, MusicContinuationData, SimpleHeaderRenderer, Thumbnails, ThumbnailsWrap,
|
||||
ContentsRenderer, ContinuationActionWrap, ContinuationEndpoint, MusicContinuationData,
|
||||
SimpleHeaderRenderer, Thumbnails, ThumbnailsWrap,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
@ -86,6 +87,10 @@ pub(crate) enum MusicResponseItem {
|
|||
MusicResponsiveListItemRenderer(ListMusicItem),
|
||||
MusicTwoRowItemRenderer(CoverMusicItem),
|
||||
MessageRenderer(serde::de::IgnoredAny),
|
||||
#[serde(rename_all = "camelCase")]
|
||||
ContinuationItemRenderer {
|
||||
continuation_endpoint: ContinuationEndpoint,
|
||||
},
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
|
|
@ -322,10 +327,14 @@ impl From<MusicThumbnailRenderer> for Vec<model::Thumbnail> {
|
|||
}
|
||||
|
||||
/// Music list continuation response model
|
||||
#[serde_as]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct MusicContinuation {
|
||||
pub continuation_contents: Option<ContinuationContents>,
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "VecSkipError<_>")]
|
||||
pub on_response_received_actions: Vec<ContinuationActionWrap<MusicResponseItem>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
@ -434,6 +443,7 @@ pub(crate) struct MusicListMapper {
|
|||
search_suggestion: bool,
|
||||
items: Vec<MusicItem>,
|
||||
warnings: Vec<String>,
|
||||
pub ctoken: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -455,6 +465,7 @@ impl MusicListMapper {
|
|||
search_suggestion: false,
|
||||
items: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
ctoken: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -468,6 +479,7 @@ impl MusicListMapper {
|
|||
search_suggestion: true,
|
||||
items: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
ctoken: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -482,6 +494,7 @@ impl MusicListMapper {
|
|||
search_suggestion: false,
|
||||
items: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
ctoken: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -496,6 +509,7 @@ impl MusicListMapper {
|
|||
search_suggestion: false,
|
||||
items: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
ctoken: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -507,6 +521,12 @@ impl MusicListMapper {
|
|||
// Tile
|
||||
MusicResponseItem::MusicTwoRowItemRenderer(item) => self.map_tile(item),
|
||||
MusicResponseItem::MessageRenderer(_) => Ok(None),
|
||||
MusicResponseItem::ContinuationItemRenderer {
|
||||
continuation_endpoint,
|
||||
} => {
|
||||
self.ctoken = Some(continuation_endpoint.continuation_command.token);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ impl<T: FromYtItem> MapResponse<SearchResult<T>> for response::Search {
|
|||
.filter_map(T::from_yt_item)
|
||||
.collect(),
|
||||
mapper.ctoken,
|
||||
None,
|
||||
ctx.visitor_data.map(str::to_owned),
|
||||
ContinuationEndpoint::Search,
|
||||
false,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ impl MapResponse<VideoDetails> for response::VideoDetails {
|
|||
r,
|
||||
sr.secondary_results.continuations,
|
||||
visitor_data.clone(),
|
||||
ctx.lang,
|
||||
ctx,
|
||||
);
|
||||
warnings.append(&mut res.warnings);
|
||||
res.c
|
||||
|
|
@ -359,7 +359,7 @@ impl MapResponse<VideoDetails> for response::VideoDetails {
|
|||
comment_ctoken,
|
||||
visitor_data.clone(),
|
||||
ContinuationEndpoint::Next,
|
||||
false,
|
||||
ctx.authenticated,
|
||||
),
|
||||
latest_comments: Paginator::new_ext(
|
||||
comment_count,
|
||||
|
|
@ -367,7 +367,7 @@ impl MapResponse<VideoDetails> for response::VideoDetails {
|
|||
latest_comments_ctoken,
|
||||
visitor_data.clone(),
|
||||
ContinuationEndpoint::Next,
|
||||
false,
|
||||
ctx.authenticated,
|
||||
),
|
||||
visitor_data,
|
||||
},
|
||||
|
|
@ -468,9 +468,9 @@ fn map_recommendations(
|
|||
r: MapResult<Vec<response::YouTubeListItem>>,
|
||||
continuations: Option<Vec<response::MusicContinuationData>>,
|
||||
visitor_data: Option<String>,
|
||||
lang: Language,
|
||||
ctx: &MapRespCtx<'_>,
|
||||
) -> MapResult<Paginator<VideoItem>> {
|
||||
let mut mapper = response::YouTubeListMapper::<VideoItem>::new(lang);
|
||||
let mut mapper = response::YouTubeListMapper::<VideoItem>::new(ctx.lang);
|
||||
mapper.map_response(r);
|
||||
|
||||
mapper.ctoken = mapper.ctoken.or_else(|| {
|
||||
|
|
@ -486,7 +486,7 @@ fn map_recommendations(
|
|||
mapper.ctoken,
|
||||
visitor_data,
|
||||
ContinuationEndpoint::Next,
|
||||
false,
|
||||
ctx.authenticated,
|
||||
),
|
||||
warnings: mapper.warnings,
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue