add player data mapping
This commit is contained in:
parent
edee1d2cfa
commit
46730ee8fa
11 changed files with 777 additions and 77 deletions
119
src/model/mod.rs
Normal file
119
src/model/mod.rs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
use std::ops::Range;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct PlayerData {
|
||||
pub info: VideoInfo,
|
||||
pub video_streams: Vec<VideoStream>,
|
||||
pub video_only_streams: Vec<VideoStream>,
|
||||
pub audio_streams: Vec<AudioStream>,
|
||||
pub subtitles: Vec<Subtitle>,
|
||||
pub expires_in_seconds: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct VideoInfo {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub length: u32,
|
||||
pub thumbnails: Vec<Thumbnail>,
|
||||
|
||||
pub channel_id: String,
|
||||
pub channel_name: String,
|
||||
|
||||
pub publish_date: Option<NaiveDate>,
|
||||
pub upload_date: Option<NaiveDate>,
|
||||
pub view_count: u64,
|
||||
pub keywords: Vec<String>,
|
||||
pub category: Option<String>,
|
||||
pub is_live_content: bool,
|
||||
pub is_family_safe: Option<bool>,
|
||||
|
||||
// pub like_count: Option<u32>,
|
||||
// pub dislike_count: Option<u32>
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct VideoStream {
|
||||
pub url: String,
|
||||
pub itag: u32,
|
||||
pub bitrate: u32,
|
||||
pub average_bitrate: u32,
|
||||
pub size: u64,
|
||||
pub index_range: Option<Range<u32>>,
|
||||
pub init_range: Option<Range<u32>>,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub fps: u8,
|
||||
pub quality: String,
|
||||
pub hdr: bool,
|
||||
pub mime: String,
|
||||
pub codec: VideoCodec,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct AudioStream {
|
||||
pub url: String,
|
||||
pub itag: u32,
|
||||
pub bitrate: u32,
|
||||
pub average_bitrate: u32,
|
||||
pub size: u64,
|
||||
pub index_range: Option<Range<u32>>,
|
||||
pub init_range: Option<Range<u32>>,
|
||||
pub mime: String,
|
||||
pub codec: AudioCodec,
|
||||
}
|
||||
|
||||
#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum VideoCodec {
|
||||
#[default]
|
||||
Unknown,
|
||||
/// avc1 aka H.264: https://en.wikipedia.org/wiki/Advanced_Video_Coding
|
||||
Avc1,
|
||||
/// VP9: https://en.wikipedia.org/wiki/VP9
|
||||
Vp9,
|
||||
/// AV1, the latest codec: https://en.wikipedia.org/wiki/AV1
|
||||
Av01,
|
||||
}
|
||||
|
||||
/*
|
||||
impl VideoCodec {
|
||||
pub fn from_mime_type(mime_type: &str) -> Self {
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum AudioCodec {
|
||||
#[default]
|
||||
Unknown,
|
||||
/// MP4A aka AAC: https://en.wikipedia.org/wiki/Advanced_Audio_Coding
|
||||
Mp4A,
|
||||
/// Opus: https://en.wikipedia.org/wiki/Opus_(audio_format)
|
||||
Opus
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct Thumbnail {
|
||||
pub url: String,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct Subtitle {
|
||||
pub url: String,
|
||||
pub locale: Locale,
|
||||
pub auto_generated: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct Locale {
|
||||
pub lang: String,
|
||||
pub country: String,
|
||||
}
|
||||
Reference in a new issue