use crate::prelude::DownloadError;
use self::{
index::VideoIndex,
info::VideoDataInfo,
length_text::VideoLengthText,
menu::Menu,
nav_endpoint::NavigationEndpoint,
short_by_line_text::ShortBylineText,
thumbnail::{ThumbnailData, ThumbnailOverlay},
title::VideoTitle,
};
mod index;
mod info;
mod length_text;
mod menu;
mod nav_endpoint;
mod short_by_line_text;
mod thumbnail;
mod title;
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct SkippedFields {}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct VideoData {
#[serde(rename = "videoId")]
pub video_id: String,
pub thumbnail: ThumbnailData,
pub title: VideoTitle,
pub index: VideoIndex,
#[serde(rename = "shortBylineText")]
pub short_byline_text: ShortBylineText,
#[serde(rename = "lengthText")]
pub length_text: VideoLengthText,
#[serde(rename = "navigationEndpoint")]
pub navigation_endpoint: NavigationEndpoint,
#[serde(rename = "lengthSeconds")]
pub length_seconds: String,
#[serde(rename = "trackingParams")]
pub tracking_params: String,
#[serde(rename = "isPlayable")]
pub is_playable: bool,
pub menu: Menu,
#[serde(rename = "thumbnailOverlays")]
pub thumbnail_overlays: Vec<ThumbnailOverlay>,
#[serde(rename = "videoInfo")]
pub video_info: VideoDataInfo,
}
impl VideoData {
pub fn get_title(&self) -> Result<String, DownloadError> {
Ok(self
.title
.runs
.get(0)
.ok_or_else(|| {
DownloadError::YoutubeError(format!(
"Could not retrieve title of video with id `{}`",
self.video_id
))
})?
.text
.to_owned())
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct AccessibilityDataWrapper {
#[serde(rename = "accessibilityData")]
pub accessibility_data: AccessibilityData,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct AccessibilityData {
pub label: String,
}