src/structs/fullplaylist.rs
46 lines · 1478 bytes
1use chrono::{DateTime, NaiveDateTime, Utc};
2use invidious::structs::universal::Playlist;
3use serde::{Deserialize, Serialize};
4
5use super::MiniVideo;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct FullPlayList {
9 pub title: String,
10 pub playlist_id: String,
11 pub video_count: usize,
12 pub views: usize,
13 pub updated: String,
14 pub thumbnail: Option<String>,
15 pub description: String,
16 pub author: String,
17 pub author_id: String,
18 pub videos: Vec<MiniVideo>,
19}
20
21impl From<Playlist> for FullPlayList {
22 fn from(original: Playlist) -> Self {
23 Self {
24 title: original.title,
25 playlist_id: original.playlistId,
26 video_count: original.videoCount as usize,
27 views: original.viewCount as usize,
28 updated: {
29 let datetime: DateTime<Utc> = DateTime::from_utc(
30 NaiveDateTime::from_timestamp(original.updated as i64, 0),
31 Utc,
32 );
33 format!(" [{}]", datetime.format("%Y/%m/%d"))
34 },
35 thumbnail: if original.videos.len() == 0 {
36 None
37 } else {
38 Some(original.videos[0].videoThumbnails[4].url.clone())
39 },
40 description: original.description,
41 author: original.author,
42 author_id: original.authorId,
43 videos: original.videos.into_iter().map(MiniVideo::from).collect(),
44 }
45 }
46}