feat: add frameset

This commit is contained in:
ThetaDev 2023-04-24 23:56:17 +02:00
parent e184341625
commit aa5cd47dcd
12 changed files with 339 additions and 10 deletions

61
src/model/frameset.rs Normal file
View file

@ -0,0 +1,61 @@
use serde::{Deserialize, Serialize};
/// Set of video frames for seek preview
///
/// YouTube generates a set of images containing a grid of frames for each video.
/// These images are used by the player for the seekbar preview.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[non_exhaustive]
pub struct Frameset {
/// Url template of the frameset
///
/// The `$M` placeholder has to be replaced with the page index (starting from 0).
pub url_template: String,
/// Width of a single frame in pixels
pub frame_width: u32,
/// Height of a single frame in pixels
pub frame_height: u32,
/// Number of pages (individual images)
pub page_count: u32,
/// Total number of frames in the set
pub total_count: u32,
/// Duration per frame in milliseconds
pub duration_per_frame: u32,
/// Number of frames in the x direction
pub frames_per_page_x: u32,
/// Number of frames in the y direction.
pub frames_per_page_y: u32,
}
/// Iterator producing frameset page urls
pub struct FramesetUrls<'a> {
frameset: &'a Frameset,
i: u32,
}
impl Frameset {
/// Gets an iterator over the page URLs of the frameset
pub fn urls(&self) -> FramesetUrls {
FramesetUrls {
frameset: self,
i: 0,
}
}
}
impl Iterator for FramesetUrls<'_> {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
if self.i < self.frameset.page_count {
let url = self
.frameset
.url_template
.replace("$M", &self.i.to_string());
self.i += 1;
Some(url)
} else {
None
}
}
}

View file

@ -1,23 +1,22 @@
//! YouTube API response models
mod convert;
mod frameset;
mod ordering;
pub mod paginator;
pub mod richtext;
pub mod traits;
use serde_with::serde_as;
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 crate::{error::Error, param::Country, serializer::DateYmd, util};
use self::{paginator::Paginator, richtext::RichText};
use crate::{error::Error, param::Country, serializer::DateYmd, util};
/*
#COMMON
@ -155,6 +154,8 @@ pub struct VideoPlayer {
pub hls_manifest_url: Option<String>,
/// Dash manifest URL (for livestreams)
pub dash_manifest_url: Option<String>,
/// Video frames for seek preview
pub preview_frames: Vec<Frameset>,
/// YouTube visitor data cookie
pub visitor_data: Option<String>,
}