fix: a/b test 11: parsing like count with new data model
This commit is contained in:
parent
53cc9f1a27
commit
4d124c6d98
4 changed files with 100 additions and 7 deletions
|
|
@ -27,6 +27,7 @@ pub enum ABTest {
|
||||||
TrackViewcount = 8,
|
TrackViewcount = 8,
|
||||||
PlaylistsForShorts = 9,
|
PlaylistsForShorts = 9,
|
||||||
ChannelAboutModal = 10,
|
ChannelAboutModal = 10,
|
||||||
|
LikeButtonViewmodel = 11,
|
||||||
}
|
}
|
||||||
|
|
||||||
const TESTS_TO_RUN: [ABTest; 3] = [
|
const TESTS_TO_RUN: [ABTest; 3] = [
|
||||||
|
|
@ -100,6 +101,7 @@ pub async fn run_test(
|
||||||
ABTest::PlaylistsForShorts => playlists_for_shorts(&query).await,
|
ABTest::PlaylistsForShorts => playlists_for_shorts(&query).await,
|
||||||
ABTest::TrackViewcount => track_viewcount(&query).await,
|
ABTest::TrackViewcount => track_viewcount(&query).await,
|
||||||
ABTest::ChannelAboutModal => channel_about_modal(&query).await,
|
ABTest::ChannelAboutModal => channel_about_modal(&query).await,
|
||||||
|
ABTest::LikeButtonViewmodel => like_button_viewmodel(&query).await,
|
||||||
}
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
pb.inc(1);
|
pb.inc(1);
|
||||||
|
|
@ -301,3 +303,19 @@ pub async fn channel_about_modal(rp: &RustyPipeQuery) -> Result<bool> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(!res.contains("\"EgVhYm91dPIGBAoCEgA%3D\""))
|
Ok(!res.contains("\"EgVhYm91dPIGBAoCEgA%3D\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn like_button_viewmodel(rp: &RustyPipeQuery) -> Result<bool> {
|
||||||
|
let res = rp
|
||||||
|
.raw(
|
||||||
|
ClientType::Desktop,
|
||||||
|
"next",
|
||||||
|
&QVideo {
|
||||||
|
context: rp.get_context(ClientType::Desktop, true, None).await,
|
||||||
|
video_id: "ZeerrnuLi5E",
|
||||||
|
content_check_ok: true,
|
||||||
|
racy_check_ok: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(res.contains("\"segmentedLikeDislikeButtonViewModel\""))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -432,3 +432,35 @@ channel metadata has to be fetched.
|
||||||
The new modal uses a continuation request with a token which can be easily generated.
|
The new modal uses a continuation request with a token which can be easily generated.
|
||||||
Attempts to fetch the old about tab with the A/B test enabled will lead to a redirect to
|
Attempts to fetch the old about tab with the A/B test enabled will lead to a redirect to
|
||||||
the main tab.
|
the main tab.
|
||||||
|
|
||||||
|
## [11] Like-Button viewmodel
|
||||||
|
|
||||||
|
- **Encountered on:** 03.11.2023
|
||||||
|
- **Impact:** 🟢 Low
|
||||||
|
- **Endpoint:** next
|
||||||
|
|
||||||
|
YouTube introduced an updated date model for the like/dislike buttons. The new model
|
||||||
|
looks needlessly complex but contains the same parsing-relevant data as the old model
|
||||||
|
(accessibility text to get like count).
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"segmentedLikeDislikeButtonViewModel": {
|
||||||
|
"likeButtonViewModel": {
|
||||||
|
"likeButtonViewModel": {
|
||||||
|
"toggleButtonViewModel": {
|
||||||
|
"toggleButtonViewModel": {
|
||||||
|
"defaultButtonViewModel": {
|
||||||
|
"buttonViewModel": {
|
||||||
|
"iconName": "LIKE",
|
||||||
|
"title": "4.2M",
|
||||||
|
"accessibilityText": "like this video along with 4,209,059 other people"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,46 @@ pub(crate) enum TopLevelButton {
|
||||||
SegmentedLikeDislikeButtonRenderer {
|
SegmentedLikeDislikeButtonRenderer {
|
||||||
like_button: ToggleButtonWrap,
|
like_button: ToggleButtonWrap,
|
||||||
},
|
},
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
SegmentedLikeDislikeButtonViewModel {
|
||||||
|
like_button_view_model: LikeButtonViewModelWrap,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct LikeButtonViewModelWrap {
|
||||||
|
pub like_button_view_model: LikeButtonViewModel,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct LikeButtonViewModel {
|
||||||
|
pub toggle_button_view_model: ToggleButtonViewModelWrap,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct ToggleButtonViewModelWrap {
|
||||||
|
pub toggle_button_view_model: ToggleButtonViewModel,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct ToggleButtonViewModel {
|
||||||
|
pub default_button_view_model: ButtonViewModelWrap,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct ButtonViewModelWrap {
|
||||||
|
pub button_view_model: ButtonViewModel,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct ButtonViewModel {
|
||||||
|
pub accessibility_text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like/Dislike button
|
/// Like/Dislike button
|
||||||
|
|
|
||||||
|
|
@ -159,17 +159,20 @@ impl MapResponse<VideoDetails> for response::VideoDetails {
|
||||||
video_actions,
|
video_actions,
|
||||||
date_text,
|
date_text,
|
||||||
}) => {
|
}) => {
|
||||||
let like_btn = video_actions
|
let like_text = video_actions
|
||||||
.menu_renderer
|
.menu_renderer
|
||||||
.top_level_buttons
|
.top_level_buttons
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|button| {
|
.find_map(|button| {
|
||||||
let btn = match button {
|
let (icon, text) = match button {
|
||||||
response::video_details::TopLevelButton::ToggleButtonRenderer(btn) => btn,
|
response::video_details::TopLevelButton::ToggleButtonRenderer(btn) => (btn.default_icon.icon_type, btn.accessibility_data),
|
||||||
response::video_details::TopLevelButton::SegmentedLikeDislikeButtonRenderer { like_button } => like_button.toggle_button_renderer,
|
response::video_details::TopLevelButton::SegmentedLikeDislikeButtonRenderer { like_button } => (like_button.toggle_button_renderer.default_icon.icon_type, like_button.toggle_button_renderer.accessibility_data),
|
||||||
|
response::video_details::TopLevelButton::SegmentedLikeDislikeButtonViewModel { like_button_view_model } => {
|
||||||
|
(IconType::Like, like_button_view_model.like_button_view_model.toggle_button_view_model.toggle_button_view_model.default_button_view_model.button_view_model.accessibility_text)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
match btn.default_icon.icon_type {
|
match icon {
|
||||||
IconType::Like => Some(btn),
|
IconType::Like => Some(text),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -184,7 +187,7 @@ impl MapResponse<VideoDetails> for response::VideoDetails {
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
// accessibility_data contains no digits if the like count is hidden,
|
// accessibility_data contains no digits if the like count is hidden,
|
||||||
// so we ignore parse errors here for now
|
// so we ignore parse errors here for now
|
||||||
like_btn.and_then(|btn| util::parse_numeric(&btn.accessibility_data).ok()),
|
like_text.and_then(|txt| util::parse_numeric(&txt).ok()),
|
||||||
date_text.as_deref().and_then(|txt| {
|
date_text.as_deref().and_then(|txt| {
|
||||||
timeago::parse_textual_date_or_warn(lang, txt, &mut warnings)
|
timeago::parse_textual_date_or_warn(lang, txt, &mut warnings)
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Reference in a new issue