Commit 81c019f4cd

81c019f4cdbcf537253b2aa15987e6f900f9e9cf

parent: 48f5025ff6

Unsigned

Siriusmart <sirius@siri.ws> · 2025-10-20 12:41 UTC

re-added support for invidious backend

Layout: unified · split

src/config/search.rs +4 −12
@@ -112,8 +112,7 @@ impl SearchFilters {
112 } 112 }
113} 113}
114 114
115#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)] 115#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
116#[derive(Default)]
117pub enum SearchFilterSort { 116pub enum SearchFilterSort {
118 #[default] 117 #[default]
119 Relevance, 118 Relevance,
@@ -122,8 +121,7 @@ pub enum SearchFilterSort {
122 Views, 121 Views,
123} 122}
124 123
125#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)] 124#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
126#[derive(Default)]
127pub enum SearchFilterDate { 125pub enum SearchFilterDate {
128 #[default] 126 #[default]
129 None, 127 None,
@@ -134,8 +132,7 @@ pub enum SearchFilterDate {
134 Year, 132 Year,
135} 133}
136 134
137#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)] 135#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
138#[derive(Default)]
139pub enum SearchFilterDuration { 136pub enum SearchFilterDuration {
140 #[default] 137 #[default]
141 None, 138 None,
@@ -144,8 +141,7 @@ pub enum SearchFilterDuration {
144 Long, 141 Long,
145} 142}
146 143
147#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)] 144#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
148#[derive(Default)]
149pub enum SearchFilterType { 145pub enum SearchFilterType {
150 #[default] 146 #[default]
151 All, 147 All,
@@ -154,10 +150,6 @@ pub enum SearchFilterType {
154 Playlist, 150 Playlist,
155} 151}
156 152
157
158
159
160
161impl Display for SearchFilterSort { 153impl Display for SearchFilterSort {
162 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 154 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163 f.write_str(match self { 155 f.write_str(match self {
src/config/serde.rs +1 −3
@@ -4,8 +4,7 @@ use ratatui::{style::Color, widgets::BorderType};
4use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
5 5
6/// `BorderType` but impl `serde` 6/// `BorderType` but impl `serde`
7#[derive(Serialize, Deserialize, Clone, Copy)] 7#[derive(Serialize, Deserialize, Clone, Copy, Default)]
8#[derive(Default)]
9pub enum BorderTypeSerde { 8pub enum BorderTypeSerde {
10 Plain, 9 Plain,
11 #[default] 10 #[default]
@@ -14,7 +13,6 @@ pub enum BorderTypeSerde {
14 Thick, 13 Thick,
15} 14}
16 15
17
18impl From<BorderTypeSerde> for BorderType { 16impl From<BorderTypeSerde> for BorderType {
19 fn from(origianl: BorderTypeSerde) -> BorderType { 17 fn from(origianl: BorderTypeSerde) -> BorderType {
20 match origianl { 18 match origianl {
src/global/common/exposed/channel/channel.rs +1 −1
@@ -31,7 +31,7 @@ pub struct Channel {
31 pub allowed_regions: Vec<CountryCode>, 31 pub allowed_regions: Vec<CountryCode>,
32 32
33 #[serde(rename = "latestVideos")] 33 #[serde(rename = "latestVideos")]
34 pub lastest_videos: Vec<CommonVideo>, 34 pub latest_videos: Vec<CommonVideo>,
35 35
36 #[serde(rename = "relatedChannels")] 36 #[serde(rename = "relatedChannels")]
37 pub related_channels: Vec<RelatedChannel>, 37 pub related_channels: Vec<RelatedChannel>,
src/global/functions/from_url.rs +18 −9
@@ -6,7 +6,7 @@ fn is_id_char(c: char) -> bool {
6pub fn from_channel_url(identifier: &str) -> Result<String, String> { 6pub fn from_channel_url(identifier: &str) -> Result<String, String> {
7 // if it doesnt look like a url, just assume it is an identifier 7 // if it doesnt look like a url, just assume it is an identifier
8 if identifier.chars().all(is_id_char) { 8 if identifier.chars().all(is_id_char) {
9 return Ok(identifier.to_string()) 9 return Ok(identifier.to_string());
10 } 10 }
11 11
12 let index = if let Some(index) = identifier.find("/channel/") { 12 let index = if let Some(index) = identifier.find("/channel/") {
@@ -15,44 +15,53 @@ pub fn from_channel_url(identifier: &str) -> Result<String, String> {
15 return Err(format!("Cannot find channel id from string `{identifier}`")); 15 return Err(format!("Cannot find channel id from string `{identifier}`"));
16 }; 16 };
17 17
18 Ok(identifier[index..].chars().take_while(|c| is_id_char(*c)).collect()) 18 Ok(identifier[index..]
19 .chars()
20 .take_while(|c| is_id_char(*c))
21 .collect())
19} 22}
20 23
21pub fn from_video_url(identifier: &str) -> Result<String, String> { 24pub fn from_video_url(identifier: &str) -> Result<String, String> {
22 if identifier.chars().all(is_id_char) { 25 if identifier.chars().all(is_id_char) {
23 return Ok(identifier.to_string()) 26 return Ok(identifier.to_string());
24 } 27 }
25 28
26 let index = if let Some(index) = identifier.find("?v=") { 29 let index = if let Some(index) = identifier.find("?v=") {
27 index + 3 30 index + 3
28 // and also "youtu.be/" 31 // and also "youtu.be/"
29 } else if let Some(index) = identifier.find("youtu.be/") { 32 } else if let Some(index) = identifier.find("youtu.be/") {
30 index + 9 33 index + 9
31 } else { 34 } else {
32 return Err(format!("Cannot find video id from string `{identifier}`")); 35 return Err(format!("Cannot find video id from string `{identifier}`"));
33 }; 36 };
34 37
35 Ok(identifier[index..].chars().take_while(|c| is_id_char(*c)).collect()) 38 Ok(identifier[index..]
39 .chars()
40 .take_while(|c| is_id_char(*c))
41 .collect())
36} 42}
37 43
38pub fn from_playlist_url(identifier: &str) -> Result<String, String> { 44pub fn from_playlist_url(identifier: &str) -> Result<String, String> {
39 if identifier.chars().all(is_id_char) { 45 if identifier.chars().all(is_id_char) {
40 return Ok(identifier.to_string()) 46 return Ok(identifier.to_string());
41 } 47 }
42 48
43 // the id can come after "list=" in urls 49 // the id can come after "list=" in urls
44 let index = if let Some(index) = identifier.find("list=") { 50 let index = if let Some(index) = identifier.find("list=") {
45 if identifier.len() < index + 39 { 51 if identifier.len() < index + 39 {
46 return Err(format!( 52 return Err(format!(
47 "Cannot find plalyist id from string `{identifier}`" 53 "Cannot find plalyist id from string `{identifier}`"
48 )); 54 ));
49 } 55 }
50 index + 5 56 index + 5
51 } else { 57 } else {
52 return Err(format!( 58 return Err(format!(
53 "Cannot find playlist id from string `{identifier}`" 59 "Cannot find playlist id from string `{identifier}`"
54 )); 60 ));
55 }; 61 };
56 62
57 Ok(identifier[index..].chars().take_while(|c| is_id_char(*c)).collect()) 63 Ok(identifier[index..]
64 .chars()
65 .take_while(|c| is_id_char(*c))
66 .collect())
58} 67}
src/global/functions/singleitem_load.rs +8 −10
@@ -2,8 +2,8 @@ use crate::{
2 config::MainConfig, 2 config::MainConfig,
3 global::{functions::download_all_images, structs::Item, traits::SearchProviderWrapper}, 3 global::{functions::download_all_images, structs::Item, traits::SearchProviderWrapper},
4}; 4};
5use std::{error::Error, fs};
6use home::home_dir; 5use home::home_dir;
6use std::{error::Error, fs};
7 7
8pub fn load_playlist(id: &str, mainconfig: &MainConfig) -> Result<Item, Box<dyn Error>> { 8pub fn load_playlist(id: &str, mainconfig: &MainConfig) -> Result<Item, Box<dyn Error>> {
9 let playlist = 9 let playlist =
@@ -33,7 +33,7 @@ pub fn load_video(id: &str, mainconfig: &MainConfig) -> Result<Item, Box<dyn Err
33pub fn load_channel(id: &str, mainconfig: &MainConfig) -> Result<Item, Box<dyn Error>> { 33pub fn load_channel(id: &str, mainconfig: &MainConfig) -> Result<Item, Box<dyn Error>> {
34 let home_dir = home_dir().unwrap(); 34 let home_dir = home_dir().unwrap();
35 let cache_path = home_dir.join(format!(".cache/youtube-tui/channels/{id}.json")); 35 let cache_path = home_dir.join(format!(".cache/youtube-tui/channels/{id}.json"));
36 36
37 if cache_path.exists() { 37 if cache_path.exists() {
38 if let Ok(content) = fs::read_to_string(&cache_path) { 38 if let Ok(content) = fs::read_to_string(&cache_path) {
39 if let Ok(item) = serde_json::from_str::<Item>(&content) { 39 if let Ok(item) = serde_json::from_str::<Item>(&content) {
@@ -41,20 +41,18 @@ pub fn load_channel(id: &str, mainconfig: &MainConfig) -> Result<Item, Box<dyn E
41 } 41 }
42 } 42 }
43 } 43 }
44 44
45 let channel = Item::from_full_channel( 45 let channel =
46 SearchProviderWrapper::channel(id)?, 46 Item::from_full_channel(SearchProviderWrapper::channel(id)?, mainconfig.image_index);
47 mainconfig.image_index, 47
48 );
49
50 if let Some(parent) = cache_path.parent() { 48 if let Some(parent) = cache_path.parent() {
51 fs::create_dir_all(parent)?; 49 fs::create_dir_all(parent)?;
52 } 50 }
53 fs::write(&cache_path, serde_json::to_string(&channel)?)?; 51 fs::write(&cache_path, serde_json::to_string(&channel)?)?;
54 52
55 if mainconfig.images.display() { 53 if mainconfig.images.display() {
56 download_all_images(vec![(&channel).into()]); 54 download_all_images(vec![(&channel).into()]);
57 } 55 }
58 56
59 Ok(channel) 57 Ok(channel)
60} 58}
src/global/structs/invidiousclient.rs +641 −32
@@ -3,7 +3,7 @@ use invidious::{ClientSync, ClientSyncTrait};
3use crate::global::traits::SearchProviderTrait; 3use crate::global::traits::SearchProviderTrait;
4 4
5// used in `data.global` 5// used in `data.global`
6/// Holds the invidious client 6/// Holds the crate::global::common client
7#[derive(Clone)] 7#[derive(Clone)]
8pub struct InvidiousClient(pub ClientSync); 8pub struct InvidiousClient(pub ClientSync);
9 9
@@ -13,13 +13,609 @@ impl InvidiousClient {
13 } 13 }
14} 14}
15 15
16impl From<invidious::hidden::Storyboard> for crate::global::common::hidden::Storyboard {
17 fn from(value: invidious::hidden::Storyboard) -> Self {
18 Self {
19 url: value.url,
20 template_url: value.template_url,
21 width: value.width,
22 height: value.height,
23 count: value.count,
24 interval: value.interval,
25 storyboard_width: value.storyboard_width,
26 storyboard_height: value.storyboard_height,
27 storyboard_count: value.storyboard_count,
28 }
29 }
30}
31
32impl From<invidious::CommonThumbnail> for crate::global::common::CommonThumbnail {
33 fn from(value: invidious::CommonThumbnail) -> Self {
34 Self {
35 quality: value.quality,
36 url: value.url,
37 width: value.width,
38 height: value.height,
39 }
40 }
41}
42
43impl From<invidious::hidden::CountryCode> for crate::global::common::hidden::CountryCode {
44 fn from(value: invidious::hidden::CountryCode) -> Self {
45 match value {
46 invidious::hidden::CountryCode::AD => Self::AD,
47 invidious::hidden::CountryCode::AE => Self::AE,
48 invidious::hidden::CountryCode::AF => Self::AF,
49 invidious::hidden::CountryCode::AG => Self::AG,
50 invidious::hidden::CountryCode::AI => Self::AI,
51 invidious::hidden::CountryCode::AL => Self::AL,
52 invidious::hidden::CountryCode::AM => Self::AM,
53 invidious::hidden::CountryCode::AO => Self::AO,
54 invidious::hidden::CountryCode::AQ => Self::AQ,
55 invidious::hidden::CountryCode::AR => Self::AR,
56 invidious::hidden::CountryCode::AS => Self::AS,
57 invidious::hidden::CountryCode::AT => Self::AT,
58 invidious::hidden::CountryCode::AU => Self::AU,
59 invidious::hidden::CountryCode::AW => Self::AW,
60 invidious::hidden::CountryCode::AX => Self::AX,
61 invidious::hidden::CountryCode::AZ => Self::AZ,
62 invidious::hidden::CountryCode::BA => Self::BA,
63 invidious::hidden::CountryCode::BB => Self::BB,
64 invidious::hidden::CountryCode::BD => Self::BD,
65 invidious::hidden::CountryCode::BE => Self::BE,
66 invidious::hidden::CountryCode::BF => Self::BF,
67 invidious::hidden::CountryCode::BG => Self::BG,
68 invidious::hidden::CountryCode::BH => Self::BH,
69 invidious::hidden::CountryCode::BI => Self::BI,
70 invidious::hidden::CountryCode::BJ => Self::BJ,
71 invidious::hidden::CountryCode::BL => Self::BL,
72 invidious::hidden::CountryCode::BM => Self::BM,
73 invidious::hidden::CountryCode::BN => Self::BN,
74 invidious::hidden::CountryCode::BO => Self::BO,
75 invidious::hidden::CountryCode::BQ => Self::BQ,
76 invidious::hidden::CountryCode::BR => Self::BR,
77 invidious::hidden::CountryCode::BS => Self::BS,
78 invidious::hidden::CountryCode::BT => Self::BT,
79 invidious::hidden::CountryCode::BV => Self::BV,
80 invidious::hidden::CountryCode::BW => Self::BW,
81 invidious::hidden::CountryCode::BY => Self::BY,
82 invidious::hidden::CountryCode::BZ => Self::BZ,
83 invidious::hidden::CountryCode::CA => Self::CA,
84 invidious::hidden::CountryCode::CC => Self::CC,
85 invidious::hidden::CountryCode::CD => Self::CD,
86 invidious::hidden::CountryCode::CF => Self::CF,
87 invidious::hidden::CountryCode::CG => Self::CG,
88 invidious::hidden::CountryCode::CH => Self::CH,
89 invidious::hidden::CountryCode::CI => Self::CI,
90 invidious::hidden::CountryCode::CK => Self::CK,
91 invidious::hidden::CountryCode::CL => Self::CL,
92 invidious::hidden::CountryCode::CM => Self::CM,
93 invidious::hidden::CountryCode::CN => Self::CN,
94 invidious::hidden::CountryCode::CO => Self::CO,
95 invidious::hidden::CountryCode::CR => Self::CR,
96 invidious::hidden::CountryCode::CU => Self::CU,
97 invidious::hidden::CountryCode::CV => Self::CV,
98 invidious::hidden::CountryCode::CW => Self::CW,
99 invidious::hidden::CountryCode::CX => Self::CX,
100 invidious::hidden::CountryCode::CY => Self::CY,
101 invidious::hidden::CountryCode::CZ => Self::CZ,
102 invidious::hidden::CountryCode::DE => Self::DE,
103 invidious::hidden::CountryCode::DJ => Self::DJ,
104 invidious::hidden::CountryCode::DK => Self::DK,
105 invidious::hidden::CountryCode::DM => Self::DM,
106 invidious::hidden::CountryCode::DO => Self::DO,
107 invidious::hidden::CountryCode::DZ => Self::DZ,
108 invidious::hidden::CountryCode::EC => Self::EC,
109 invidious::hidden::CountryCode::EE => Self::EE,
110 invidious::hidden::CountryCode::EG => Self::EG,
111 invidious::hidden::CountryCode::EH => Self::EH,
112 invidious::hidden::CountryCode::ER => Self::ER,
113 invidious::hidden::CountryCode::ES => Self::ES,
114 invidious::hidden::CountryCode::ET => Self::ET,
115 invidious::hidden::CountryCode::FI => Self::FI,
116 invidious::hidden::CountryCode::FJ => Self::FJ,
117 invidious::hidden::CountryCode::FK => Self::FK,
118 invidious::hidden::CountryCode::FM => Self::FM,
119 invidious::hidden::CountryCode::FO => Self::FO,
120 invidious::hidden::CountryCode::FR => Self::FR,
121 invidious::hidden::CountryCode::GA => Self::GA,
122 invidious::hidden::CountryCode::GB => Self::GB,
123 invidious::hidden::CountryCode::GD => Self::GD,
124 invidious::hidden::CountryCode::GE => Self::GE,
125 invidious::hidden::CountryCode::GF => Self::GF,
126 invidious::hidden::CountryCode::GG => Self::GG,
127 invidious::hidden::CountryCode::GH => Self::GH,
128 invidious::hidden::CountryCode::GI => Self::GI,
129 invidious::hidden::CountryCode::GL => Self::GL,
130 invidious::hidden::CountryCode::GM => Self::GM,
131 invidious::hidden::CountryCode::GN => Self::GN,
132 invidious::hidden::CountryCode::GP => Self::GP,
133 invidious::hidden::CountryCode::GQ => Self::GQ,
134 invidious::hidden::CountryCode::GR => Self::GR,
135 invidious::hidden::CountryCode::GS => Self::GS,
136 invidious::hidden::CountryCode::GT => Self::GT,
137 invidious::hidden::CountryCode::GU => Self::GU,
138 invidious::hidden::CountryCode::GW => Self::GW,
139 invidious::hidden::CountryCode::GY => Self::GY,
140 invidious::hidden::CountryCode::HK => Self::HK,
141 invidious::hidden::CountryCode::HM => Self::HM,
142 invidious::hidden::CountryCode::HN => Self::HN,
143 invidious::hidden::CountryCode::HR => Self::HR,
144 invidious::hidden::CountryCode::HT => Self::HT,
145 invidious::hidden::CountryCode::HU => Self::HU,
146 invidious::hidden::CountryCode::ID => Self::ID,
147 invidious::hidden::CountryCode::IE => Self::IE,
148 invidious::hidden::CountryCode::IL => Self::IL,
149 invidious::hidden::CountryCode::IM => Self::IM,
150 invidious::hidden::CountryCode::IN => Self::IN,
151 invidious::hidden::CountryCode::IO => Self::IO,
152 invidious::hidden::CountryCode::IQ => Self::IQ,
153 invidious::hidden::CountryCode::IR => Self::IR,
154 invidious::hidden::CountryCode::IS => Self::IS,
155 invidious::hidden::CountryCode::IT => Self::IT,
156 invidious::hidden::CountryCode::JE => Self::JE,
157 invidious::hidden::CountryCode::JM => Self::JM,
158 invidious::hidden::CountryCode::JO => Self::JO,
159 invidious::hidden::CountryCode::JP => Self::JP,
160 invidious::hidden::CountryCode::KE => Self::KE,
161 invidious::hidden::CountryCode::KG => Self::KG,
162 invidious::hidden::CountryCode::KH => Self::KH,
163 invidious::hidden::CountryCode::KI => Self::KI,
164 invidious::hidden::CountryCode::KM => Self::KM,
165 invidious::hidden::CountryCode::KN => Self::KN,
166 invidious::hidden::CountryCode::KP => Self::KP,
167 invidious::hidden::CountryCode::KR => Self::KR,
168 invidious::hidden::CountryCode::KW => Self::KW,
169 invidious::hidden::CountryCode::KY => Self::KY,
170 invidious::hidden::CountryCode::KZ => Self::KZ,
171 invidious::hidden::CountryCode::LA => Self::LA,
172 invidious::hidden::CountryCode::LB => Self::LB,
173 invidious::hidden::CountryCode::LC => Self::LC,
174 invidious::hidden::CountryCode::LI => Self::LI,
175 invidious::hidden::CountryCode::LK => Self::LK,
176 invidious::hidden::CountryCode::LR => Self::LR,
177 invidious::hidden::CountryCode::LS => Self::LS,
178 invidious::hidden::CountryCode::LT => Self::LT,
179 invidious::hidden::CountryCode::LU => Self::LU,
180 invidious::hidden::CountryCode::LV => Self::LV,
181 invidious::hidden::CountryCode::LY => Self::LY,
182 invidious::hidden::CountryCode::MA => Self::MA,
183 invidious::hidden::CountryCode::MC => Self::MC,
184 invidious::hidden::CountryCode::MD => Self::MD,
185 invidious::hidden::CountryCode::ME => Self::ME,
186 invidious::hidden::CountryCode::MF => Self::MF,
187 invidious::hidden::CountryCode::MG => Self::MG,
188 invidious::hidden::CountryCode::MH => Self::MH,
189 invidious::hidden::CountryCode::MK => Self::MK,
190 invidious::hidden::CountryCode::ML => Self::ML,
191 invidious::hidden::CountryCode::MM => Self::MM,
192 invidious::hidden::CountryCode::MN => Self::MN,
193 invidious::hidden::CountryCode::MO => Self::MO,
194 invidious::hidden::CountryCode::MP => Self::MP,
195 invidious::hidden::CountryCode::MQ => Self::MQ,
196 invidious::hidden::CountryCode::MR => Self::MR,
197 invidious::hidden::CountryCode::MS => Self::MS,
198 invidious::hidden::CountryCode::MT => Self::MT,
199 invidious::hidden::CountryCode::MU => Self::MU,
200 invidious::hidden::CountryCode::MV => Self::MV,
201 invidious::hidden::CountryCode::MW => Self::MW,
202 invidious::hidden::CountryCode::MX => Self::MX,
203 invidious::hidden::CountryCode::MY => Self::MY,
204 invidious::hidden::CountryCode::MZ => Self::MZ,
205 invidious::hidden::CountryCode::NA => Self::NA,
206 invidious::hidden::CountryCode::NC => Self::NC,
207 invidious::hidden::CountryCode::NE => Self::NE,
208 invidious::hidden::CountryCode::NF => Self::NF,
209 invidious::hidden::CountryCode::NG => Self::NG,
210 invidious::hidden::CountryCode::NI => Self::NI,
211 invidious::hidden::CountryCode::NL => Self::NL,
212 invidious::hidden::CountryCode::NO => Self::NO,
213 invidious::hidden::CountryCode::NP => Self::NP,
214 invidious::hidden::CountryCode::NR => Self::NR,
215 invidious::hidden::CountryCode::NU => Self::NU,
216 invidious::hidden::CountryCode::NZ => Self::NZ,
217 invidious::hidden::CountryCode::OM => Self::OM,
218 invidious::hidden::CountryCode::PA => Self::PA,
219 invidious::hidden::CountryCode::PE => Self::PE,
220 invidious::hidden::CountryCode::PF => Self::PF,
221 invidious::hidden::CountryCode::PG => Self::PG,
222 invidious::hidden::CountryCode::PH => Self::PH,
223 invidious::hidden::CountryCode::PK => Self::PK,
224 invidious::hidden::CountryCode::PL => Self::PL,
225 invidious::hidden::CountryCode::PM => Self::PM,
226 invidious::hidden::CountryCode::PN => Self::PN,
227 invidious::hidden::CountryCode::PR => Self::PR,
228 invidious::hidden::CountryCode::PS => Self::PS,
229 invidious::hidden::CountryCode::PT => Self::PT,
230 invidious::hidden::CountryCode::PW => Self::PW,
231 invidious::hidden::CountryCode::PY => Self::PY,
232 invidious::hidden::CountryCode::QA => Self::QA,
233 invidious::hidden::CountryCode::RE => Self::RE,
234 invidious::hidden::CountryCode::RO => Self::RO,
235 invidious::hidden::CountryCode::RS => Self::RS,
236 invidious::hidden::CountryCode::RU => Self::RU,
237 invidious::hidden::CountryCode::RW => Self::RW,
238 invidious::hidden::CountryCode::SA => Self::SA,
239 invidious::hidden::CountryCode::SB => Self::SB,
240 invidious::hidden::CountryCode::SC => Self::SC,
241 invidious::hidden::CountryCode::SD => Self::SD,
242 invidious::hidden::CountryCode::SE => Self::SE,
243 invidious::hidden::CountryCode::SG => Self::SG,
244 invidious::hidden::CountryCode::SH => Self::SH,
245 invidious::hidden::CountryCode::SI => Self::SI,
246 invidious::hidden::CountryCode::SJ => Self::SJ,
247 invidious::hidden::CountryCode::SK => Self::SK,
248 invidious::hidden::CountryCode::SL => Self::SL,
249 invidious::hidden::CountryCode::SM => Self::SM,
250 invidious::hidden::CountryCode::SN => Self::SN,
251 invidious::hidden::CountryCode::SO => Self::SO,
252 invidious::hidden::CountryCode::SR => Self::SR,
253 invidious::hidden::CountryCode::SS => Self::SS,
254 invidious::hidden::CountryCode::ST => Self::ST,
255 invidious::hidden::CountryCode::SV => Self::SV,
256 invidious::hidden::CountryCode::SX => Self::SX,
257 invidious::hidden::CountryCode::SY => Self::SY,
258 invidious::hidden::CountryCode::SZ => Self::SZ,
259 invidious::hidden::CountryCode::TC => Self::TC,
260 invidious::hidden::CountryCode::TD => Self::TD,
261 invidious::hidden::CountryCode::TF => Self::TF,
262 invidious::hidden::CountryCode::TG => Self::TG,
263 invidious::hidden::CountryCode::TH => Self::TH,
264 invidious::hidden::CountryCode::TJ => Self::TJ,
265 invidious::hidden::CountryCode::TK => Self::TK,
266 invidious::hidden::CountryCode::TL => Self::TL,
267 invidious::hidden::CountryCode::TM => Self::TM,
268 invidious::hidden::CountryCode::TN => Self::TN,
269 invidious::hidden::CountryCode::TO => Self::TO,
270 invidious::hidden::CountryCode::TR => Self::TR,
271 invidious::hidden::CountryCode::TT => Self::TT,
272 invidious::hidden::CountryCode::TV => Self::TV,
273 invidious::hidden::CountryCode::TW => Self::TW,
274 invidious::hidden::CountryCode::TZ => Self::TZ,
275 invidious::hidden::CountryCode::UA => Self::UA,
276 invidious::hidden::CountryCode::UG => Self::UG,
277 invidious::hidden::CountryCode::UM => Self::UM,
278 invidious::hidden::CountryCode::US => Self::US,
279 invidious::hidden::CountryCode::UY => Self::UY,
280 invidious::hidden::CountryCode::UZ => Self::UZ,
281 invidious::hidden::CountryCode::VA => Self::VA,
282 invidious::hidden::CountryCode::VC => Self::VC,
283 invidious::hidden::CountryCode::VE => Self::VE,
284 invidious::hidden::CountryCode::VG => Self::VG,
285 invidious::hidden::CountryCode::VI => Self::VI,
286 invidious::hidden::CountryCode::VN => Self::VN,
287 invidious::hidden::CountryCode::VU => Self::VU,
288 invidious::hidden::CountryCode::WF => Self::WF,
289 invidious::hidden::CountryCode::WS => Self::WS,
290 invidious::hidden::CountryCode::YE => Self::YE,
291 invidious::hidden::CountryCode::YT => Self::YT,
292 invidious::hidden::CountryCode::ZA => Self::ZA,
293 invidious::hidden::CountryCode::ZM => Self::ZM,
294 invidious::hidden::CountryCode::ZW => Self::ZW,
295 }
296 }
297}
298
299impl From<invidious::hidden::AdaptiveFormat> for crate::global::common::hidden::AdaptiveFormat {
300 fn from(value: invidious::hidden::AdaptiveFormat) -> Self {
301 Self {
302 index: value.index,
303 bitrate: value.bitrate,
304 init: value.init,
305 url: value.url,
306 itag: value.itag,
307 r#type: value.r#type,
308 clen: value.clen,
309 lmt: value.lmt,
310 projection_type: value.projection_type,
311 fps: value.fps,
312 container: value.container,
313 encoding: value.encoding,
314 quality: value.quality,
315 resolution: value.resolution,
316 quality_label: value.quality_label,
317 audio_quality: value.audio_quality,
318 audio_sample_rate: value.audio_sample_rate,
319 audio_channels: value.audio_channels,
320 }
321 }
322}
323
324impl From<invidious::CommonImage> for crate::global::common::CommonImage {
325 fn from(value: invidious::CommonImage) -> Self {
326 Self {
327 url: value.url,
328 width: value.width,
329 height: value.height,
330 }
331 }
332}
333
334impl From<invidious::hidden::FormatStream> for crate::global::common::hidden::FormatStream {
335 fn from(value: invidious::hidden::FormatStream) -> Self {
336 Self {
337 url: value.url,
338 itag: value.itag,
339 r#type: value.r#type,
340 quality: value.quality,
341 container: value.container,
342 encoding: value.encoding,
343 quality_label: value.quality_label,
344 resolution: value.resolution,
345 size: value.size,
346 }
347 }
348}
349
350impl From<invidious::hidden::Caption> for crate::global::common::hidden::Caption {
351 fn from(value: invidious::hidden::Caption) -> Self {
352 Self {
353 label: value.label,
354 language: value.language,
355 url: value.url,
356 }
357 }
358}
359
360impl From<invidious::hidden::VideoShort> for crate::global::common::hidden::VideoShort {
361 fn from(value: invidious::hidden::VideoShort) -> Self {
362 Self {
363 id: value.id,
364 title: value.title,
365 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
366 author: value.author,
367 length: value.length,
368 views_text: value.views_text,
369 }
370 }
371}
372
373impl From<invidious::video::Video> for crate::global::common::video::Video {
374 fn from(value: invidious::video::Video) -> Self {
375 Self {
376 r#type: value.r#type,
377 title: value.title,
378 id: value.id,
379 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
380 storyboards: value.storyboards.into_iter().map(|v| v.into()).collect(),
381 description: value.description,
382 description_html: value.description_html,
383 published: value.published,
384 published_text: value.published_text,
385 keywords: value.keywords,
386 views: value.views,
387 likes: value.likes,
388 dislikes: value.dislikes,
389 paid: value.paid,
390 premium: value.premium,
391 family_friendly: value.family_friendly,
392 allowed_regions: value
393 .allowed_regions
394 .into_iter()
395 .map(|v| v.into())
396 .collect(),
397 genre: value.genre,
398 genre_url: value.genre_url,
399 author: value.author,
400 author_id: value.author_id,
401 author_url: value.author_url,
402 author_thumbnails: value
403 .author_thumbnails
404 .into_iter()
405 .map(|v| v.into())
406 .collect(),
407 sub_count_text: value.sub_count_text,
408 length: value.length,
409 allow_ratings: value.allow_ratings,
410 rating: value.rating,
411 listed: value.listed,
412 live: value.live,
413 upcoming: value.upcoming,
414 premiere_timestamp: value.premiere_timestamp,
415 dash: value.dash,
416 adaptive_formats: value
417 .adaptive_formats
418 .into_iter()
419 .map(|v| v.into())
420 .collect(),
421 format_streams: value.format_streams.into_iter().map(|v| v.into()).collect(),
422 captions: value.captions.into_iter().map(|v| v.into()).collect(),
423 recommended_videos: value
424 .recommended_videos
425 .into_iter()
426 .map(|v| v.into())
427 .collect(),
428 }
429 }
430}
431
432impl From<invidious::CommonVideo> for crate::global::common::CommonVideo {
433 fn from(value: invidious::CommonVideo) -> Self {
434 Self {
435 title: value.title,
436 id: value.id,
437 author: value.author,
438 author_id: value.author_id,
439 author_url: value.author_url,
440 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
441 description: value.description,
442 description_html: value.description_html,
443 views: value.views,
444 length: value.length,
445 published: value.published,
446 published_text: value.published_text,
447 premiere_timestamp: value.premiere_timestamp,
448 live: value.live,
449 premium: value.premium,
450 upcoming: value.upcoming,
451 }
452 }
453}
454
455impl From<invidious::CommonPlaylist> for crate::global::common::CommonPlaylist {
456 fn from(value: invidious::CommonPlaylist) -> Self {
457 Self {
458 title: value.title,
459 id: value.id,
460 thumbnail: value.thumbnail,
461 author: value.author,
462 author_id: value.author_id,
463 author_verified: value.author_verified,
464 video_count: value.video_count,
465 videos: value.videos.into_iter().map(|v| v.into()).collect(),
466 }
467 }
468}
469
470impl From<invidious::CommonPlaylistVideo> for crate::global::common::CommonPlaylistVideo {
471 fn from(value: invidious::CommonPlaylistVideo) -> Self {
472 Self {
473 title: value.title,
474 id: value.id,
475 length: value.length,
476 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
477 }
478 }
479}
480
481impl From<invidious::CommonChannel> for crate::global::common::CommonChannel {
482 fn from(value: invidious::CommonChannel) -> Self {
483 Self {
484 name: value.name,
485 id: value.id,
486 url: value.url,
487 verified: value.verified,
488 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
489 auto_generated: value.auto_generated,
490 subscribers: value.subscribers,
491 video_count: value.video_count,
492 description: value.description,
493 description_html: value.description_html,
494 }
495 }
496}
497
498impl From<invidious::hidden::SearchItem> for crate::global::common::hidden::SearchItem {
499 fn from(value: invidious::hidden::SearchItem) -> Self {
500 match value {
501 invidious::hidden::SearchItem::Video(video) => Self::Video(video.into()),
502 invidious::hidden::SearchItem::Playlist(pl) => Self::Playlist(pl.into()),
503 invidious::hidden::SearchItem::Channel(ch) => Self::Channel(ch.into()),
504 }
505 }
506}
507
508impl From<invidious::channel::Channel> for crate::global::common::channel::Channel {
509 fn from(value: invidious::channel::Channel) -> Self {
510 Self {
511 name: value.name,
512 id: value.id,
513 url: value.url,
514 banners: value.banners.into_iter().map(|v| v.into()).collect(),
515 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
516 subscribers: value.subscribers,
517 total_views: value.total_views,
518 joined: value.joined,
519 auto_generated: value.auto_generated,
520 family_friendly: value.family_friendly,
521 description: value.description,
522 description_html: value.description_html,
523 allowed_regions: value
524 .allowed_regions
525 .into_iter()
526 .map(|v| v.into())
527 .collect(),
528 latest_videos: value.lastest_videos.into_iter().map(|v| v.into()).collect(),
529 related_channels: value
530 .related_channels
531 .into_iter()
532 .map(|v| v.into())
533 .collect(),
534 }
535 }
536}
537
538impl From<invidious::hidden::RelatedChannel> for crate::global::common::hidden::RelatedChannel {
539 fn from(value: invidious::hidden::RelatedChannel) -> Self {
540 Self {
541 name: value.name,
542 id: value.id,
543 url: value.url,
544 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
545 }
546 }
547}
548
549impl From<invidious::hidden::PopularItem> for crate::global::common::hidden::PopularItem {
550 fn from(value: invidious::hidden::PopularItem) -> Self {
551 Self {
552 r#type: value.r#type,
553 title: value.title,
554 id: value.id,
555 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
556 length: value.length,
557 views: value.views,
558 author: value.author,
559 author_id: value.author_id,
560 author_url: value.author_url,
561 published: value.published,
562 published_text: value.published_text,
563 }
564 }
565}
566
567impl From<invidious::universal::Playlist> for crate::global::common::universal::Playlist {
568 fn from(value: invidious::universal::Playlist) -> Self {
569 Self {
570 title: value.title,
571 id: value.id,
572 thumbnail: value.thumbnail,
573 author: value.author,
574 author_id: value.author_id,
575 author_thumbnails: value
576 .author_thumbnails
577 .into_iter()
578 .map(|v| v.into())
579 .collect(),
580 description: value.description,
581 description_html: value.description_html,
582 video_count: value.video_count,
583 views: value.views,
584 updated: value.updated,
585 listed: value.listed,
586 videos: value.videos.into_iter().map(|v| v.into()).collect(),
587 }
588 }
589}
590
591impl From<invidious::hidden::PlaylistItem> for crate::global::common::hidden::PlaylistItem {
592 fn from(value: invidious::hidden::PlaylistItem) -> Self {
593 Self {
594 title: value.title,
595 id: value.id,
596 author: value.author,
597 author_id: value.author_id,
598 author_url: value.author_url,
599 thumbnails: value.thumbnails.into_iter().map(|v| v.into()).collect(),
600 index: value.index,
601 length: value.length,
602 }
603 }
604}
605
16impl SearchProviderTrait for InvidiousClient { 606impl SearchProviderTrait for InvidiousClient {
17 fn supports_video(&self) -> bool { 607 fn supports_video(&self) -> bool {
18 true 608 true
19 } 609 }
20 610
21 fn video(&self, id: &str) -> Result<invidious::video::Video, Box<dyn std::error::Error>> { 611 fn video(
22 self.0.video(id, None).map_err(|e| e.into()) 612 &self,
613 id: &str,
614 ) -> Result<crate::global::common::video::Video, Box<dyn std::error::Error>> {
615 match self.0.video(id, None) {
616 Ok(k) => Ok(k.into()),
617 Err(e) => Err(e.into()),
618 }
23 } 619 }
24 620
25 fn supports_search(&self) -> bool { 621 fn supports_search(&self) -> bool {
@@ -29,41 +625,51 @@ impl SearchProviderTrait for InvidiousClient {
29 fn search( 625 fn search(
30 &self, 626 &self,
31 filters: &crate::config::Search, 627 filters: &crate::config::Search,
32 ) -> Result<Vec<invidious::hidden::SearchItem>, Box<dyn std::error::Error>> { 628 ) -> Result<Vec<crate::global::common::hidden::SearchItem>, Box<dyn std::error::Error>> {
33 self.0 629 match self.0.search(Some(&filters.to_string())) {
34 .search(Some(&filters.to_string())) 630 Ok(k) => Ok(k.items.into_iter().map(|v| v.into()).collect()),
35 .map(|res| res.items) 631 Err(e) => Err(e.into()),
36 .map_err(|e| e.into()) 632 }
37 } 633 }
38 634
39 fn supports_channel(&self) -> bool { 635 fn supports_channel(&self) -> bool {
40 true 636 true
41 } 637 }
42 638
43 fn channel(&self, id: &str) -> Result<invidious::channel::Channel, Box<dyn std::error::Error>> { 639 fn channel(
44 self.0.channel(id, None).map_err(|e| e.into()) 640 &self,
641 id: &str,
642 ) -> Result<crate::global::common::channel::Channel, Box<dyn std::error::Error>> {
643 match self.0.channel(id, None) {
644 Ok(k) => Ok(k.into()),
645 Err(e) => Err(e.into()),
646 }
45 } 647 }
46 648
47 fn supports_popular(&self) -> bool { 649 fn supports_popular(&self) -> bool {
48 true 650 true
49 } 651 }
50 652
51 fn popular(&self) -> Result<Vec<invidious::hidden::PopularItem>, Box<dyn std::error::Error>> { 653 fn popular(
52 self.0 654 &self,
53 .popular(None) 655 ) -> Result<Vec<crate::global::common::hidden::PopularItem>, Box<dyn std::error::Error>> {
54 .map(|res| res.items) 656 match self.0.popular(None) {
55 .map_err(|e| e.into()) 657 Ok(k) => Ok(k.items.into_iter().map(|v| v.into()).collect()),
658 Err(e) => Err(e.into()),
659 }
56 } 660 }
57 661
58 fn supports_trending(&self) -> bool { 662 fn supports_trending(&self) -> bool {
59 true 663 true
60 } 664 }
61 665
62 fn trending(&self) -> Result<Vec<invidious::CommonVideo>, Box<dyn std::error::Error>> { 666 fn trending(
63 self.0 667 &self,
64 .trending(None) 668 ) -> Result<Vec<crate::global::common::CommonVideo>, Box<dyn std::error::Error>> {
65 .map(|res| res.videos) 669 match self.0.trending(None) {
66 .map_err(|e| e.into()) 670 Ok(k) => Ok(k.videos.into_iter().map(|v| v.into()).collect()),
671 Err(e) => Err(e.into()),
672 }
67 } 673 }
68 674
69 fn supports_playlist(&self) -> bool { 675 fn supports_playlist(&self) -> bool {
@@ -73,8 +679,11 @@ impl SearchProviderTrait for InvidiousClient {
73 fn playlist( 679 fn playlist(
74 &self, 680 &self,
75 id: &str, 681 id: &str,
76 ) -> Result<invidious::universal::Playlist, Box<dyn std::error::Error>> { 682 ) -> Result<crate::global::common::universal::Playlist, Box<dyn std::error::Error>> {
77 self.0.playlist(id, None).map_err(|e| e.into()) 683 match self.0.playlist(id, None) {
684 Ok(k) => Ok(k.into()),
685 Err(e) => Err(e.into()),
686 }
78 } 687 }
79 688
80 fn supports_channel_videos(&self) -> bool { 689 fn supports_channel_videos(&self) -> bool {
@@ -84,11 +693,11 @@ impl SearchProviderTrait for InvidiousClient {
84 fn channel_videos( 693 fn channel_videos(
85 &self, 694 &self,
86 id: &str, 695 id: &str,
87 ) -> Result<Vec<invidious::CommonVideo>, Box<dyn std::error::Error>> { 696 ) -> Result<Vec<crate::global::common::CommonVideo>, Box<dyn std::error::Error>> {
88 self.0 697 match self.0.channel_videos(id, None) {
89 .channel_videos(id, None) 698 Ok(k) => Ok(k.videos.into_iter().map(|v| v.into()).collect()),
90 .map(|res| res.videos) 699 Err(e) => Err(e.into()),
91 .map_err(|e| e.into()) 700 }
92 } 701 }
93 702
94 fn supports_channel_playlists(&self) -> bool { 703 fn supports_channel_playlists(&self) -> bool {
@@ -98,10 +707,10 @@ impl SearchProviderTrait for InvidiousClient {
98 fn channel_playlists( 707 fn channel_playlists(
99 &self, 708 &self,
100 id: &str, 709 id: &str,
101 ) -> Result<Vec<invidious::CommonPlaylist>, Box<dyn std::error::Error>> { 710 ) -> Result<Vec<crate::global::common::CommonPlaylist>, Box<dyn std::error::Error>> {
102 self.0 711 match self.0.channel_playlists(id, None) {
103 .channel_playlists(id, None) 712 Ok(k) => Ok(k.playlists.into_iter().map(|v| v.into()).collect()),
104 .map(|res| res.playlists) 713 Err(e) => Err(e.into()),
105 .map_err(|e| e.into()) 714 }
106 } 715 }
107} 716}
src/global/structs/rustypipe.rs +1 −1
@@ -303,7 +303,7 @@ impl SearchProviderTrait for RustyPipeWrapper {
303 description: info.description.clone(), 303 description: info.description.clone(),
304 description_html: info.description, 304 description_html: info.description,
305 allowed_regions: Vec::new(), // TODO 305 allowed_regions: Vec::new(), // TODO
306 lastest_videos: Vec::new(), 306 latest_videos: Vec::new(),
307 related_channels: Vec::new(), 307 related_channels: Vec::new(),
308 }) 308 })
309 } 309 }
src/global/structs/subscriptions.rs +8 −5
@@ -235,7 +235,7 @@ fn sync_one(
235 })]); 235 })]);
236 } 236 }
237 } 237 }
238 238
239 if let Some(channel) = &channel { 239 if let Some(channel) = &channel {
240 let _ = update_channel_cache(channel, image_index); 240 let _ = update_channel_cache(channel, image_index);
241 } 241 }
@@ -243,19 +243,22 @@ fn sync_one(
243 Ok((videos, channel)) 243 Ok((videos, channel))
244} 244}
245 245
246fn update_channel_cache(channel: &FullChannelItem, image_index: usize) -> Result<(), Box<dyn Error>> { 246fn update_channel_cache(
247 channel: &FullChannelItem,
248 image_index: usize,
249) -> Result<(), Box<dyn Error>> {
247 let home_dir = home_dir().unwrap(); 250 let home_dir = home_dir().unwrap();
248 let cache_path = home_dir.join(format!(".cache/youtube-tui/channels/{}.json", channel.id)); 251 let cache_path = home_dir.join(format!(".cache/youtube-tui/channels/{}.json", channel.id));
249 252
250 if let Some(parent) = cache_path.parent() { 253 if let Some(parent) = cache_path.parent() {
251 fs::create_dir_all(parent)?; 254 fs::create_dir_all(parent)?;
252 } 255 }
253 256
254 let item = crate::global::structs::Item::from_full_channel( 257 let item = crate::global::structs::Item::from_full_channel(
255 crate::global::traits::SearchProviderWrapper::channel(&channel.id)?, 258 crate::global::traits::SearchProviderWrapper::channel(&channel.id)?,
256 image_index, 259 image_index,
257 ); 260 );
258 261
259 fs::write(&cache_path, serde_json::to_string(&item)?)?; 262 fs::write(&cache_path, serde_json::to_string(&item)?)?;
260 Ok(()) 263 Ok(())
261} 264}
src/items/channeldisplay.rs +6 −3
@@ -1,8 +1,11 @@
1
2use super::ItemInfo; 1use super::ItemInfo;
3use crate::{ 2use crate::{
4 config::*, 3 config::*,
5 global::{functions::*, structs::*, traits::{SearchProviderWrapper, CollectionNoId}}, 4 global::{
5 functions::*,
6 structs::*,
7 traits::{CollectionNoId, SearchProviderWrapper},
8 },
6}; 9};
7use ratatui::{ 10use ratatui::{
8 layout::{Constraint, Rect}, 11 layout::{Constraint, Rect},
@@ -607,7 +610,7 @@ impl FrameworkItem for ChannelDisplay {
607 .unwrap() 610 .unwrap()
608 .channel 611 .channel
609 .clone(); 612 .clone();
610 613
611 *self = Self::Main { 614 *self = Self::Main {
612 iteminfo: Box::new(ItemInfo::new(Some(channel.clone()))), 615 iteminfo: Box::new(ItemInfo::new(Some(channel.clone()))),
613 channel: Box::new(channel), 616 channel: Box::new(channel),