feat: use official date serializer, fix test
This commit is contained in:
parent
cf24f978f2
commit
deeffacc1c
5 changed files with 4 additions and 60 deletions
|
|
@ -5,6 +5,7 @@ edition = "2021"
|
|||
authors = ["ThetaDev <thetadev@magenta.de>"]
|
||||
license = "GPL-3.0"
|
||||
description = "Client for the public YouTube / YouTube Music API (Innertube), inspired by NewPipe"
|
||||
repository = "https://code.thetadev.de/ThetaDev/rustypipe"
|
||||
keywords = ["youtube", "video", "music"]
|
||||
categories = ["api-bindings", "multimedia"]
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ serde_plain = "1.0.1"
|
|||
rand = "0.8.5"
|
||||
time = { version = "0.3.15", features = [
|
||||
"macros",
|
||||
"serde",
|
||||
"serde-human-readable",
|
||||
"serde-well-known",
|
||||
] }
|
||||
futures = "0.3.21"
|
||||
|
|
|
|||
|
|
@ -12,11 +12,10 @@ pub use frameset::{Frameset, FramesetUrls};
|
|||
use std::{collections::BTreeSet, ops::Range};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::serde_as;
|
||||
use time::{Date, OffsetDateTime};
|
||||
|
||||
use self::{paginator::Paginator, richtext::RichText};
|
||||
use crate::{error::Error, param::Country, serializer::DateYmd, validate};
|
||||
use crate::{error::Error, param::Country, validate};
|
||||
|
||||
/*
|
||||
#COMMON
|
||||
|
|
@ -501,7 +500,6 @@ pub struct Subtitle {
|
|||
*/
|
||||
|
||||
/// YouTube playlist
|
||||
#[serde_as]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct Playlist {
|
||||
|
|
@ -520,7 +518,6 @@ pub struct Playlist {
|
|||
/// Channel of the playlist
|
||||
pub channel: Option<ChannelId>,
|
||||
/// Last update date
|
||||
#[serde_as(as = "Option<DateYmd>")]
|
||||
pub last_update: Option<Date>,
|
||||
/// Textual last update date
|
||||
pub last_update_txt: Option<String>,
|
||||
|
|
@ -739,7 +736,6 @@ pub struct Channel<T> {
|
|||
}
|
||||
|
||||
/// Detailed channel information
|
||||
#[serde_as]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct ChannelInfo {
|
||||
|
|
@ -757,7 +753,6 @@ pub struct ChannelInfo {
|
|||
/// Channel video count
|
||||
pub video_count: Option<u64>,
|
||||
/// Channel creation date
|
||||
#[serde_as(as = "Option<DateYmd>")]
|
||||
pub create_date: Option<Date>,
|
||||
/// Channel view count
|
||||
pub view_count: Option<u64>,
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
use serde::{
|
||||
de::{self, Visitor},
|
||||
ser, Serialize,
|
||||
};
|
||||
use serde_with::{DeserializeAs, SerializeAs};
|
||||
use time::{macros::format_description, Date};
|
||||
|
||||
const YMD_FORMAT: &[time::format_description::FormatItem] =
|
||||
format_description!("[year]-[month]-[day]");
|
||||
|
||||
pub struct DateYmd;
|
||||
|
||||
impl SerializeAs<Date> for DateYmd {
|
||||
fn serialize_as<S>(date: &Date, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
date.format(YMD_FORMAT)
|
||||
.map_err(ser::Error::custom)?
|
||||
.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> DeserializeAs<'de, Date> for DateYmd {
|
||||
fn deserialize_as<D>(deserializer: D) -> Result<Date, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
struct DateYmdVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for DateYmdVisitor {
|
||||
type Value = Date;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
formatter.write_str("a YYYY-MM-DD formatted date")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
Date::parse(v, YMD_FORMAT).map_err(|_| {
|
||||
de::Error::invalid_value(de::Unexpected::Str(v), &"a YYYY-MM-DD formatted date")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_str(DateYmdVisitor)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
pub mod text;
|
||||
|
||||
mod date;
|
||||
mod range;
|
||||
mod vec_log_err;
|
||||
|
||||
pub use date::DateYmd;
|
||||
pub use range::Range;
|
||||
pub use vec_log_err::VecSkipErrorWrap;
|
||||
|
||||
|
|
|
|||
|
|
@ -754,7 +754,7 @@ fn get_video_details_no_desc(rp: RustyPipe) {
|
|||
assert_eq!(details.id, "VYJNSQ_ANyA");
|
||||
assert_eq!(details.name, "Cricket comedy by Modi");
|
||||
assert_eq!(details.channel.id, "UC8gBy2lByHxIyoPMglerNWg");
|
||||
assert_eq!(details.channel.name, "TMP VIBES");
|
||||
assert_eq!(details.channel.name, "TMP Shorts");
|
||||
assert!(!details.channel.avatar.is_empty(), "no channel avatars");
|
||||
|
||||
assert!(
|
||||
|
|
|
|||
Reference in a new issue