Commit 8ebcdbe197
Unsigned
Layout: unified · split
Cargo.lock +2 −2
| @@ -1,6 +1,6 @@ | |||
| 1 | # This file is automatically @generated by Cargo. | 1 | # This file is automatically @generated by Cargo. |
| 2 | # It is not intended for manual editing. | 2 | # It is not intended for manual editing. |
| 3 | version = 3 | 3 | version = 4 |
| 4 | 4 | ||
| 5 | [[package]] | 5 | [[package]] |
| 6 | name = "adler" | 6 | name = "adler" |
| @@ -1590,7 +1590,7 @@ dependencies = [ | |||
| 1590 | 1590 | ||
| 1591 | [[package]] | 1591 | [[package]] |
| 1592 | name = "youtube-tui" | 1592 | name = "youtube-tui" |
| 1593 | version = "0.8.1" | 1593 | version = "0.8.2" |
| 1594 | dependencies = [ | 1594 | dependencies = [ |
| 1595 | "chrono", | 1595 | "chrono", |
| 1596 | "clipboard", | 1596 | "clipboard", |
Cargo.toml +1 −1
| @@ -1,6 +1,6 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "youtube-tui" | 2 | name = "youtube-tui" |
| 3 | version = "0.8.1" | 3 | version = "0.8.2" |
| 4 | authors = ["Siriusmart <siriusmart@tuta.io>"] | 4 | authors = ["Siriusmart <siriusmart@tuta.io>"] |
| 5 | edition = "2021" | 5 | edition = "2021" |
| 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" | 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" |
docs/src/config/commands.md +5
| @@ -84,6 +84,11 @@ Does not include custom env set in `main.yml`. | |||
| 84 | |`embed-url`|video|String url to the embed video (required to play video using mpv from Invidious)| | 84 | |`embed-url`|video|String url to the embed video (required to play video using mpv from Invidious)| |
| 85 | |`all-videos`|playlist|String url***s*** separated by space to all embed videos in a playlist| | 85 | |`all-videos`|playlist|String url***s*** separated by space to all embed videos in a playlist| |
| 86 | |`hover-url`|trending, popular, search|Url of the currenly hovering item.| | 86 | |`hover-url`|trending, popular, search|Url of the currenly hovering item.| |
| 87 | |`hover-id`|trending, popular, search|Url of the currenly hovering item.| | ||
| 88 | |`hover-channel`|trending, popular, search|Channel name of the currenly hovering item.| | ||
| 89 | |`hover-channel-id`|trending, popular, search|Channel ID of the currenly hovering item.| | ||
| 90 | |`hover-channel`|trending, popular, search|Url of the currenly hovering item.| | ||
| 91 | |`hover-channel-id`|trending, popular, search|Url of the currenly hovering item.| | ||
| 87 | |`hover-channel-url`|feed|Url of the currenly hovering channel.| | 92 | |`hover-channel-url`|feed|Url of the currenly hovering channel.| |
| 88 | |`hover-channel-id`|feed|ID of the currenly hovering channel.| | 93 | |`hover-channel-id`|feed|ID of the currenly hovering channel.| |
| 89 | |`hover-video-url`|feed|Url of the currenly hovering video.| | 94 | |`hover-video-url`|feed|Url of the currenly hovering video.| |
src/config/search.rs +40 −38
| @@ -1,3 +1,5 @@ | |||
| 1 | use std::fmt::Display; | ||
| 2 | |||
| 1 | use crate::global::{structs::Message, traits::*}; | 3 | use crate::global::{structs::Message, traits::*}; |
| 2 | use serde::{Deserialize, Serialize}; | 4 | use serde::{Deserialize, Serialize}; |
| 3 | use typemap::Key; | 5 | use typemap::Key; |
| @@ -30,9 +32,9 @@ impl ConfigTrait for Search { | |||
| 30 | const LABEL: &'static str = "search"; | 32 | const LABEL: &'static str = "search"; |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | impl ToString for Search { | 35 | impl Display for Search { |
| 34 | fn to_string(&self) -> String { | 36 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 35 | format!( | 37 | f.write_fmt(format_args!( |
| 36 | "{}&page={}", | 38 | "{}&page={}", |
| 37 | [ | 39 | [ |
| 38 | format!("q={}", encode(&self.query)), | 40 | format!("q={}", encode(&self.query)), |
| @@ -43,7 +45,7 @@ impl ToString for Search { | |||
| 43 | ] | 45 | ] |
| 44 | .join("&"), | 46 | .join("&"), |
| 45 | self.page | 47 | self.page |
| 46 | ) | 48 | )) |
| 47 | } | 49 | } |
| 48 | } | 50 | } |
| 49 | 51 | ||
| @@ -168,49 +170,49 @@ impl Default for SearchFilterType { | |||
| 168 | } | 170 | } |
| 169 | } | 171 | } |
| 170 | 172 | ||
| 171 | impl ToString for SearchFilterSort { | 173 | impl Display for SearchFilterSort { |
| 172 | fn to_string(&self) -> String { | 174 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 173 | match self { | 175 | f.write_str(match self { |
| 174 | Self::Relevance => String::from("relevance"), | 176 | Self::Relevance => "relevance", |
| 175 | Self::Rating => String::from("rating"), | 177 | Self::Rating => "rating", |
| 176 | Self::Date => String::from("date"), | 178 | Self::Date => "date", |
| 177 | Self::Views => String::from("views"), | 179 | Self::Views => "views", |
| 178 | } | 180 | }) |
| 179 | } | 181 | } |
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | impl ToString for SearchFilterDate { | 184 | impl Display for SearchFilterDate { |
| 183 | fn to_string(&self) -> String { | 185 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 184 | match self { | 186 | f.write_str(match self { |
| 185 | Self::None => String::from("none"), | 187 | Self::None => "none", |
| 186 | Self::Hour => String::from("hour"), | 188 | Self::Hour => "hour", |
| 187 | Self::Day => String::from("day"), | 189 | Self::Day => "day", |
| 188 | Self::Week => String::from("week"), | 190 | Self::Week => "week", |
| 189 | Self::Month => String::from("month"), | 191 | Self::Month => "month", |
| 190 | Self::Year => String::from("year"), | 192 | Self::Year => "year", |
| 191 | } | 193 | }) |
| 192 | } | 194 | } |
| 193 | } | 195 | } |
| 194 | 196 | ||
| 195 | impl ToString for SearchFilterDuration { | 197 | impl Display for SearchFilterDuration { |
| 196 | fn to_string(&self) -> String { | 198 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 197 | match self { | 199 | f.write_str(match self { |
| 198 | Self::None => String::from("none"), | 200 | Self::None => "none", |
| 199 | Self::Short => String::from("short"), | 201 | Self::Short => "short", |
| 200 | Self::Medium => String::from("medium"), | 202 | Self::Medium => "medium", |
| 201 | Self::Long => String::from("long"), | 203 | Self::Long => "long", |
| 202 | } | 204 | }) |
| 203 | } | 205 | } |
| 204 | } | 206 | } |
| 205 | 207 | ||
| 206 | impl ToString for SearchFilterType { | 208 | impl Display for SearchFilterType { |
| 207 | fn to_string(&self) -> String { | 209 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 208 | match self { | 210 | f.write_str(match self { |
| 209 | Self::All => String::from("all"), | 211 | Self::All => "all", |
| 210 | Self::Video => String::from("video"), | 212 | Self::Video => "video", |
| 211 | Self::Channel => String::from("channel"), | 213 | Self::Channel => "channel", |
| 212 | Self::Playlist => String::from("playlist"), | 214 | Self::Playlist => "playlist", |
| 213 | } | 215 | }) |
| 214 | } | 216 | } |
| 215 | } | 217 | } |
| 216 | 218 | ||
src/global/functions/update_provider.rs +4 −6
| @@ -30,13 +30,11 @@ pub fn update_provider(data: &mut FrameworkData) { | |||
| 30 | String::from("url"), | 30 | String::from("url"), |
| 31 | match status.provider { | 31 | match status.provider { |
| 32 | Provider::YouTube => { | 32 | Provider::YouTube => { |
| 33 | format!("https://youtube.com/results?{}", search.to_string()) | 33 | format!("https://youtube.com/results?{}", search) |
| 34 | } | ||
| 35 | Provider::Invidious => { | ||
| 36 | format!("{}/search?{}", mainconfig.invidious_instance, search) | ||
| 34 | } | 37 | } |
| 35 | Provider::Invidious => format!( | ||
| 36 | "{}/search?{}", | ||
| 37 | mainconfig.invidious_instance, | ||
| 38 | search.to_string() | ||
| 39 | ), | ||
| 40 | }, | 38 | }, |
| 41 | )], | 39 | )], |
| 42 | Page::MainMenu(MainMenuPage::Popular) => vec![( | 40 | Page::MainMenu(MainMenuPage::Popular) => vec![( |
src/global/structs/item.rs +1 −2
| @@ -59,8 +59,7 @@ pub struct MiniVideoItem { | |||
| 59 | 59 | ||
| 60 | impl PartialOrd for MiniVideoItem { | 60 | impl PartialOrd for MiniVideoItem { |
| 61 | fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | 61 | fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
| 62 | other.timestamp.partial_cmp(&self.timestamp) | 62 | Some(self.cmp(other)) |
| 63 | // self.timestamp.partial_cmp(&other.timestamp) | ||
| 64 | } | 63 | } |
| 65 | } | 64 | } |
| 66 | 65 | ||
src/global/structs/subscriptions.rs +6 −6
| @@ -264,7 +264,11 @@ pub struct SubItem { | |||
| 264 | impl Eq for SubItem {} | 264 | impl Eq for SubItem {} |
| 265 | impl Ord for SubItem { | 265 | impl Ord for SubItem { |
| 266 | fn cmp(&self, other: &Self) -> std::cmp::Ordering { | 266 | fn cmp(&self, other: &Self) -> std::cmp::Ordering { |
| 267 | self.partial_cmp(other).unwrap() | 267 | let get_timestamp = |item: &Self| match item.videos.first() { |
| 268 | Some(video) => video.timestamp.unwrap(), | ||
| 269 | None => 0, | ||
| 270 | }; | ||
| 271 | get_timestamp(other).cmp(&get_timestamp(self)) | ||
| 268 | } | 272 | } |
| 269 | } | 273 | } |
| 270 | 274 | ||
| @@ -282,11 +286,7 @@ impl PartialEq for SubItem { | |||
| 282 | 286 | ||
| 283 | impl PartialOrd for SubItem { | 287 | impl PartialOrd for SubItem { |
| 284 | fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | 288 | fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
| 285 | let get_timestamp = |item: &Self| match item.videos.first() { | 289 | Some(self.cmp(other)) |
| 286 | Some(video) => video.timestamp.unwrap(), | ||
| 287 | None => 0, | ||
| 288 | }; | ||
| 289 | get_timestamp(other).partial_cmp(&get_timestamp(self)) | ||
| 290 | } | 290 | } |
| 291 | } | 291 | } |
| 292 | 292 | ||
src/global/traits/collection.rs +1 −4
| @@ -220,10 +220,7 @@ where | |||
| 220 | 220 | ||
| 221 | // if res is err, then the file either doesn't exist of has be altered incorrectly, in | 221 | // if res is err, then the file either doesn't exist of has be altered incorrectly, in |
| 222 | // which case returns Self::default() | 222 | // which case returns Self::default() |
| 223 | let items = match res { | 223 | let items = res.unwrap_or_default(); |
| 224 | Ok(res) => res, | ||
| 225 | Err(_) => Vec::new(), | ||
| 226 | }; | ||
| 227 | 224 | ||
| 228 | Self::from_items(items) | 225 | Self::from_items(items) |
| 229 | } | 226 | } |
src/items/channeldisplay.rs +10 −7
| @@ -20,19 +20,22 @@ pub enum ChannelDisplay { | |||
| 20 | /// a blank item, will turn into one of the other variants when `.load()` depending on the page | 20 | /// a blank item, will turn into one of the other variants when `.load()` depending on the page |
| 21 | None, | 21 | None, |
| 22 | /// main channel display page | 22 | /// main channel display page |
| 23 | Main { channel: Item, iteminfo: ItemInfo }, | 23 | Main { |
| 24 | channel: Box<Item>, | ||
| 25 | iteminfo: Box<ItemInfo>, | ||
| 26 | }, | ||
| 24 | /// latest videos | 27 | /// latest videos |
| 25 | Videos { | 28 | Videos { |
| 26 | videos: Vec<Item>, | 29 | videos: Vec<Item>, |
| 27 | textlist: TextList, | 30 | textlist: TextList, |
| 28 | iteminfo: ItemInfo, | 31 | iteminfo: Box<ItemInfo>, |
| 29 | grid: Grid, | 32 | grid: Grid, |
| 30 | }, | 33 | }, |
| 31 | /// created playlists | 34 | /// created playlists |
| 32 | Playlists { | 35 | Playlists { |
| 33 | playlists: Vec<Item>, | 36 | playlists: Vec<Item>, |
| 34 | textlist: TextList, | 37 | textlist: TextList, |
| 35 | iteminfo: ItemInfo, | 38 | iteminfo: Box<ItemInfo>, |
| 36 | grid: Grid, | 39 | grid: Grid, |
| 37 | }, | 40 | }, |
| 38 | } | 41 | } |
| @@ -422,8 +425,8 @@ impl FrameworkItem for ChannelDisplay { | |||
| 422 | download_all_images(vec![(&channel).into()]); | 425 | download_all_images(vec![(&channel).into()]); |
| 423 | } | 426 | } |
| 424 | *self = Self::Main { | 427 | *self = Self::Main { |
| 425 | iteminfo: ItemInfo::new(Some(channel.clone())), | 428 | iteminfo: Box::new(ItemInfo::new(Some(channel.clone()))), |
| 426 | channel, | 429 | channel: Box::new(channel), |
| 427 | } | 430 | } |
| 428 | } | 431 | } |
| 429 | ChannelDisplayPageType::Videos => { | 432 | ChannelDisplayPageType::Videos => { |
| @@ -447,7 +450,7 @@ impl FrameworkItem for ChannelDisplay { | |||
| 447 | .border_type(appearance.borders) | 450 | .border_type(appearance.borders) |
| 448 | .style(Style::default().fg(appearance.colors.text)) | 451 | .style(Style::default().fg(appearance.colors.text)) |
| 449 | .items(&videos)?, | 452 | .items(&videos)?, |
| 450 | iteminfo: ItemInfo::new(videos.first().cloned()), | 453 | iteminfo: Box::new(ItemInfo::new(videos.first().cloned())), |
| 451 | grid: Grid::new( | 454 | grid: Grid::new( |
| 452 | vec![Constraint::Percentage(60), Constraint::Percentage(40)], | 455 | vec![Constraint::Percentage(60), Constraint::Percentage(40)], |
| 453 | vec![Constraint::Percentage(100)], | 456 | vec![Constraint::Percentage(100)], |
| @@ -477,7 +480,7 @@ impl FrameworkItem for ChannelDisplay { | |||
| 477 | .border_type(appearance.borders) | 480 | .border_type(appearance.borders) |
| 478 | .style(Style::default().fg(appearance.colors.text)) | 481 | .style(Style::default().fg(appearance.colors.text)) |
| 479 | .items(&playlists)?, | 482 | .items(&playlists)?, |
| 480 | iteminfo: ItemInfo::new(playlists.first().cloned()), | 483 | iteminfo: Box::new(ItemInfo::new(playlists.first().cloned())), |
| 481 | grid: Grid::new( | 484 | grid: Grid::new( |
| 482 | vec![Constraint::Percentage(60), Constraint::Percentage(40)], | 485 | vec![Constraint::Percentage(60), Constraint::Percentage(40)], |
| 483 | vec![Constraint::Percentage(100)], | 486 | vec![Constraint::Percentage(100)], |
src/items/itemlist.rs +78 −33
| @@ -37,44 +37,89 @@ impl ItemList { | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | match &self.items[self.textlist.selected] { | 39 | match &self.items[self.textlist.selected] { |
| 40 | Item::MiniVideo(MiniVideoItem { id, .. }) | 40 | Item::MiniVideo(MiniVideoItem { |
| 41 | | Item::FullVideo(FullVideoItem { id, .. }) => { | 41 | id, |
| 42 | vec![( | 42 | title, |
| 43 | String::from("hover-url"), | 43 | channel_id, |
| 44 | format!( | 44 | channel, |
| 45 | "{}/watch?v={id}", | 45 | .. |
| 46 | match status.provider { | 46 | }) |
| 47 | Provider::YouTube => "https://youtube.com", | 47 | | Item::FullVideo(FullVideoItem { |
| 48 | Provider::Invidious => &mainconfig.invidious_instance, | 48 | id, |
| 49 | } | 49 | title, |
| 50 | channel_id, | ||
| 51 | channel, | ||
| 52 | .. | ||
| 53 | }) => { | ||
| 54 | vec![ | ||
| 55 | ( | ||
| 56 | String::from("hover-url"), | ||
| 57 | format!( | ||
| 58 | "{}/watch?v={id}", | ||
| 59 | match status.provider { | ||
| 60 | Provider::YouTube => "https://youtube.com", | ||
| 61 | Provider::Invidious => &mainconfig.invidious_instance, | ||
| 62 | } | ||
| 63 | ), | ||
| 50 | ), | 64 | ), |
| 51 | )] | 65 | (String::from("hover-title"), title.clone()), |
| 66 | (String::from("hover-id"), id.clone()), | ||
| 67 | (String::from("hover-type"), String::from("video")), | ||
| 68 | (String::from("hover-channel-id"), channel_id.clone()), | ||
| 69 | (String::from("hover-channel"), channel.clone()), | ||
| 70 | ] | ||
| 52 | } | 71 | } |
| 53 | Item::MiniPlaylist(MiniPlaylistItem { id, .. }) | 72 | Item::MiniPlaylist(MiniPlaylistItem { |
| 54 | | Item::FullPlaylist(FullPlaylistItem { id, .. }) => { | 73 | id, |
| 55 | vec![( | 74 | title, |
| 56 | String::from("hover-url"), | 75 | channel_id, |
| 57 | format!( | 76 | channel, |
| 58 | "{}/playlist?list={id}", | 77 | .. |
| 59 | match status.provider { | 78 | }) |
| 60 | Provider::YouTube => "https://youtube.com", | 79 | | Item::FullPlaylist(FullPlaylistItem { |
| 61 | Provider::Invidious => &mainconfig.invidious_instance, | 80 | id, |
| 62 | } | 81 | title, |
| 82 | channel_id, | ||
| 83 | channel, | ||
| 84 | .. | ||
| 85 | }) => { | ||
| 86 | vec![ | ||
| 87 | ( | ||
| 88 | String::from("hover-url"), | ||
| 89 | format!( | ||
| 90 | "{}/playlist?list={id}", | ||
| 91 | match status.provider { | ||
| 92 | Provider::YouTube => "https://youtube.com", | ||
| 93 | Provider::Invidious => &mainconfig.invidious_instance, | ||
| 94 | } | ||
| 95 | ), | ||
| 63 | ), | 96 | ), |
| 64 | )] | 97 | (String::from("hover-title"), title.clone()), |
| 98 | (String::from("hover-id"), id.clone()), | ||
| 99 | (String::from("hover-type"), String::from("playlist")), | ||
| 100 | (String::from("hover-channel-id"), channel_id.clone()), | ||
| 101 | (String::from("hover-channel"), channel.clone()), | ||
| 102 | ] | ||
| 65 | } | 103 | } |
| 66 | Item::MiniChannel(MiniChannelItem { id, .. }) | 104 | Item::MiniChannel(MiniChannelItem { id, name, .. }) |
| 67 | | Item::FullChannel(FullChannelItem { id, .. }) => { | 105 | | Item::FullChannel(FullChannelItem { id, name, .. }) => { |
| 68 | vec![( | 106 | vec![ |
| 69 | String::from("hover-url"), | 107 | ( |
| 70 | format!( | 108 | String::from("hover-url"), |
| 71 | "{}/channel/{id}", | 109 | format!( |
| 72 | match status.provider { | 110 | "{}/channel/{id}", |
| 73 | Provider::YouTube => "https://youtube.com", | 111 | match status.provider { |
| 74 | Provider::Invidious => &mainconfig.invidious_instance, | 112 | Provider::YouTube => "https://youtube.com", |
| 75 | } | 113 | Provider::Invidious => &mainconfig.invidious_instance, |
| 114 | } | ||
| 115 | ), | ||
| 76 | ), | 116 | ), |
| 77 | )] | 117 | (String::from("hover-title"), name.clone()), |
| 118 | (String::from("hover-id"), id.clone()), | ||
| 119 | (String::from("hover-channel-id"), id.clone()), | ||
| 120 | (String::from("hover-channel"), name.clone()), | ||
| 121 | (String::from("hover-type"), String::from("channel")), | ||
| 122 | ] | ||
| 78 | } | 123 | } |
| 79 | Item::Page(_) => { | 124 | Item::Page(_) => { |
| 80 | vec![(String::from("hover-url"), String::from("not avaliable"))] | 125 | vec![(String::from("hover-url"), String::from("not avaliable"))] |
src/items/pagebutton.rs +14 −12
| @@ -1,3 +1,5 @@ | |||
| 1 | use std::fmt::Display; | ||
| 2 | |||
| 1 | use crate::{config::AppearanceConfig, global::structs::*}; | 3 | use crate::{config::AppearanceConfig, global::structs::*}; |
| 2 | use ratatui::{ | 4 | use ratatui::{ |
| 3 | layout::Alignment, | 5 | layout::Alignment, |
| @@ -53,18 +55,18 @@ impl PageButton { | |||
| 53 | // } | 55 | // } |
| 54 | } | 56 | } |
| 55 | 57 | ||
| 56 | impl ToString for PageButton { | 58 | impl Display for PageButton { |
| 57 | fn to_string(&self) -> String { | 59 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 58 | match self { | 60 | f.write_str(match self { |
| 59 | Self::Popular => String::from("Popular"), | 61 | Self::Popular => "Popular", |
| 60 | Self::Trending => String::from("Trending"), | 62 | Self::Trending => "Trending", |
| 61 | Self::ChannelMain => String::from("Main"), | 63 | Self::ChannelMain => "Main", |
| 62 | Self::ChannelVideos => String::from("Videos"), | 64 | Self::ChannelVideos => "Videos", |
| 63 | Self::ChannelPlaylists => String::from("Playlists"), | 65 | Self::ChannelPlaylists => "Playlists", |
| 64 | Self::History => String::from("History"), | 66 | Self::History => "History", |
| 65 | Self::Feed => String::from("Feed"), | 67 | Self::Feed => "Feed", |
| 66 | Self::Library => String::from("Library"), | 68 | Self::Library => "Library", |
| 67 | } | 69 | }) |
| 68 | } | 70 | } |
| 69 | } | 71 | } |
| 70 | 72 | ||