src/structs/minichannel.rs

be4224817b612a60266af4f70f7e6836e60d0e9c
youtube-tui/src/structs/minichannel.rs history · blame · raw

41 lines · 1141 bytes

 1use invidious::structs::hidden::SearchItem;
 2use serde::{Deserialize, Serialize};
 3use thousands::Separable;
 4
 5#[derive(Debug, Clone, Serialize, Deserialize)]
 6pub struct MiniChannel {
 7    pub author: String,
 8    pub author_url: String,
 9    pub author_id: String,
10    pub thumbnail: String,
11    pub description: String,
12    pub sub_count: String,
13    pub video_count: String,
14}
15
16impl From<SearchItem> for MiniChannel {
17    fn from(original: SearchItem) -> Self {
18        match original {
19            SearchItem::Channel {
20                author,
21                authorId,
22                authorUrl,
23                authorThumbnails,
24                subCount,
25                videoCount,
26                description,
27                descriptionHtml: _,
28            } => Self {
29                author,
30                author_id: authorId,
31                author_url: authorUrl,
32                thumbnail: authorThumbnails[4].url.clone(),
33                description,
34                sub_count: subCount.separate_with_commas(),
35                video_count: videoCount.to_string(),
36            },
37
38            _ => unreachable!(),
39        }
40    }
41}