fix: response models
This commit is contained in:
parent
9da166304a
commit
17094d121b
5 changed files with 17 additions and 16 deletions
|
|
@ -530,9 +530,9 @@ mod tests {
|
|||
}
|
||||
|
||||
/// Assert equality within 10% margin
|
||||
fn assert_approx(left: u32, right: u32) {
|
||||
fn assert_approx(left: f64, right: f64) {
|
||||
if left != right {
|
||||
let f = left as f64 / right as f64;
|
||||
let f = left / right;
|
||||
assert!(
|
||||
0.9 < f && f < 1.1,
|
||||
"{} not within 10% margin of {}",
|
||||
|
|
@ -593,7 +593,7 @@ mod tests {
|
|||
.unwrap();
|
||||
|
||||
// Bitrates may change between requests
|
||||
assert_approx(video.bitrate, 1507068);
|
||||
assert_approx(video.bitrate as f64, 1507068.0);
|
||||
assert_eq!(video.average_bitrate, 1345149);
|
||||
assert_eq!(video.size, 43553412);
|
||||
assert_eq!(video.width, 1280);
|
||||
|
|
@ -605,7 +605,7 @@ mod tests {
|
|||
assert_eq!(video.format, VideoFormat::Webm);
|
||||
assert_eq!(video.codec, VideoCodec::Vp9);
|
||||
|
||||
assert_approx(audio.bitrate, 130685);
|
||||
assert_approx(audio.bitrate as f64, 130685.0);
|
||||
assert_eq!(audio.average_bitrate, 129496);
|
||||
assert_eq!(audio.size, 4193863);
|
||||
assert_eq!(audio.mime, "audio/mp4; codecs=\"mp4a.40.2\"");
|
||||
|
|
@ -623,9 +623,9 @@ mod tests {
|
|||
.find(|s| s.itag == 251)
|
||||
.unwrap();
|
||||
|
||||
assert_approx(video.bitrate, 1340829);
|
||||
assert_eq!(video.average_bitrate, 1233444);
|
||||
assert_eq!(video.size, 39936630);
|
||||
assert_approx(video.bitrate as f64, 1340829.0);
|
||||
assert_approx(video.average_bitrate as f64, 1233444.0);
|
||||
assert_approx(video.size as f64, 39936630.0);
|
||||
assert_eq!(video.width, 1280);
|
||||
assert_eq!(video.height, 720);
|
||||
assert_eq!(video.fps, 30);
|
||||
|
|
@ -636,9 +636,9 @@ mod tests {
|
|||
assert_eq!(video.codec, VideoCodec::Av01);
|
||||
assert_eq!(video.throttled, false);
|
||||
|
||||
assert_approx(audio.bitrate, 142718);
|
||||
assert_eq!(audio.average_bitrate, 130708);
|
||||
assert_eq!(audio.size, 4232344);
|
||||
assert_approx(audio.bitrate as f64, 142718.0);
|
||||
assert_approx(audio.average_bitrate as f64, 130708.0);
|
||||
assert_approx(audio.size as f64, 4232344.0);
|
||||
assert_eq!(audio.mime, "audio/webm; codecs=\"opus\"");
|
||||
assert_eq!(audio.format, AudioFormat::Webm);
|
||||
assert_eq!(audio.codec, AudioCodec::Opus);
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ pub enum TimeOverlayStyle {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MusicItem {
|
||||
pub thumbnail: MusicThumbnailRenderer,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub playlist_item_data: Option<PlaylistItemData>,
|
||||
#[serde_as(as = "VecSkipError<_>")]
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ pub struct Format {
|
|||
#[serde_as(as = "JsonString")]
|
||||
pub content_length: u64,
|
||||
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub quality: Option<Quality>,
|
||||
pub fps: Option<u8>,
|
||||
|
|
@ -89,6 +90,7 @@ pub struct Format {
|
|||
pub color_info: Option<ColorInfo>,
|
||||
|
||||
// Audio only
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub audio_quality: Option<AudioQuality>,
|
||||
#[serde_as(as = "Option<JsonString>")]
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ pub struct HeaderRenderer {
|
|||
pub playlist_id: String,
|
||||
#[serde_as(as = "crate::serializer::text::Text")]
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "DefaultOnError<Option<crate::serializer::text::Text>>")]
|
||||
pub description_text: Option<String>,
|
||||
/// `"495", " videos"`
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ pub enum VideoResultsItem {
|
|||
owner: VideoOwner,
|
||||
#[serde_as(as = "crate::serializer::text::Text")]
|
||||
description: String,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
metadata_row_container: Option<MetadataRowContainer>,
|
||||
},
|
||||
|
|
@ -337,16 +338,12 @@ pub struct Comment {
|
|||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CommentRenderer {
|
||||
/*
|
||||
#[serde_as(as = "crate::serializer::text::Text")]
|
||||
pub author_text: String,
|
||||
pub author_thumbnail: Thumbnails,
|
||||
pub author_endpoint: AuthorEndpoint,
|
||||
*/
|
||||
// There may be comments with missing authors (possibly deleted users?)
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "DefaultOnError<Option<crate::serializer::text::Text>>")]
|
||||
pub author_text: Option<String>,
|
||||
pub author_thumbnail: Thumbnails,
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "DefaultOnError")]
|
||||
pub author_endpoint: Option<AuthorEndpoint>,
|
||||
|
||||
|
|
|
|||
Reference in a new issue