From 9f7f337efd90eb7ffecac9c2285ba9318aae6cb6 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Tue, 18 Oct 2022 23:06:19 +0200 Subject: [PATCH 1/2] fix: remove split seconds --- src/client/mod.rs | 2 +- src/report.rs | 4 ++-- src/timeago.rs | 2 +- src/util/date.rs | 13 ++++++++++++- src/util/mod.rs | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index d5f9f3e..e762253 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -269,7 +269,7 @@ impl CacheEntry { impl From for CacheEntry { fn from(f: T) -> Self { Self::Some { - last_update: OffsetDateTime::now_utc(), + last_update: util::now_sec(), data: f, } } diff --git a/src/report.rs b/src/report.rs index 979d13b..3497cee 100644 --- a/src/report.rs +++ b/src/report.rs @@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize}; use time::macros::format_description; use time::OffsetDateTime; -use crate::deobfuscate::DeobfData; use crate::error::Error; +use crate::{deobfuscate::DeobfData, util}; const FILENAME_FORMAT: &[time::format_description::FormatItem] = format_description!("[year]-[month]-[day]_[hour]-[minute]-[second]"); @@ -81,7 +81,7 @@ impl Default for Info { Self { package: "rustypipe".to_owned(), version: "0.1.0".to_owned(), - date: OffsetDateTime::now_utc(), + date: util::now_sec(), } } } diff --git a/src/timeago.rs b/src/timeago.rs index 8ae4bec..53b0090 100644 --- a/src/timeago.rs +++ b/src/timeago.rs @@ -84,7 +84,7 @@ impl Mul for TimeAgo { impl From for OffsetDateTime { fn from(ta: TimeAgo) -> Self { - let ts = OffsetDateTime::now_utc(); + let ts = util::now_sec(); match ta.unit { TimeUnit::Second => ts - Duration::seconds(ta.n as i64), TimeUnit::Minute => ts - Duration::minutes(ta.n as i64), diff --git a/src/util/date.rs b/src/util/date.rs index a161565..742a9c6 100644 --- a/src/util/date.rs +++ b/src/util/date.rs @@ -1,4 +1,4 @@ -use time::{Date, Month}; +use time::{Date, Month, OffsetDateTime}; pub const fn month_from_n(n: u8) -> Option { match n { @@ -42,3 +42,14 @@ pub fn shift_months(date: Date, months: i32) -> Date { pub fn shift_years(date: Date, years: i32) -> Date { shift_months(date, years * 12) } + +/// Get the current datetime without milli/micro/nanoseconds +pub fn now_sec() -> OffsetDateTime { + OffsetDateTime::now_utc() + .replace_millisecond(0) + .unwrap() + .replace_microsecond(0) + .unwrap() + .replace_nanosecond(0) + .unwrap() +} diff --git a/src/util/mod.rs b/src/util/mod.rs index 9c6ab8f..02a746f 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -3,7 +3,7 @@ mod protobuf; pub mod dictionary; -pub use date::{month_from_n, shift_months, shift_years}; +pub use date::{month_from_n, now_sec, shift_months, shift_years}; pub use protobuf::ProtoBuilder; use std::{ From 39b32da5a4c05c2ff46650cac47e566a782200d3 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Wed, 19 Oct 2022 00:24:37 +0200 Subject: [PATCH 2/2] fix(channel): new rich grid renderer continuation format --- src/client/pagination.rs | 20 +++++++++++++------- src/client/response/mod.rs | 26 ++++++++++++++++++++++---- src/client/response/video_details.rs | 4 ++-- src/client/video_details.rs | 5 ++++- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/client/pagination.rs b/src/client/pagination.rs index 94b5396..818d3af 100644 --- a/src/client/pagination.rs +++ b/src/client/pagination.rs @@ -53,14 +53,20 @@ impl> MapResponse> for response::Continuati lang: crate::param::Language, _deobf: Option<&crate::deobfuscate::Deobfuscator>, ) -> Result>, ExtractionError> { - let mut actions = self.on_response_received_actions; - let items = actions - .try_swap_remove(0) + let items = self + .on_response_received_actions + .and_then(|mut actions| { + actions + .try_swap_remove(0) + .map(|action| action.append_continuation_items_action.continuation_items) + }) + .or_else(|| { + self.continuation_contents + .map(|contents| contents.rich_grid_continuation.contents) + }) .ok_or(ExtractionError::InvalidData(Cow::Borrowed( - "no item section renderer", - )))? - .append_continuation_items_action - .continuation_items; + "no continuation items", + )))?; let mut mapper = response::YouTubeListMapper::::new(lang); mapper.map_response(items); diff --git a/src/client/response/mod.rs b/src/client/response/mod.rs index 644b998..b0452d7 100644 --- a/src/client/response/mod.rs +++ b/src/client/response/mod.rs @@ -140,6 +140,12 @@ pub(crate) struct AlertRenderer { pub text: String, } +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub(crate) struct ResponseContext { + pub visitor_data: Option, +} + // CONTINUATION #[serde_as] @@ -153,8 +159,12 @@ pub(crate) struct Continuation { alias = "onResponseReceivedCommands", alias = "onResponseReceivedEndpoints" )] - #[serde_as(as = "VecSkipError<_>")] - pub on_response_received_actions: Vec, + #[serde_as(as = "Option>")] + pub on_response_received_actions: Option>, + /// Used for channel video rich grid renderer + /// + /// A/B test seen on 19.10.2022 + pub continuation_contents: Option, } #[derive(Debug, Deserialize)] @@ -173,8 +183,16 @@ pub(crate) struct ContinuationAction { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] -pub(crate) struct ResponseContext { - pub visitor_data: Option, +pub(crate) struct RichGridContinuationContents { + pub rich_grid_continuation: RichGridContinuation, +} + +#[serde_as] +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub(crate) struct RichGridContinuation { + #[serde_as(as = "VecLogError<_>")] + pub contents: MapResult>, } // YouTube Music diff --git a/src/client/response/video_details.rs b/src/client/response/video_details.rs index 19a0cce..77871e2 100644 --- a/src/client/response/video_details.rs +++ b/src/client/response/video_details.rs @@ -66,8 +66,8 @@ pub(crate) struct VideoResultsWrap { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub(crate) struct VideoResults { - #[serde_as(as = "VecLogError<_>")] - pub contents: MapResult>, + #[serde_as(as = "Option>")] + pub contents: Option>>, } /// Video metadata item diff --git a/src/client/video_details.rs b/src/client/video_details.rs index 132af0f..714875e 100644 --- a/src/client/video_details.rs +++ b/src/client/video_details.rs @@ -102,7 +102,10 @@ impl MapResponse for response::VideoDetails { .two_column_watch_next_results .results .results - .contents; + .contents + .ok_or(ExtractionError::ContentUnavailable(Cow::Borrowed( + "Video not found", + )))?; warnings.append(&mut primary_results.warnings); let mut primary_info = None;