fix: parse upload date of channel shorts
This commit is contained in:
parent
629728393b
commit
b8c540f815
2 changed files with 102 additions and 50 deletions
|
|
@ -133,6 +133,8 @@ pub(crate) struct ReelItemRenderer {
|
|||
/// Dashes may be `\u2013` (emdash)
|
||||
#[serde_as(as = "Option<AccessibilityText>")]
|
||||
pub accessibility: Option<String>,
|
||||
#[serde_as(as = "DefaultOnError")]
|
||||
pub navigation_endpoint: Option<ReelNavigationEndpoint>,
|
||||
}
|
||||
|
||||
/// Playlist displayed in search results
|
||||
|
|
@ -283,6 +285,45 @@ pub(crate) struct ChannelThumbnailWithLinkRenderer {
|
|||
pub thumbnail: Thumbnails,
|
||||
}
|
||||
|
||||
/// Short video item navigation endpoint (contains upload date)
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ReelNavigationEndpoint {
|
||||
pub reel_watch_endpoint: ReelWatchEndpoint,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ReelWatchEndpoint {
|
||||
pub overlay: ReelPlayerOverlay,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ReelPlayerOverlay {
|
||||
pub reel_player_overlay_renderer: ReelPlayerOverlayRenderer,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ReelPlayerOverlayRenderer {
|
||||
pub reel_player_header_supported_renderers: ReelPlayerHeaderRenderers,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ReelPlayerHeaderRenderers {
|
||||
pub reel_player_header_renderer: ReelPlayerHeaderRenderer,
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ReelPlayerHeaderRenderer {
|
||||
#[serde_as(as = "Text")]
|
||||
pub timestamp_text: String,
|
||||
}
|
||||
|
||||
trait IsLive {
|
||||
fn is_live(&self) -> bool;
|
||||
}
|
||||
|
|
@ -415,6 +456,15 @@ impl<T> YouTubeListMapper<T> {
|
|||
static ACCESSIBILITY_SEP_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(" [-\u{2013}] (.+) [-\u{2013}] ").unwrap());
|
||||
|
||||
let pub_date_txt = video.navigation_endpoint.map(|n| {
|
||||
n.reel_watch_endpoint
|
||||
.overlay
|
||||
.reel_player_overlay_renderer
|
||||
.reel_player_header_supported_renderers
|
||||
.reel_player_header_renderer
|
||||
.timestamp_text
|
||||
});
|
||||
|
||||
VideoItem {
|
||||
id: video.video_id,
|
||||
title: video.headline,
|
||||
|
|
@ -432,8 +482,10 @@ impl<T> YouTubeListMapper<T> {
|
|||
}),
|
||||
thumbnail: video.thumbnail.into(),
|
||||
channel: self.channel.clone(),
|
||||
publish_date: None,
|
||||
publish_date_txt: None,
|
||||
publish_date: pub_date_txt
|
||||
.as_ref()
|
||||
.and_then(|txt| timeago::parse_timeago_to_dt(self.lang, txt)),
|
||||
publish_date_txt: pub_date_txt,
|
||||
view_count: video
|
||||
.view_count_text
|
||||
.map(|txt| util::parse_numeric(&txt).unwrap_or_default()),
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 days ago"),
|
||||
view_count: Some(593),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -164,7 +164,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("4 days ago"),
|
||||
view_count: Some(141),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -190,7 +190,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("6 days ago"),
|
||||
view_count: Some(652),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -216,7 +216,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("8 days ago"),
|
||||
view_count: Some(795),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -242,7 +242,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("9 days ago"),
|
||||
view_count: Some(17),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -268,7 +268,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("11 days ago"),
|
||||
view_count: Some(1),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -294,7 +294,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("13 days ago"),
|
||||
view_count: Some(15),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -320,7 +320,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(26),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -346,7 +346,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(864),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -372,7 +372,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(21),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -398,7 +398,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(1),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -424,7 +424,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 weeks ago"),
|
||||
view_count: Some(45),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -450,7 +450,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 weeks ago"),
|
||||
view_count: Some(18),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -476,7 +476,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 weeks ago"),
|
||||
view_count: Some(16),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -502,7 +502,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 weeks ago"),
|
||||
view_count: Some(13),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -528,7 +528,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(34),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -554,7 +554,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(13),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -580,7 +580,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(756),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -606,7 +606,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(13),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -632,7 +632,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(39),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -658,7 +658,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(18),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -684,7 +684,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(31),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -710,7 +710,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(17),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -736,7 +736,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(18),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -762,7 +762,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(18),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -788,7 +788,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(11),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -814,7 +814,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(31),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -840,7 +840,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("1 month ago"),
|
||||
view_count: Some(688),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -866,7 +866,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(19),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -892,7 +892,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(1),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -918,7 +918,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(64),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -944,7 +944,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(16),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -970,7 +970,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(27),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -996,7 +996,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(25),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1022,7 +1022,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(2),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1048,7 +1048,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("2 months ago"),
|
||||
view_count: Some(53),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1074,7 +1074,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(2),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1100,7 +1100,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(91),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1126,7 +1126,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(26),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1152,7 +1152,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(65),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1178,7 +1178,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(22),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1204,7 +1204,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(66),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1230,7 +1230,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(39),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1256,7 +1256,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("3 months ago"),
|
||||
view_count: Some(978),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1282,7 +1282,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(45),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1308,7 +1308,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(21),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1334,7 +1334,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(4),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
@ -1360,7 +1360,7 @@ Channel(
|
|||
subscriber_count: Some(2980000),
|
||||
)),
|
||||
publish_date: "[date]",
|
||||
publish_date_txt: None,
|
||||
publish_date_txt: Some("4 months ago"),
|
||||
view_count: Some(63),
|
||||
is_live: false,
|
||||
is_short: true,
|
||||
|
|
|
|||
Reference in a new issue