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