43 lines
917 B
Rust
43 lines
917 B
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum YtDlpItem {
|
|
PlaylistItem {
|
|
id: String,
|
|
url: String,
|
|
title: String,
|
|
duration: Option<f64>,
|
|
playlist_index: Option<i32>,
|
|
},
|
|
VideoItem {
|
|
id: String,
|
|
webpage_url: String,
|
|
title: String,
|
|
duration: Option<f64>,
|
|
},
|
|
}
|
|
|
|
impl YtDlpItem {
|
|
pub fn get_title(&self) -> &str {
|
|
match self {
|
|
YtDlpItem::PlaylistItem { title, .. } => title,
|
|
YtDlpItem::VideoItem { title, .. } => title,
|
|
}
|
|
}
|
|
|
|
pub fn get_url(&self) -> &str {
|
|
match self {
|
|
YtDlpItem::PlaylistItem { url, .. } => url,
|
|
YtDlpItem::VideoItem { webpage_url, .. } => webpage_url,
|
|
}
|
|
}
|
|
|
|
pub fn get_duration(&self) -> Option<f64> {
|
|
match self {
|
|
YtDlpItem::PlaylistItem { duration, .. } => *duration,
|
|
YtDlpItem::VideoItem { duration, .. } => *duration,
|
|
}
|
|
}
|
|
}
|