Commit 896a63a991
Unsigned
Layout: unified · split
README.md +2 −4
| @@ -1,10 +1,8 @@ | |||
| 1 | ## Warning: | 1 | ## Warning: |
| 2 | * This app is incomplete but is basically usable | ||
| 3 | * This app is only for *\*nix* systems | 2 | * This app is only for *\*nix* systems |
| 4 | 3 | ||
| 5 | ## Changes made in this commit | 4 | ## Changes made in this commit |
| 6 | * Playlist support | 5 | * Channel support |
| 7 | * Adaptive config files (e.g. auto update config files while preserving the original options) | ||
| 8 | 6 | ||
| 9 | ## Installation | 7 | ## Installation |
| 10 | Requirements: Git, Cargo and the Rust Compiler | 8 | Requirements: Git, Cargo and the Rust Compiler |
| @@ -138,9 +136,9 @@ The config files are located in `~/.config/youtube-tui`, run the program once to | |||
| 138 | > - "{video_save_location}" | 136 | > - "{video_save_location}" |
| 139 | > ``` | 137 | > ``` |
| 140 | ## To Do | 138 | ## To Do |
| 141 | * Channel support | ||
| 142 | * Update notice (e.g. when a new version is released on GitHub or crates.io, can be disabled in the config file) | 139 | * Update notice (e.g. when a new version is released on GitHub or crates.io, can be disabled in the config file) |
| 143 | * Keybind options (e.g. change the keybinds in the config file) | 140 | * Keybind options (e.g. change the keybinds in the config file) |
| 141 | * Channel search + item sorting | ||
| 144 | 142 | ||
| 145 | ## Bugs | 143 | ## Bugs |
| 146 | * If there is a bug please open a GitHub issue thx :)\ No newline at end of file | 144 | * If there is a bug please open a GitHub issue thx :)\ No newline at end of file |
src/app/app.rs +23 −1
| @@ -20,7 +20,7 @@ use tui::{ | |||
| 20 | 20 | ||
| 21 | use super::{ | 21 | use super::{ |
| 22 | config::Config, | 22 | config::Config, |
| 23 | pages::{item_info::ItemInfo, search::Search}, | 23 | pages::{channel::Channel, item_info::ItemInfo, search::Search}, |
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | #[derive(Debug)] | 26 | #[derive(Debug)] |
| @@ -80,6 +80,7 @@ impl App { | |||
| 80 | Item::MainMenu(item) => item.selectable(), | 80 | Item::MainMenu(item) => item.selectable(), |
| 81 | Item::ItemInfo(item) => item.selectable(), | 81 | Item::ItemInfo(item) => item.selectable(), |
| 82 | Item::Search(item) => item.selectable(), | 82 | Item::Search(item) => item.selectable(), |
| 83 | Item::Channel(item) => item.selectable(), | ||
| 83 | } { | 84 | } { |
| 84 | row_vec.push((x, y)); | 85 | row_vec.push((x, y)); |
| 85 | } | 86 | } |
| @@ -128,6 +129,14 @@ impl App { | |||
| 128 | self.state[y].items[x].item = Item::Search(item); | 129 | self.state[y].items[x].item = Item::Search(item); |
| 129 | } | 130 | } |
| 130 | } | 131 | } |
| 132 | Item::Channel(item) => { | ||
| 133 | let mut item = item.clone(); | ||
| 134 | let hold = item.key_input(key, self); | ||
| 135 | self = hold.1; | ||
| 136 | if hold.0 { | ||
| 137 | self.state[y].items[x].item = Item::Channel(item); | ||
| 138 | } | ||
| 139 | } | ||
| 131 | } | 140 | } |
| 132 | 141 | ||
| 133 | return self; | 142 | return self; |
| @@ -176,6 +185,13 @@ impl App { | |||
| 176 | self.selected = Some((x, y)); | 185 | self.selected = Some((x, y)); |
| 177 | } | 186 | } |
| 178 | } | 187 | } |
| 188 | Item::Channel(mut item) => { | ||
| 189 | let held = item.select(self); | ||
| 190 | self = held.0; | ||
| 191 | if held.1 { | ||
| 192 | self.selected = Some((x, y)); | ||
| 193 | } | ||
| 194 | } | ||
| 179 | } | 195 | } |
| 180 | 196 | ||
| 181 | return self; | 197 | return self; |
| @@ -260,6 +276,7 @@ impl App { | |||
| 260 | Page::MainMenu(_) => MainMenu::min(), | 276 | Page::MainMenu(_) => MainMenu::min(), |
| 261 | Page::ItemDisplay(_) => ItemInfo::min(), | 277 | Page::ItemDisplay(_) => ItemInfo::min(), |
| 262 | Page::Search => Search::min(), | 278 | Page::Search => Search::min(), |
| 279 | Page::Channel(_, _) => Channel::min(), | ||
| 263 | }; | 280 | }; |
| 264 | 281 | ||
| 265 | if size.width < min.0 || size.height < min.1 { | 282 | if size.width < min.0 || size.height < min.1 { |
| @@ -364,6 +381,11 @@ impl App { | |||
| 364 | i.render_item(frame, chunk, selected, hover, self.popup_focus); | 381 | i.render_item(frame, chunk, selected, hover, self.popup_focus); |
| 365 | false | 382 | false |
| 366 | } | 383 | } |
| 384 | |||
| 385 | Item::Channel(i) => { | ||
| 386 | i.render_item(frame, chunk, selected, hover, self.popup_focus, &self.page); | ||
| 387 | false | ||
| 388 | } | ||
| 367 | } { | 389 | } { |
| 368 | popups.push((item, selected, hover, chunk)); | 390 | popups.push((item, selected, hover, chunk)); |
| 369 | } | 391 | } |
src/app/config/commands.rs +5 −1
| @@ -152,7 +152,11 @@ impl Default for CommandsConfig { | |||
| 152 | playlist_shuffle_audio_all: CommandConfig { | 152 | playlist_shuffle_audio_all: CommandConfig { |
| 153 | command: String::from("mpv"), | 153 | command: String::from("mpv"), |
| 154 | open_in_console: true, | 154 | open_in_console: true, |
| 155 | args: vec![String::from("--no-video"), String::from("{url}"), String::from("--shuffle")], | 155 | args: vec![ |
| 156 | String::from("--no-video"), | ||
| 157 | String::from("{url}"), | ||
| 158 | String::from("--shuffle"), | ||
| 159 | ], | ||
| 156 | }, | 160 | }, |
| 157 | download_all_audio: CommandConfig { | 161 | download_all_audio: CommandConfig { |
| 158 | command: String::from("yt-dlp"), | 162 | command: String::from("yt-dlp"), |
src/app/config/main.rs +6 −2
| @@ -1,4 +1,8 @@ | |||
| 1 | use std::{error::Error, fs::{self, OpenOptions}, io::Write}; | 1 | use std::{ |
| 2 | error::Error, | ||
| 3 | fs::{self, OpenOptions}, | ||
| 4 | io::Write, | ||
| 5 | }; | ||
| 2 | 6 | ||
| 3 | use serde::{Deserialize, Serialize}; | 7 | use serde::{Deserialize, Serialize}; |
| 4 | 8 | ||
| @@ -78,4 +82,4 @@ impl MainConfig { | |||
| 78 | 82 | ||
| 79 | Ok(main) | 83 | Ok(main) |
| 80 | } | 84 | } |
| 81 | }\ No newline at end of file | 85 | } |
src/app/pages/channel.rs added +441
| @@ -0,0 +1,441 @@ | |||
| 1 | use std::{collections::LinkedList, error::Error}; | ||
| 2 | |||
| 3 | use crossterm::event::KeyCode; | ||
| 4 | use tui::{ | ||
| 5 | backend::Backend, | ||
| 6 | layout::{Alignment, Constraint, Rect}, | ||
| 7 | style::{Color, Style}, | ||
| 8 | widgets::{Block, BorderType, Borders, Paragraph}, | ||
| 9 | Frame, | ||
| 10 | }; | ||
| 11 | |||
| 12 | use crate::{ | ||
| 13 | app::app::App, | ||
| 14 | functions::download_all_thumbnails, | ||
| 15 | structs::{FullChannel, Item, ListItem, MiniPlayList, MiniVideo, Page, Row, RowItem}, | ||
| 16 | traits::{KeyInput, SelectItem}, | ||
| 17 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, | ||
| 18 | }; | ||
| 19 | |||
| 20 | use super::{ | ||
| 21 | global::GlobalItem, | ||
| 22 | item_info::{DisplayItem, ItemInfo}, | ||
| 23 | }; | ||
| 24 | |||
| 25 | #[derive(Debug, Clone, Copy, PartialEq)] | ||
| 26 | pub enum ChannelPage { | ||
| 27 | Home, | ||
| 28 | Playlists, | ||
| 29 | Videos, | ||
| 30 | } | ||
| 31 | |||
| 32 | #[derive(Debug, Clone)] | ||
| 33 | pub enum ChannelItem { | ||
| 34 | InfoDisplay(ChannelDisplayItem), | ||
| 35 | SelectItems(ChannelPage), | ||
| 36 | } | ||
| 37 | |||
| 38 | #[derive(Debug, Clone)] | ||
| 39 | pub enum ChannelDisplayItem { | ||
| 40 | Playlists(Vec<MiniPlayList>, TextList), | ||
| 41 | Videos(Vec<MiniVideo>, TextList), | ||
| 42 | Home(FullChannel), | ||
| 43 | Unknown, | ||
| 44 | } | ||
| 45 | |||
| 46 | impl ChannelItem { | ||
| 47 | pub fn load_item(&self, app: &App) -> Result<Self, Box<dyn Error>> { | ||
| 48 | let mut this = self.clone(); | ||
| 49 | |||
| 50 | if let Page::Channel(channel_page, id) = &app.page { | ||
| 51 | if let ChannelItem::InfoDisplay(displayitem) = &mut this { | ||
| 52 | match channel_page { | ||
| 53 | ChannelPage::Home => { | ||
| 54 | let channel = app.client.channel(id, None)?; | ||
| 55 | let mut linked_list = LinkedList::new(); | ||
| 56 | linked_list.push_back(( | ||
| 57 | channel.authorThumbnails[4].url.clone(), | ||
| 58 | channel.authorId.clone(), | ||
| 59 | )); | ||
| 60 | let _ = download_all_thumbnails(linked_list); | ||
| 61 | |||
| 62 | *displayitem = ChannelDisplayItem::Home(channel.into()); | ||
| 63 | } | ||
| 64 | ChannelPage::Playlists => { | ||
| 65 | let mut textlist = TextList::default(); | ||
| 66 | let playlists = app | ||
| 67 | .client | ||
| 68 | .channel_playlists(id, None)? | ||
| 69 | .playlists | ||
| 70 | .into_iter() | ||
| 71 | .map(|item| { | ||
| 72 | textlist.items.push(item.title.clone()); | ||
| 73 | item.into() | ||
| 74 | }) | ||
| 75 | .collect::<Vec<MiniPlayList>>(); | ||
| 76 | |||
| 77 | let mut linked_list = LinkedList::new(); | ||
| 78 | for item in playlists.iter() { | ||
| 79 | if let Some(thumbnail) = &item.thumbnail { | ||
| 80 | linked_list | ||
| 81 | .push_back((thumbnail.clone(), item.playlist_id.clone())); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | let _ = download_all_thumbnails(linked_list); | ||
| 85 | |||
| 86 | *displayitem = ChannelDisplayItem::Playlists(playlists, textlist); | ||
| 87 | } | ||
| 88 | |||
| 89 | ChannelPage::Videos => { | ||
| 90 | let mut textlist = TextList::default(); | ||
| 91 | let videos = app | ||
| 92 | .client | ||
| 93 | .channel_videos(id, None)? | ||
| 94 | .videos | ||
| 95 | .into_iter() | ||
| 96 | .map(|item| { | ||
| 97 | textlist.items.push(item.title.clone()); | ||
| 98 | item.into() | ||
| 99 | }) | ||
| 100 | .collect::<Vec<MiniVideo>>(); | ||
| 101 | |||
| 102 | let mut linked_list = LinkedList::new(); | ||
| 103 | for item in videos.iter() { | ||
| 104 | linked_list | ||
| 105 | .push_back((item.video_thumbnail.clone(), item.video_id.clone())); | ||
| 106 | } | ||
| 107 | let _ = download_all_thumbnails(linked_list); | ||
| 108 | |||
| 109 | *displayitem = ChannelDisplayItem::Videos(videos, textlist); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | Ok(this) | ||
| 116 | } | ||
| 117 | |||
| 118 | pub fn render_item<B: Backend>( | ||
| 119 | &mut self, | ||
| 120 | frame: &mut Frame<B>, | ||
| 121 | rect: Rect, | ||
| 122 | selected: bool, | ||
| 123 | hover: bool, | ||
| 124 | popup_focus: bool, | ||
| 125 | page: &Page, | ||
| 126 | ) { | ||
| 127 | let mut style = Style::default().fg(if selected { | ||
| 128 | Color::LightBlue | ||
| 129 | } else if hover { | ||
| 130 | Color::LightRed | ||
| 131 | } else { | ||
| 132 | Color::Reset | ||
| 133 | }); | ||
| 134 | |||
| 135 | match self { | ||
| 136 | ChannelItem::InfoDisplay(displayitem) => match displayitem { | ||
| 137 | ChannelDisplayItem::Unknown => { | ||
| 138 | let block = Block::default() | ||
| 139 | .border_type(BorderType::Rounded) | ||
| 140 | .borders(Borders::ALL) | ||
| 141 | .border_style(style); | ||
| 142 | |||
| 143 | frame.render_widget(block, rect); | ||
| 144 | } | ||
| 145 | ChannelDisplayItem::Home(channel) => { | ||
| 146 | let block = Block::default() | ||
| 147 | .border_type(BorderType::Rounded) | ||
| 148 | .borders(Borders::ALL) | ||
| 149 | .border_style(style); | ||
| 150 | |||
| 151 | let inner = block.inner(rect); | ||
| 152 | frame.render_widget(block, rect); | ||
| 153 | frame.render_widget( | ||
| 154 | ItemDisplay { | ||
| 155 | item: ListItem::FullChannel(channel.clone()), | ||
| 156 | }, | ||
| 157 | inner, | ||
| 158 | ); | ||
| 159 | } | ||
| 160 | ChannelDisplayItem::Videos(videos, textlist) => { | ||
| 161 | let split = HorizontalSplit::default() | ||
| 162 | .percentages(vec![60, 40]) | ||
| 163 | .border_style(Style::default().fg(if selected { | ||
| 164 | Color::LightBlue | ||
| 165 | } else if hover { | ||
| 166 | Color::LightRed | ||
| 167 | } else { | ||
| 168 | Color::Reset | ||
| 169 | })); | ||
| 170 | |||
| 171 | let chunks = split.inner(rect); | ||
| 172 | |||
| 173 | frame.render_widget(split, rect); | ||
| 174 | |||
| 175 | textlist.area(chunks[0]); | ||
| 176 | let mut textlist = textlist.clone(); | ||
| 177 | |||
| 178 | if selected { | ||
| 179 | textlist.selected_style(Style::default().fg(Color::LightRed)); | ||
| 180 | } else { | ||
| 181 | textlist.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 182 | } | ||
| 183 | |||
| 184 | if let Some(item) = videos.iter().nth(textlist.selected) { | ||
| 185 | if !popup_focus { | ||
| 186 | frame.render_widget( | ||
| 187 | ItemDisplay { | ||
| 188 | item: ListItem::MiniVideo(item.clone()), | ||
| 189 | }, | ||
| 190 | chunks[1], | ||
| 191 | ); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | frame.render_widget(textlist, chunks[0]); | ||
| 196 | } | ||
| 197 | ChannelDisplayItem::Playlists(playlists, textlist) => { | ||
| 198 | let split = HorizontalSplit::default() | ||
| 199 | .percentages(vec![60, 40]) | ||
| 200 | .border_style(Style::default().fg(if selected { | ||
| 201 | Color::LightBlue | ||
| 202 | } else if hover { | ||
| 203 | Color::LightRed | ||
| 204 | } else { | ||
| 205 | Color::Reset | ||
| 206 | })); | ||
| 207 | |||
| 208 | let chunks = split.inner(rect); | ||
| 209 | |||
| 210 | frame.render_widget(split, rect); | ||
| 211 | |||
| 212 | textlist.area(chunks[0]); | ||
| 213 | let mut textlist = textlist.clone(); | ||
| 214 | |||
| 215 | if selected { | ||
| 216 | textlist.selected_style(Style::default().fg(Color::LightRed)); | ||
| 217 | } else { | ||
| 218 | textlist.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 219 | } | ||
| 220 | |||
| 221 | if let Some(item) = playlists.iter().nth(textlist.selected) { | ||
| 222 | if !popup_focus { | ||
| 223 | frame.render_widget( | ||
| 224 | ItemDisplay { | ||
| 225 | item: ListItem::MiniPlayList(item.clone()), | ||
| 226 | }, | ||
| 227 | chunks[1], | ||
| 228 | ); | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | frame.render_widget(textlist, chunks[0]); | ||
| 233 | } | ||
| 234 | }, | ||
| 235 | ChannelItem::SelectItems(selected_page) => { | ||
| 236 | if !hover { | ||
| 237 | if let Page::Channel(channel_page, _) = page { | ||
| 238 | if *selected_page == *channel_page { | ||
| 239 | style = style.fg(Color::LightYellow); | ||
| 240 | } | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | let block = Block::default() | ||
| 245 | .border_type(BorderType::Rounded) | ||
| 246 | .borders(Borders::ALL) | ||
| 247 | .border_style(style); | ||
| 248 | let paragraph = Paragraph::new(format!("{:?}", selected_page)) | ||
| 249 | .block(block) | ||
| 250 | .alignment(Alignment::Center); | ||
| 251 | |||
| 252 | frame.render_widget(paragraph, rect); | ||
| 253 | } | ||
| 254 | } | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | impl KeyInput for ChannelItem { | ||
| 259 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) { | ||
| 260 | match self { | ||
| 261 | ChannelItem::InfoDisplay(displayitem) => match displayitem { | ||
| 262 | ChannelDisplayItem::Videos(videos, textlist) => match key { | ||
| 263 | KeyCode::Up => { | ||
| 264 | textlist.up(); | ||
| 265 | } | ||
| 266 | KeyCode::Down => { | ||
| 267 | textlist.down(); | ||
| 268 | } | ||
| 269 | KeyCode::PageUp => { | ||
| 270 | textlist.selected = 0; | ||
| 271 | } | ||
| 272 | KeyCode::PageDown => { | ||
| 273 | textlist.selected = textlist.items.len() - 1; | ||
| 274 | } | ||
| 275 | KeyCode::Enter => { | ||
| 276 | let state = ItemInfo::default(); | ||
| 277 | let mut history = app.history.clone(); | ||
| 278 | history.push(app.into()); | ||
| 279 | |||
| 280 | return ( | ||
| 281 | false, | ||
| 282 | App { | ||
| 283 | history, | ||
| 284 | page: Page::ItemDisplay(DisplayItem::Video( | ||
| 285 | videos[textlist.selected].video_id.clone(), | ||
| 286 | )), | ||
| 287 | selectable: App::selectable(&state), | ||
| 288 | state, | ||
| 289 | ..Default::default() | ||
| 290 | }, | ||
| 291 | ); | ||
| 292 | } | ||
| 293 | _ => {} | ||
| 294 | }, | ||
| 295 | |||
| 296 | ChannelDisplayItem::Playlists(playlists, textlist) => match key { | ||
| 297 | KeyCode::Up => { | ||
| 298 | textlist.up(); | ||
| 299 | } | ||
| 300 | KeyCode::Down => { | ||
| 301 | textlist.down(); | ||
| 302 | } | ||
| 303 | KeyCode::PageUp => { | ||
| 304 | textlist.selected = 0; | ||
| 305 | } | ||
| 306 | KeyCode::PageDown => { | ||
| 307 | textlist.selected = textlist.items.len() - 1; | ||
| 308 | } | ||
| 309 | KeyCode::Enter => { | ||
| 310 | let state = ItemInfo::default(); | ||
| 311 | let mut history = app.history.clone(); | ||
| 312 | history.push(app.into()); | ||
| 313 | |||
| 314 | return ( | ||
| 315 | false, | ||
| 316 | App { | ||
| 317 | history, | ||
| 318 | page: Page::ItemDisplay(DisplayItem::PlayList( | ||
| 319 | playlists[textlist.selected].playlist_id.clone(), | ||
| 320 | )), | ||
| 321 | selectable: App::selectable(&state), | ||
| 322 | state, | ||
| 323 | ..Default::default() | ||
| 324 | }, | ||
| 325 | ); | ||
| 326 | } | ||
| 327 | _ => {} | ||
| 328 | }, | ||
| 329 | |||
| 330 | _ => unreachable!(), | ||
| 331 | }, | ||
| 332 | _ => { | ||
| 333 | unreachable!() | ||
| 334 | } | ||
| 335 | } | ||
| 336 | |||
| 337 | (true, app) | ||
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | impl SelectItem for ChannelItem { | ||
| 342 | fn select(&mut self, app: App) -> (App, bool) { | ||
| 343 | let cloned = self.clone(); | ||
| 344 | match &cloned { | ||
| 345 | ChannelItem::InfoDisplay(_) => (app, true), | ||
| 346 | ChannelItem::SelectItems(tab) => { | ||
| 347 | if let Page::Channel(channel_page, id) = &app.page.clone() { | ||
| 348 | if *tab == *channel_page { | ||
| 349 | return (app, false); | ||
| 350 | } | ||
| 351 | |||
| 352 | let state = Channel::default(); | ||
| 353 | let mut history = app.history.clone(); | ||
| 354 | history.push(app.into()); | ||
| 355 | |||
| 356 | return ( | ||
| 357 | App { | ||
| 358 | history, | ||
| 359 | page: Page::Channel(tab.clone(), id.clone()), | ||
| 360 | selectable: App::selectable(&state), | ||
| 361 | state, | ||
| 362 | ..Default::default() | ||
| 363 | }, | ||
| 364 | false, | ||
| 365 | ); | ||
| 366 | } else { | ||
| 367 | (app, false) | ||
| 368 | } | ||
| 369 | } | ||
| 370 | } | ||
| 371 | } | ||
| 372 | |||
| 373 | fn selectable(&self) -> bool { | ||
| 374 | true | ||
| 375 | } | ||
| 376 | } | ||
| 377 | |||
| 378 | pub struct Channel; | ||
| 379 | |||
| 380 | impl Channel { | ||
| 381 | pub fn message() -> String { | ||
| 382 | String::from("Loading channel info...") | ||
| 383 | } | ||
| 384 | |||
| 385 | pub fn min() -> (u16, u16) { | ||
| 386 | (45, 15) | ||
| 387 | } | ||
| 388 | |||
| 389 | pub fn default() -> Vec<Row> { | ||
| 390 | vec![ | ||
| 391 | Row { | ||
| 392 | items: vec![ | ||
| 393 | RowItem { | ||
| 394 | item: Item::Global(GlobalItem::SearchBar), | ||
| 395 | constraint: Constraint::Min(16), | ||
| 396 | }, | ||
| 397 | RowItem { | ||
| 398 | item: Item::Global(GlobalItem::SearchSettings), | ||
| 399 | constraint: Constraint::Length(5), | ||
| 400 | }, | ||
| 401 | ], | ||
| 402 | centered: false, | ||
| 403 | height: Constraint::Length(3), | ||
| 404 | }, | ||
| 405 | Row { | ||
| 406 | items: vec![ | ||
| 407 | RowItem { | ||
| 408 | item: Item::Channel(ChannelItem::SelectItems(ChannelPage::Home)), | ||
| 409 | constraint: Constraint::Length(15), | ||
| 410 | }, | ||
| 411 | RowItem { | ||
| 412 | item: Item::Channel(ChannelItem::SelectItems(ChannelPage::Videos)), | ||
| 413 | constraint: Constraint::Length(15), | ||
| 414 | }, | ||
| 415 | RowItem { | ||
| 416 | item: Item::Channel(ChannelItem::SelectItems(ChannelPage::Playlists)), | ||
| 417 | constraint: Constraint::Length(15), | ||
| 418 | }, | ||
| 419 | ], | ||
| 420 | centered: true, | ||
| 421 | height: Constraint::Length(3), | ||
| 422 | }, | ||
| 423 | Row { | ||
| 424 | items: vec![RowItem { | ||
| 425 | item: Item::Channel(ChannelItem::InfoDisplay(ChannelDisplayItem::Unknown)), | ||
| 426 | constraint: Constraint::Percentage(100), | ||
| 427 | }], | ||
| 428 | centered: false, | ||
| 429 | height: Constraint::Min(6), | ||
| 430 | }, | ||
| 431 | Row { | ||
| 432 | items: vec![RowItem { | ||
| 433 | item: Item::Global(GlobalItem::MessageBar), | ||
| 434 | constraint: Constraint::Percentage(100), | ||
| 435 | }], | ||
| 436 | centered: false, | ||
| 437 | height: Constraint::Length(3), | ||
| 438 | }, | ||
| 439 | ] | ||
| 440 | } | ||
| 441 | } | ||
src/app/pages/item_info.rs +41 −9
| @@ -21,7 +21,10 @@ use tui::{ | |||
| 21 | Frame, | 21 | Frame, |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | use super::global::GlobalItem; | 24 | use super::{ |
| 25 | channel::{Channel, ChannelPage}, | ||
| 26 | global::GlobalItem, | ||
| 27 | }; | ||
| 25 | 28 | ||
| 26 | #[derive(Debug, Clone)] | 29 | #[derive(Debug, Clone)] |
| 27 | pub enum ItemInfoItem { | 30 | pub enum ItemInfoItem { |
| @@ -242,9 +245,23 @@ impl KeyInput for ItemInfoItem { | |||
| 242 | run_command(command, app.message.clone()); | 245 | run_command(command, app.message.clone()); |
| 243 | } | 246 | } |
| 244 | 5 => { | 247 | 5 => { |
| 245 | *app.message.lock().unwrap() = Some(String::from( | 248 | let state = Channel::default(); |
| 246 | "Too lazy to implement that what do you expect?", | 249 | let mut history = app.history.clone(); |
| 247 | )); | 250 | history.push(app.into()); |
| 251 | |||
| 252 | return ( | ||
| 253 | false, | ||
| 254 | App { | ||
| 255 | history, | ||
| 256 | page: Page::Channel( | ||
| 257 | ChannelPage::Home, | ||
| 258 | videoinfo.video.channel_id.clone(), | ||
| 259 | ), | ||
| 260 | selectable: App::selectable(&state), | ||
| 261 | state, | ||
| 262 | ..Default::default() | ||
| 263 | }, | ||
| 264 | ); | ||
| 248 | } | 265 | } |
| 249 | 6 => { | 266 | 6 => { |
| 250 | videoinfo.mode.toggle(); | 267 | videoinfo.mode.toggle(); |
| @@ -499,9 +516,24 @@ impl KeyInput for ItemInfoItem { | |||
| 499 | } | 516 | } |
| 500 | 517 | ||
| 501 | 7 => { | 518 | 7 => { |
| 502 | *app.message.lock().unwrap() = Some(String::from( | 519 | let state = Channel::default(); |
| 503 | "Too lazy to implement that what do you expect?", | 520 | let mut history = app.history.clone(); |
| 504 | )); | 521 | history.push(app.into()); |
| 522 | |||
| 523 | return ( | ||
| 524 | false, | ||
| 525 | App { | ||
| 526 | history, | ||
| 527 | page: Page::Channel( | ||
| 528 | ChannelPage::Home, | ||
| 529 | playlistinfo.playlist.author_id.clone(), | ||
| 530 | ), | ||
| 531 | selectable: App::selectable(&state), | ||
| 532 | state, | ||
| 533 | load: true, | ||
| 534 | ..Default::default() | ||
| 535 | }, | ||
| 536 | ); | ||
| 505 | } | 537 | } |
| 506 | 538 | ||
| 507 | 8 => { | 539 | 8 => { |
| @@ -562,7 +594,7 @@ impl ItemInfoItem { | |||
| 562 | &self, | 594 | &self, |
| 563 | app: &App, | 595 | app: &App, |
| 564 | watch_history: &mut WatchHistory, | 596 | watch_history: &mut WatchHistory, |
| 565 | ) -> Result<Box<Self>, Box<dyn Error>> { | 597 | ) -> Result<Self, Box<dyn Error>> { |
| 566 | let mut this = self.clone(); | 598 | let mut this = self.clone(); |
| 567 | 599 | ||
| 568 | if let ItemInfoItem::Unknown = this { | 600 | if let ItemInfoItem::Unknown = this { |
| @@ -650,7 +682,7 @@ impl ItemInfoItem { | |||
| 650 | _ => {} | 682 | _ => {} |
| 651 | } | 683 | } |
| 652 | } | 684 | } |
| 653 | Ok(Box::new(this)) | 685 | Ok(this) |
| 654 | } | 686 | } |
| 655 | 687 | ||
| 656 | pub fn render_item<B: Backend>( | 688 | pub fn render_item<B: Backend>( |
src/app/pages/main_menu.rs +6 −14
| @@ -69,24 +69,16 @@ impl KeyInput for MainMenuItem { | |||
| 69 | page: Page::ItemDisplay( | 69 | page: Page::ItemDisplay( |
| 70 | match list.iter().nth(textlist.selected).unwrap() { | 70 | match list.iter().nth(textlist.selected).unwrap() { |
| 71 | ListItem::FullVideo(item) => { | 71 | ListItem::FullVideo(item) => { |
| 72 | DisplayItem::Video( | 72 | DisplayItem::Video(item.video_id.clone()) |
| 73 | item.video_id.clone(), | ||
| 74 | ) | ||
| 75 | } | 73 | } |
| 76 | ListItem::FullPlayList(item) => { | 74 | ListItem::FullPlayList(item) => { |
| 77 | DisplayItem::PlayList( | 75 | DisplayItem::PlayList(item.playlist_id.clone()) |
| 78 | item.playlist_id.clone(), | ||
| 79 | ) | ||
| 80 | } | 76 | } |
| 81 | ListItem::MiniPlayList(item) => { | 77 | ListItem::MiniPlayList(item) => { |
| 82 | DisplayItem::PlayList( | 78 | DisplayItem::PlayList(item.playlist_id.clone()) |
| 83 | item.playlist_id.clone(), | ||
| 84 | ) | ||
| 85 | } | 79 | } |
| 86 | ListItem::MiniVideo(item) => { | 80 | ListItem::MiniVideo(item) => { |
| 87 | DisplayItem::Video( | 81 | DisplayItem::Video(item.video_id.clone()) |
| 88 | item.video_id.clone(), | ||
| 89 | ) | ||
| 90 | } | 82 | } |
| 91 | _ => unreachable!(), | 83 | _ => unreachable!(), |
| 92 | }, | 84 | }, |
| @@ -107,7 +99,7 @@ impl KeyInput for MainMenuItem { | |||
| 107 | } | 99 | } |
| 108 | 100 | ||
| 109 | impl MainMenuItem { | 101 | impl MainMenuItem { |
| 110 | pub fn load_item(&self, app: &App) -> Result<Box<Self>, Box<dyn Error>> { | 102 | pub fn load_item(&self, app: &App) -> Result<Self, Box<dyn Error>> { |
| 111 | let mut this = self.clone(); | 103 | let mut this = self.clone(); |
| 112 | 104 | ||
| 113 | match &mut this { | 105 | match &mut this { |
| @@ -209,7 +201,7 @@ impl MainMenuItem { | |||
| 209 | _ => {} | 201 | _ => {} |
| 210 | } | 202 | } |
| 211 | 203 | ||
| 212 | Ok(Box::new(this)) | 204 | Ok(this) |
| 213 | } | 205 | } |
| 214 | 206 | ||
| 215 | pub fn render_item<B: Backend>( | 207 | pub fn render_item<B: Backend>( |
src/app/pages/mod.rs +2 −1
| @@ -1,4 +1,5 @@ | |||
| 1 | pub mod channel; | ||
| 1 | pub mod global; | 2 | pub mod global; |
| 2 | pub mod item_info; | 3 | pub mod item_info; |
| 3 | pub mod main_menu; | 4 | pub mod main_menu; |
| 4 | pub mod search;\ No newline at end of file | 5 | pub mod search; |
src/app/pages/search.rs +46 −3
| @@ -12,12 +12,13 @@ use tui::{ | |||
| 12 | use crate::{ | 12 | use crate::{ |
| 13 | app::app::App, | 13 | app::app::App, |
| 14 | functions::download_all_thumbnails, | 14 | functions::download_all_thumbnails, |
| 15 | structs::{Item, ListItem, MiniPlayList, MiniVideo, Page, Row, RowItem}, | 15 | structs::{Item, ListItem, MiniChannel, MiniPlayList, MiniVideo, Page, Row, RowItem}, |
| 16 | traits::{KeyInput, SelectItem}, | 16 | traits::{KeyInput, SelectItem}, |
| 17 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, | 17 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | use super::{ | 20 | use super::{ |
| 21 | channel::{Channel, ChannelPage}, | ||
| 21 | global::GlobalItem, | 22 | global::GlobalItem, |
| 22 | item_info::{DisplayItem, ItemInfo}, | 23 | item_info::{DisplayItem, ItemInfo}, |
| 23 | main_menu::textlist_from_video_list, | 24 | main_menu::textlist_from_video_list, |
| @@ -123,6 +124,26 @@ impl KeyInput for SearchItem { | |||
| 123 | ); | 124 | ); |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 127 | ListItem::MiniChannel(channel) => { | ||
| 128 | let state = Channel::default(); | ||
| 129 | let mut history = app.history.clone(); | ||
| 130 | history.push(app.into()); | ||
| 131 | |||
| 132 | return ( | ||
| 133 | false, | ||
| 134 | App { | ||
| 135 | history, | ||
| 136 | page: Page::Channel( | ||
| 137 | ChannelPage::Home, | ||
| 138 | channel.author_id.clone(), | ||
| 139 | ), | ||
| 140 | selectable: App::selectable(&state), | ||
| 141 | state, | ||
| 142 | ..Default::default() | ||
| 143 | }, | ||
| 144 | ); | ||
| 145 | } | ||
| 146 | |||
| 126 | _ => {} | 147 | _ => {} |
| 127 | } | 148 | } |
| 128 | } | 149 | } |
| @@ -136,7 +157,7 @@ impl KeyInput for SearchItem { | |||
| 136 | } | 157 | } |
| 137 | 158 | ||
| 138 | impl SearchItem { | 159 | impl SearchItem { |
| 139 | pub fn load_item(&self, app: &App) -> Result<Box<Self>, Box<dyn Error>> { | 160 | pub fn load_item(&self, app: &App) -> Result<Self, Box<dyn Error>> { |
| 140 | let mut this = self.clone(); | 161 | let mut this = self.clone(); |
| 141 | 162 | ||
| 142 | match &mut this { | 163 | match &mut this { |
| @@ -191,6 +212,19 @@ impl SearchItem { | |||
| 191 | items.push_back(ListItem::MiniPlayList(MiniPlayList::from(item))); | 212 | items.push_back(ListItem::MiniPlayList(MiniPlayList::from(item))); |
| 192 | } | 213 | } |
| 193 | 214 | ||
| 215 | InvidiousSearchItem::Channel { | ||
| 216 | author: _, | ||
| 217 | authorId: _, | ||
| 218 | authorUrl: _, | ||
| 219 | authorThumbnails: _, | ||
| 220 | subCount: _, | ||
| 221 | videoCount: _, | ||
| 222 | description: _, | ||
| 223 | descriptionHtml: _, | ||
| 224 | } => { | ||
| 225 | items.push_back(ListItem::MiniChannel(MiniChannel::from(item))); | ||
| 226 | } | ||
| 227 | |||
| 194 | _ => {} | 228 | _ => {} |
| 195 | } | 229 | } |
| 196 | } | 230 | } |
| @@ -226,6 +260,15 @@ impl SearchItem { | |||
| 226 | } | 260 | } |
| 227 | } | 261 | } |
| 228 | 262 | ||
| 263 | ListItem::MiniChannel(channel) => { | ||
| 264 | thumbnails.push_back(( | ||
| 265 | format!("https:{}", channel.thumbnail.clone()), | ||
| 266 | channel.author_id.clone(), | ||
| 267 | )); | ||
| 268 | |||
| 269 | // panic!("{:?}", channel.thumbnail.clone()); | ||
| 270 | } | ||
| 271 | |||
| 229 | _ => {} | 272 | _ => {} |
| 230 | } | 273 | } |
| 231 | } | 274 | } |
| @@ -236,7 +279,7 @@ impl SearchItem { | |||
| 236 | } | 279 | } |
| 237 | } | 280 | } |
| 238 | 281 | ||
| 239 | Ok(Box::new(this)) | 282 | Ok(this) |
| 240 | } | 283 | } |
| 241 | 284 | ||
| 242 | pub fn render_item<B: Backend>( | 285 | pub fn render_item<B: Backend>( |
src/functions/download_all_thumbnails.rs +1 −4
| @@ -20,9 +20,7 @@ pub fn download_all_thumbnails( | |||
| 20 | Ok(()) | 20 | Ok(()) |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | pub async fn download_items( | 23 | pub async fn download_items(urls: LinkedList<(String, String)>) -> Result<(), Box<dyn Error>> { |
| 24 | urls: LinkedList<(String, String)>, | ||
| 25 | ) -> Result<(), Box<dyn Error>> { | ||
| 26 | let mut actions = Vec::new(); | 24 | let mut actions = Vec::new(); |
| 27 | let mut path = home::home_dir().expect("Cannot get your home directory"); | 25 | let mut path = home::home_dir().expect("Cannot get your home directory"); |
| 28 | path.push(".cache"); | 26 | path.push(".cache"); |
| @@ -30,7 +28,6 @@ pub async fn download_items( | |||
| 30 | path.push("thumbnails"); | 28 | path.push("thumbnails"); |
| 31 | 29 | ||
| 32 | for (url, video_id) in urls.iter() { | 30 | for (url, video_id) in urls.iter() { |
| 33 | |||
| 34 | path.push(format!("{}.png", video_id)); | 31 | path.push(format!("{}.png", video_id)); |
| 35 | 32 | ||
| 36 | if !path.exists() { | 33 | if !path.exists() { |
src/functions/mod.rs +1 −1
| @@ -5,4 +5,4 @@ mod insert_vec; | |||
| 5 | pub use insert_vec::*; | 5 | pub use insert_vec::*; |
| 6 | 6 | ||
| 7 | mod center_rect; | 7 | mod center_rect; |
| 8 | pub use center_rect::*;\ No newline at end of file | 8 | pub use center_rect::*; |
src/main.rs +20 −4
| @@ -11,7 +11,7 @@ use tui::{ | |||
| 11 | use youtube_tui::{ | 11 | use youtube_tui::{ |
| 12 | app::{ | 12 | app::{ |
| 13 | app::App, | 13 | app::App, |
| 14 | pages::{item_info::ItemInfo, main_menu::MainMenu, search::Search}, | 14 | pages::{channel::Channel, item_info::ItemInfo, main_menu::MainMenu, search::Search}, |
| 15 | }, | 15 | }, |
| 16 | structs::{Item, Page, Row, RowItem}, | 16 | structs::{Item, Page, Row, RowItem}, |
| 17 | }; | 17 | }; |
| @@ -53,6 +53,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | |||
| 53 | Page::MainMenu(_) => MainMenu::message(), | 53 | Page::MainMenu(_) => MainMenu::message(), |
| 54 | Page::ItemDisplay(_) => ItemInfo::message(), | 54 | Page::ItemDisplay(_) => ItemInfo::message(), |
| 55 | Page::Search => Search::message(), | 55 | Page::Search => Search::message(), |
| 56 | Page::Channel(_, _) => Channel::message(), | ||
| 56 | }); | 57 | }); |
| 57 | terminal.clear()?; | 58 | terminal.clear()?; |
| 58 | ui(&mut terminal, &mut app)?; | 59 | ui(&mut terminal, &mut app)?; |
| @@ -64,7 +65,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | |||
| 64 | Item::MainMenu(item) => match item.load_item(&app) { | 65 | Item::MainMenu(item) => match item.load_item(&app) { |
| 65 | Ok(new) => { | 66 | Ok(new) => { |
| 66 | row_vec.push(RowItem { | 67 | row_vec.push(RowItem { |
| 67 | item: Item::MainMenu(*new), | 68 | item: Item::MainMenu(new), |
| 68 | ..*row_item | 69 | ..*row_item |
| 69 | }); | 70 | }); |
| 70 | } | 71 | } |
| @@ -81,7 +82,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | |||
| 81 | match item.load_item(&app, &mut watch_history) { | 82 | match item.load_item(&app, &mut watch_history) { |
| 82 | Ok(new) => { | 83 | Ok(new) => { |
| 83 | row_vec.push(RowItem { | 84 | row_vec.push(RowItem { |
| 84 | item: Item::ItemInfo(*new), | 85 | item: Item::ItemInfo(new), |
| 85 | ..*row_item | 86 | ..*row_item |
| 86 | }); | 87 | }); |
| 87 | } | 88 | } |
| @@ -98,7 +99,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | |||
| 98 | Item::Search(item) => match item.load_item(&app) { | 99 | Item::Search(item) => match item.load_item(&app) { |
| 99 | Ok(new) => { | 100 | Ok(new) => { |
| 100 | row_vec.push(RowItem { | 101 | row_vec.push(RowItem { |
| 101 | item: Item::Search(*new), | 102 | item: Item::Search(new), |
| 102 | ..*row_item | 103 | ..*row_item |
| 103 | }); | 104 | }); |
| 104 | } | 105 | } |
| @@ -110,6 +111,21 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | |||
| 110 | *app.message.lock().unwrap() = Some(e.to_string()); | 111 | *app.message.lock().unwrap() = Some(e.to_string()); |
| 111 | } | 112 | } |
| 112 | }, | 113 | }, |
| 114 | Item::Channel(item) => match item.load_item(&app) { | ||
| 115 | Ok(new) => { | ||
| 116 | row_vec.push(RowItem { | ||
| 117 | item: Item::Channel(new), | ||
| 118 | ..*row_item | ||
| 119 | }); | ||
| 120 | } | ||
| 121 | Err(e) => { | ||
| 122 | row_vec.push(RowItem { | ||
| 123 | item: Item::Channel(item.clone()), | ||
| 124 | ..*row_item | ||
| 125 | }); | ||
| 126 | *app.message.lock().unwrap() = Some(e.to_string()); | ||
| 127 | } | ||
| 128 | }, | ||
| 113 | _ => { | 129 | _ => { |
| 114 | row_vec.push(RowItem { | 130 | row_vec.push(RowItem { |
| 115 | item: row_item.item.clone(), | 131 | item: row_item.item.clone(), |
src/structs/fullchannel.rs added +28
| @@ -0,0 +1,28 @@ | |||
| 1 | use invidious::structs::channel::Channel; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use thousands::Separable; | ||
| 4 | |||
| 5 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 6 | pub struct FullChannel { | ||
| 7 | pub author: String, | ||
| 8 | pub author_id: String, | ||
| 9 | pub author_url: String, | ||
| 10 | pub thumbnail: String, | ||
| 11 | pub description: String, | ||
| 12 | pub sub_count: String, | ||
| 13 | pub total_views: String, | ||
| 14 | } | ||
| 15 | |||
| 16 | impl From<Channel> for FullChannel { | ||
| 17 | fn from(original: Channel) -> Self { | ||
| 18 | Self { | ||
| 19 | author: original.author, | ||
| 20 | author_id: original.authorId, | ||
| 21 | author_url: original.authorUrl, | ||
| 22 | thumbnail: original.authorThumbnails[4].url.clone(), | ||
| 23 | description: original.description, | ||
| 24 | sub_count: original.subCount.separate_with_commas(), | ||
| 25 | total_views: original.totalViews.separate_with_commas(), | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
src/structs/fullvideo.rs +1 −1
| @@ -1,7 +1,7 @@ | |||
| 1 | use chrono::{DateTime, NaiveDateTime, Utc}; | 1 | use chrono::{DateTime, NaiveDateTime, Utc}; |
| 2 | use invidious::structs::video::Video; | 2 | use invidious::structs::video::Video; |
| 3 | use thousands::Separable; | ||
| 4 | use serde::{Deserialize, Serialize}; | 3 | use serde::{Deserialize, Serialize}; |
| 4 | use thousands::Separable; | ||
| 5 | 5 | ||
| 6 | #[derive(Debug, Clone, Serialize, Deserialize)] | 6 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 7 | pub struct FullVideo { | 7 | pub struct FullVideo { |
src/structs/listitem.rs +15 −1
| @@ -1,7 +1,7 @@ | |||
| 1 | use crate::structs::{FullVideo, MiniVideo}; | 1 | use crate::structs::{FullVideo, MiniVideo}; |
| 2 | use serde::{Deserialize, Serialize}; | 2 | use serde::{Deserialize, Serialize}; |
| 3 | 3 | ||
| 4 | use super::{FullPlayList, MiniPlayList}; | 4 | use super::{FullChannel, FullPlayList, MiniChannel, MiniPlayList}; |
| 5 | 5 | ||
| 6 | #[derive(Debug, Clone, Deserialize, Serialize)] | 6 | #[derive(Debug, Clone, Deserialize, Serialize)] |
| 7 | pub enum ListItem { | 7 | pub enum ListItem { |
| @@ -9,6 +9,8 @@ pub enum ListItem { | |||
| 9 | FullVideo(FullVideo), | 9 | FullVideo(FullVideo), |
| 10 | MiniPlayList(MiniPlayList), | 10 | MiniPlayList(MiniPlayList), |
| 11 | FullPlayList(FullPlayList), | 11 | FullPlayList(FullPlayList), |
| 12 | MiniChannel(MiniChannel), | ||
| 13 | FullChannel(FullChannel), | ||
| 12 | PageTurner(bool), // true: +1 | false: -1 | 14 | PageTurner(bool), // true: +1 | false: -1 |
| 13 | } | 15 | } |
| 14 | 16 | ||
| @@ -58,6 +60,18 @@ impl ListItem { | |||
| 58 | .into_iter() | 60 | .into_iter() |
| 59 | .filter(|c| !c.is_ascii_control()) | 61 | .filter(|c| !c.is_ascii_control()) |
| 60 | .collect(), | 62 | .collect(), |
| 63 | ListItem::MiniChannel(channel) => channel | ||
| 64 | .author | ||
| 65 | .chars() | ||
| 66 | .into_iter() | ||
| 67 | .filter(|c| !c.is_ascii_control()) | ||
| 68 | .collect(), | ||
| 69 | ListItem::FullChannel(channel) => channel | ||
| 70 | .author | ||
| 71 | .chars() | ||
| 72 | .into_iter() | ||
| 73 | .filter(|c| !c.is_ascii_control()) | ||
| 74 | .collect(), | ||
| 61 | ListItem::PageTurner(turner) => { | 75 | ListItem::PageTurner(turner) => { |
| 62 | if *turner { | 76 | if *turner { |
| 63 | String::from("Next Page") | 77 | String::from("Next Page") |
src/structs/minichannel.rs added +41
| @@ -0,0 +1,41 @@ | |||
| 1 | use invidious::structs::hidden::SearchItem; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use thousands::Separable; | ||
| 4 | |||
| 5 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 6 | pub 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 | |||
| 16 | impl 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 | } | ||
src/structs/miniplaylist.rs +19 −1
| @@ -1,4 +1,4 @@ | |||
| 1 | use invidious::structs::hidden::SearchItem; | 1 | use invidious::structs::hidden::{Playlist, SearchItem}; |
| 2 | use serde::{Deserialize, Serialize}; | 2 | use serde::{Deserialize, Serialize}; |
| 3 | 3 | ||
| 4 | #[derive(Debug, Clone, Deserialize, Serialize)] | 4 | #[derive(Debug, Clone, Deserialize, Serialize)] |
| @@ -43,3 +43,21 @@ impl From<SearchItem> for MiniPlayList { | |||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | |||
| 47 | impl 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 | } | ||
src/structs/minivideo.rs +71 −28
| @@ -1,7 +1,9 @@ | |||
| 1 | use chrono::{prelude::*, Utc}; | 1 | use chrono::{prelude::*, Utc}; |
| 2 | use invidious::structs::hidden::{PopularItem, TrendingVideo, SearchItem, PlaylistItem}; | 2 | use invidious::structs::hidden::{ |
| 3 | use thousands::Separable; | 3 | ChannelVideo, PlaylistItem, PopularItem, SearchItem, TrendingVideo, |
| 4 | }; | ||
| 4 | use serde::{Deserialize, Serialize}; | 5 | use serde::{Deserialize, Serialize}; |
| 6 | use thousands::Separable; | ||
| 5 | 7 | ||
| 6 | #[derive(Debug, Clone, Serialize, Deserialize)] | 8 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 7 | pub struct MiniVideo { | 9 | pub struct MiniVideo { |
| @@ -75,31 +77,45 @@ impl From<PopularItem> for MiniVideo { | |||
| 75 | impl From<SearchItem> for MiniVideo { | 77 | impl From<SearchItem> for MiniVideo { |
| 76 | fn from(original: SearchItem) -> Self { | 78 | fn from(original: SearchItem) -> Self { |
| 77 | match original { | 79 | match original { |
| 78 | SearchItem::Video { title, videoId, author, authorId: _, authorUrl, lengthSeconds, videoThumbnails, description, descriptionHtml: _, viewCount, published, publishedText, liveNow: _, paid: _, premium: _ } => { | 80 | SearchItem::Video { |
| 79 | MiniVideo { | 81 | title, |
| 80 | title: title, | 82 | videoId, |
| 81 | video_id: videoId, | 83 | author, |
| 82 | video_thumbnail: videoThumbnails[0].url.clone(), | 84 | authorId: _, |
| 83 | length: hrtime::from_sec_padded(lengthSeconds as u64), | 85 | authorUrl, |
| 84 | view_count: Some(viewCount.separate_with_commas()), | 86 | lengthSeconds, |
| 85 | author: author, | 87 | videoThumbnails, |
| 86 | author_url: authorUrl, | 88 | description, |
| 87 | published: Some(format!( | 89 | descriptionHtml: _, |
| 88 | "{}{}", | 90 | viewCount, |
| 89 | publishedText, | 91 | published, |
| 90 | if Utc::now().timestamp() - published as i64 > 86400 { | 92 | publishedText, |
| 91 | let datetime: DateTime<Utc> = DateTime::from_utc( | 93 | liveNow: _, |
| 92 | NaiveDateTime::from_timestamp(published as i64, 0), | 94 | paid: _, |
| 93 | Utc, | 95 | premium: _, |
| 94 | ); | 96 | } => MiniVideo { |
| 95 | format!(" [{}]", datetime.format("%Y/%m/%d")) | 97 | title: title, |
| 96 | } else { | 98 | video_id: videoId, |
| 97 | String::new() | 99 | video_thumbnail: videoThumbnails[0].url.clone(), |
| 98 | } | 100 | length: hrtime::from_sec_padded(lengthSeconds as u64), |
| 99 | )), | 101 | view_count: Some(viewCount.separate_with_commas()), |
| 100 | description: Some(description), | 102 | author: author, |
| 101 | } | 103 | author_url: authorUrl, |
| 102 | } | 104 | published: Some(format!( |
| 105 | "{}{}", | ||
| 106 | publishedText, | ||
| 107 | if Utc::now().timestamp() - published as i64 > 86400 { | ||
| 108 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 109 | NaiveDateTime::from_timestamp(published as i64, 0), | ||
| 110 | Utc, | ||
| 111 | ); | ||
| 112 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 113 | } else { | ||
| 114 | String::new() | ||
| 115 | } | ||
| 116 | )), | ||
| 117 | description: Some(description), | ||
| 118 | }, | ||
| 103 | 119 | ||
| 104 | _ => unreachable!(), | 120 | _ => unreachable!(), |
| 105 | } | 121 | } |
| @@ -118,7 +134,34 @@ impl From<PlaylistItem> for MiniVideo { | |||
| 118 | author_url: original.authorUrl, | 134 | author_url: original.authorUrl, |
| 119 | published: None, | 135 | published: None, |
| 120 | description: None, | 136 | description: None, |
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 121 | 140 | ||
| 141 | impl From<ChannelVideo> for MiniVideo { | ||
| 142 | fn from(original: ChannelVideo) -> Self { | ||
| 143 | MiniVideo { | ||
| 144 | title: original.title, | ||
| 145 | video_id: original.videoId, | ||
| 146 | video_thumbnail: original.videoThumbnails[4].url.clone(), | ||
| 147 | length: hrtime::from_sec_padded(original.lengthSeconds as u64), | ||
| 148 | view_count: Some(original.viewCount.separate_with_commas()), | ||
| 149 | author: original.author, | ||
| 150 | author_url: original.authorUrl, | ||
| 151 | published: Some(format!( | ||
| 152 | "{}{}", | ||
| 153 | original.publishedText, | ||
| 154 | if Utc::now().timestamp() - original.published as i64 > 86400 { | ||
| 155 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 156 | NaiveDateTime::from_timestamp(original.published as i64, 0), | ||
| 157 | Utc, | ||
| 158 | ); | ||
| 159 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 160 | } else { | ||
| 161 | String::new() | ||
| 162 | } | ||
| 163 | )), | ||
| 164 | description: None, | ||
| 122 | } | 165 | } |
| 123 | } | 166 | } |
| 124 | }\ No newline at end of file | 167 | } |
src/structs/mod.rs +7 −1
| @@ -26,4 +26,10 @@ mod miniplaylist; | |||
| 26 | pub use miniplaylist::*; | 26 | pub use miniplaylist::*; |
| 27 | 27 | ||
| 28 | mod fullplaylist; | 28 | mod fullplaylist; |
| 29 | pub use fullplaylist::*;\ No newline at end of file | 29 | pub use fullplaylist::*; |
| 30 | |||
| 31 | mod minichannel; | ||
| 32 | pub use minichannel::*; | ||
| 33 | |||
| 34 | mod fullchannel; | ||
| 35 | pub use fullchannel::*; | ||
src/structs/page.rs +4 −1
| @@ -1,9 +1,12 @@ | |||
| 1 | use crate::app::pages::{item_info::DisplayItem, main_menu::MainMenuSelector}; | 1 | use crate::app::pages::{ |
| 2 | channel::ChannelPage, item_info::DisplayItem, main_menu::MainMenuSelector, | ||
| 3 | }; | ||
| 2 | 4 | ||
| 3 | #[derive(Debug, PartialEq, Clone)] | 5 | #[derive(Debug, PartialEq, Clone)] |
| 4 | pub enum Page { | 6 | pub enum Page { |
| 5 | MainMenu(MainMenuSelector), | 7 | MainMenu(MainMenuSelector), |
| 6 | ItemDisplay(DisplayItem), | 8 | ItemDisplay(DisplayItem), |
| 9 | Channel(ChannelPage, String), | ||
| 7 | Search, | 10 | Search, |
| 8 | } | 11 | } |
| 9 | 12 | ||
src/structs/states.rs +5 −1
| @@ -1,6 +1,9 @@ | |||
| 1 | use tui::layout::Constraint; | 1 | use tui::layout::Constraint; |
| 2 | 2 | ||
| 3 | use crate::app::pages::{global::GlobalItem, item_info::ItemInfoItem, main_menu::MainMenuItem, search::SearchItem}; | 3 | use crate::app::pages::{ |
| 4 | channel::ChannelItem, global::GlobalItem, item_info::ItemInfoItem, main_menu::MainMenuItem, | ||
| 5 | search::SearchItem, | ||
| 6 | }; | ||
| 4 | 7 | ||
| 5 | #[derive(Debug, Clone)] | 8 | #[derive(Debug, Clone)] |
| 6 | pub enum Item { | 9 | pub enum Item { |
| @@ -8,6 +11,7 @@ pub enum Item { | |||
| 8 | MainMenu(MainMenuItem), | 11 | MainMenu(MainMenuItem), |
| 9 | ItemInfo(ItemInfoItem), | 12 | ItemInfo(ItemInfoItem), |
| 10 | Search(SearchItem), | 13 | Search(SearchItem), |
| 14 | Channel(ChannelItem), | ||
| 11 | } | 15 | } |
| 12 | 16 | ||
| 13 | #[derive(Debug, Clone)] | 17 | #[derive(Debug, Clone)] |
src/traits/mod.rs +1 −1
| @@ -2,4 +2,4 @@ mod select_item; | |||
| 2 | pub use select_item::*; | 2 | pub use select_item::*; |
| 3 | 3 | ||
| 4 | mod key_input; | 4 | mod key_input; |
| 5 | pub use key_input::*;\ No newline at end of file | 5 | pub use key_input::*; |
src/widgets/force_clear.rs +9 −2
| @@ -1,4 +1,9 @@ | |||
| 1 | use tui::{widgets::Widget, buffer::Buffer, layout::Rect, style::{Color, Style}}; | 1 | use tui::{ |
| 2 | buffer::Buffer, | ||
| 3 | layout::Rect, | ||
| 4 | style::{Color, Style}, | ||
| 5 | widgets::Widget, | ||
| 6 | }; | ||
| 2 | 7 | ||
| 3 | pub struct ForceClear; | 8 | pub struct ForceClear; |
| 4 | 9 | ||
| @@ -6,7 +11,9 @@ impl Widget for ForceClear { | |||
| 6 | fn render(self, rect: Rect, buffer: &mut Buffer) { | 11 | fn render(self, rect: Rect, buffer: &mut Buffer) { |
| 7 | for y in rect.y..rect.y + rect.height { | 12 | for y in rect.y..rect.y + rect.height { |
| 8 | for x in rect.x..rect.x + rect.width { | 13 | for x in rect.x..rect.x + rect.width { |
| 9 | buffer.get_mut(x, y).set_style(Style::default().bg(Color::DarkGray)); | 14 | buffer |
| 15 | .get_mut(x, y) | ||
| 16 | .set_style(Style::default().bg(Color::DarkGray)); | ||
| 10 | } | 17 | } |
| 11 | } | 18 | } |
| 12 | } | 19 | } |
src/widgets/item_display.rs +160 −2
| @@ -16,6 +16,165 @@ pub struct ItemDisplay { | |||
| 16 | impl Widget for ItemDisplay { | 16 | impl Widget for ItemDisplay { |
| 17 | fn render(self, area: Rect, buf: &mut Buffer) { | 17 | fn render(self, area: Rect, buf: &mut Buffer) { |
| 18 | match self.item { | 18 | match self.item { |
| 19 | ListItem::MiniChannel(channel) => { | ||
| 20 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 21 | path.push(".cache"); | ||
| 22 | path.push("youtube-tui"); | ||
| 23 | path.push("thumbnails"); | ||
| 24 | path.push(format!("{}.png", channel.author_id)); | ||
| 25 | |||
| 26 | let exists = path.exists(); | ||
| 27 | let mut image_transform = area; | ||
| 28 | if exists { | ||
| 29 | if image_transform.width * 2 > image_transform.height { | ||
| 30 | image_transform.width = image_transform.height / 2; | ||
| 31 | } | ||
| 32 | image_transform.height = image_transform.width / 2; | ||
| 33 | // image_transform.width = image_transform.height * 2; | ||
| 34 | |||
| 35 | let conf = Config { | ||
| 36 | width: Some(image_transform.width as u32), | ||
| 37 | height: Some(image_transform.height as u32), | ||
| 38 | x: image_transform.x, | ||
| 39 | y: image_transform.y as i16, | ||
| 40 | ..Default::default() | ||
| 41 | }; | ||
| 42 | |||
| 43 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 44 | } | ||
| 45 | |||
| 46 | let mut y = if exists { | ||
| 47 | image_transform.y + image_transform.height | ||
| 48 | } else { | ||
| 49 | area.y | ||
| 50 | }; | ||
| 51 | |||
| 52 | let mut to_print = Vec::new(); | ||
| 53 | to_print.push((String::from("[Channel]"), Style::default().fg(Color::Gray))); | ||
| 54 | to_print.push((channel.author, Style::default().fg(Color::LightBlue))); | ||
| 55 | to_print.push(( | ||
| 56 | format!("Subscribers: {}", channel.sub_count), | ||
| 57 | Style::default().fg(Color::LightYellow), | ||
| 58 | )); | ||
| 59 | to_print.push(( | ||
| 60 | format!("Video Count: {}", channel.video_count), | ||
| 61 | Style::default().fg(Color::LightCyan), | ||
| 62 | )); | ||
| 63 | |||
| 64 | to_print.push(( | ||
| 65 | String::from("Description: "), | ||
| 66 | Style::default().fg(Color::Gray), | ||
| 67 | )); | ||
| 68 | |||
| 69 | for (mut item, style) in to_print { | ||
| 70 | if y > area.height + area.y - 1 { | ||
| 71 | return; | ||
| 72 | } | ||
| 73 | |||
| 74 | if item.len() > area.width as usize { | ||
| 75 | item = format!("{}...", &item[..area.width as usize - 3]); | ||
| 76 | } | ||
| 77 | buf.set_string(area.x, y, item, style); | ||
| 78 | y += 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | if y < area.height + area.y { | ||
| 82 | let rect = Rect { | ||
| 83 | x: area.x, | ||
| 84 | y: y, | ||
| 85 | width: area.width, | ||
| 86 | height: area.height + area.y - y, | ||
| 87 | }; | ||
| 88 | |||
| 89 | let paragraph = Paragraph::new(channel.description.clone()) | ||
| 90 | .wrap(Wrap { trim: true }) | ||
| 91 | .alignment(Alignment::Left) | ||
| 92 | .style(Style::default().fg(Color::Gray)); | ||
| 93 | |||
| 94 | paragraph.render(rect, buf); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | ListItem::FullChannel(channel) => { | ||
| 98 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 99 | path.push(".cache"); | ||
| 100 | path.push("youtube-tui"); | ||
| 101 | path.push("thumbnails"); | ||
| 102 | path.push(format!("{}.png", channel.author_id)); | ||
| 103 | |||
| 104 | let exists = path.exists(); | ||
| 105 | let mut image_transform = area; | ||
| 106 | if exists { | ||
| 107 | image_transform.height = image_transform.width * 9 / 64; | ||
| 108 | image_transform.width = image_transform.height * 2; | ||
| 109 | |||
| 110 | let conf = Config { | ||
| 111 | width: Some(image_transform.width as u32), | ||
| 112 | height: Some(image_transform.height as u32), | ||
| 113 | x: image_transform.x, | ||
| 114 | y: image_transform.y as i16, | ||
| 115 | ..Default::default() | ||
| 116 | }; | ||
| 117 | |||
| 118 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 119 | } | ||
| 120 | |||
| 121 | let mut y = if exists { | ||
| 122 | image_transform.y + image_transform.height | ||
| 123 | } else { | ||
| 124 | area.y | ||
| 125 | }; | ||
| 126 | |||
| 127 | let mut to_print = Vec::new(); | ||
| 128 | to_print.push((String::from("[Channel]"), Style::default().fg(Color::Gray))); | ||
| 129 | to_print.push((channel.author, Style::default().fg(Color::LightBlue))); | ||
| 130 | to_print.push(( | ||
| 131 | format!("Subscribers: {}", channel.sub_count), | ||
| 132 | Style::default().fg(Color::LightYellow), | ||
| 133 | )); | ||
| 134 | |||
| 135 | to_print.push(( | ||
| 136 | String::from("Description: "), | ||
| 137 | Style::default().fg(Color::Gray), | ||
| 138 | )); | ||
| 139 | |||
| 140 | to_print.push(( | ||
| 141 | format!("Total Views: {}", channel.total_views), | ||
| 142 | Style::default().fg(Color::LightCyan), | ||
| 143 | )); | ||
| 144 | |||
| 145 | to_print.push(( | ||
| 146 | String::from("Description: "), | ||
| 147 | Style::default().fg(Color::Gray), | ||
| 148 | )); | ||
| 149 | |||
| 150 | for (mut item, style) in to_print { | ||
| 151 | if y > area.height + area.y - 1 { | ||
| 152 | return; | ||
| 153 | } | ||
| 154 | |||
| 155 | if item.len() > area.width as usize { | ||
| 156 | item = format!("{}...", &item[..area.width as usize - 3]); | ||
| 157 | } | ||
| 158 | buf.set_string(area.x, y, item, style); | ||
| 159 | y += 1; | ||
| 160 | } | ||
| 161 | |||
| 162 | if y < area.height + area.y { | ||
| 163 | let rect = Rect { | ||
| 164 | x: area.x, | ||
| 165 | y: y, | ||
| 166 | width: area.width, | ||
| 167 | height: area.height + area.y - y, | ||
| 168 | }; | ||
| 169 | |||
| 170 | let paragraph = Paragraph::new(channel.description.clone()) | ||
| 171 | .wrap(Wrap { trim: true }) | ||
| 172 | .alignment(Alignment::Left) | ||
| 173 | .style(Style::default().fg(Color::Gray)); | ||
| 174 | |||
| 175 | paragraph.render(rect, buf); | ||
| 176 | } | ||
| 177 | } | ||
| 19 | ListItem::MiniVideo(video) => { | 178 | ListItem::MiniVideo(video) => { |
| 20 | let mut path = home::home_dir().expect("Cannot get your home directory"); | 179 | let mut path = home::home_dir().expect("Cannot get your home directory"); |
| 21 | path.push(".cache"); | 180 | path.push(".cache"); |
| @@ -318,7 +477,7 @@ impl Widget for ItemDisplay { | |||
| 318 | if y > area.height + area.y - 1 { | 477 | if y > area.height + area.y - 1 { |
| 319 | return; | 478 | return; |
| 320 | } | 479 | } |
| 321 | 480 | ||
| 322 | if item.len() > area.width as usize { | 481 | if item.len() > area.width as usize { |
| 323 | if item.len() > area.width as usize - 2 { | 482 | if item.len() > area.width as usize - 2 { |
| 324 | for _ in area.width as usize - 3..item.len() { | 483 | for _ in area.width as usize - 3..item.len() { |
| @@ -347,7 +506,6 @@ impl Widget for ItemDisplay { | |||
| 347 | 506 | ||
| 348 | paragraph.render(area, buf); | 507 | paragraph.render(area, buf); |
| 349 | } | 508 | } |
| 350 | |||
| 351 | } | 509 | } |
| 352 | } | 510 | } |
| 353 | } | 511 | } |
src/widgets/mod.rs +1 −1
| @@ -1,4 +1,4 @@ | |||
| 1 | pub mod force_clear; | ||
| 1 | pub mod horizontal_split; | 2 | pub mod horizontal_split; |
| 2 | pub mod item_display; | 3 | pub mod item_display; |
| 3 | pub mod text_list; | 4 | pub mod text_list; |
| 4 | pub mod force_clear;\ No newline at end of file | ||