src/structs/miniplaylist.rs

9aedf4a98dfbe60cee47b4e673a37437e309f462
youtube-tui/src/structs/miniplaylist.rs history · blame · raw

63 lines · 1778 bytes

 1use invidious::structs::hidden::{Playlist, SearchItem};
 2use serde::{Deserialize, Serialize};
 3
 4#[derive(Debug, Clone, Deserialize, Serialize)]
 5pub struct MiniPlayList {
 6    pub title: String,
 7    pub playlist_id: String,
 8    pub author: String,
 9    pub author_id: String,
10    pub author_url: String,
11    pub video_count: usize,
12    pub thumbnail: Option<String>,
13}
14
15impl From<SearchItem> for MiniPlayList {
16    fn from(original: SearchItem) -> Self {
17        match original {
18            SearchItem::Playlist {
19                title,
20                playlistId,
21                author,
22                authorId,
23                authorUrl,
24                videoCount,
25                videos,
26            } => MiniPlayList {
27                title,
28                playlist_id: playlistId,
29                author,
30                author_id: authorId,
31                author_url: authorUrl,
32                video_count: videoCount as usize,
33                thumbnail: if videos.len() == 0 {
34                    None
35                } else {
36                    Some(videos[0].videoThumbnails[4].url.clone())
37                },
38            },
39
40            _ => {
41                unreachable!()
42            }
43        }
44    }
45}
46
47impl From<Playlist> for MiniPlayList {
48    fn from(original: Playlist) -> Self {
49        Self {
50            title: original.title,
51            playlist_id: original.playlistId,
52            author: original.author,
53            author_id: original.authorId,
54            author_url: original.authorUrl,
55            video_count: original.videoCount as usize,
56            thumbnail: if original.videos.len() == 0 {
57                None
58            } else {
59                Some(original.videos[0].videoThumbnails[4].url.clone())
60            },
61        }
62    }
63}