Commit 8ebcdbe197

8ebcdbe197eb877c221067b220d3e019a8dc864f

parent: 4888866509

Unsigned

siriusmart <siriusmart@tuta.io> · 2025-03-16 16:05 UTC

added hover variants

Layout: unified · split

Cargo.lock +2 −2
@@ -1,6 +1,6 @@
11# This file is automatically @generated by Cargo.
22# It is not intended for manual editing.
3version = 3
3version = 4
44
55[[package]]
66name = "adler"
@@ -1590,7 +1590,7 @@ dependencies = [
15901590
15911591[[package]]
15921592name = "youtube-tui"
1593version = "0.8.1"
1593version = "0.8.2"
15941594dependencies = [
15951595 "chrono",
15961596 "clipboard",
Cargo.toml +1 −1
@@ -1,6 +1,6 @@
11[package]
22name = "youtube-tui"
3version = "0.8.1"
3version = "0.8.2"
44authors = ["Siriusmart <siriusmart@tuta.io>"]
55edition = "2021"
66description = "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`.
8484|`embed-url`|video|String url to the embed video (required to play video using mpv from Invidious)|
8585|`all-videos`|playlist|String url***s*** separated by space to all embed videos in a playlist|
8686|`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.|
8792|`hover-channel-url`|feed|Url of the currenly hovering channel.|
8893|`hover-channel-id`|feed|ID of the currenly hovering channel.|
8994|`hover-video-url`|feed|Url of the currenly hovering video.|
src/config/search.rs +40 −38
@@ -1,3 +1,5 @@
1use std::fmt::Display;
2
13use crate::global::{structs::Message, traits::*};
24use serde::{Deserialize, Serialize};
35use typemap::Key;
@@ -30,9 +32,9 @@ impl ConfigTrait for Search {
3032 const LABEL: &'static str = "search";
3133}
3234
33impl ToString for Search {
34 fn to_string(&self) -> String {
35 format!(
35impl Display for Search {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 f.write_fmt(format_args!(
3638 "{}&page={}",
3739 [
3840 format!("q={}", encode(&self.query)),
@@ -43,7 +45,7 @@ impl ToString for Search {
4345 ]
4446 .join("&"),
4547 self.page
46 )
48 ))
4749 }
4850}
4951
@@ -168,49 +170,49 @@ impl Default for SearchFilterType {
168170 }
169171}
170172
171impl 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 }
173impl 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 })
179181 }
180182}
181183
182impl 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 }
184impl 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 })
192194 }
193195}
194196
195impl 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 }
197impl 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 })
203205 }
204206}
205207
206impl 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 }
208impl 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 })
214216 }
215217}
216218
src/global/functions/update_provider.rs +4 −6
@@ -30,13 +30,11 @@ pub fn update_provider(data: &mut FrameworkData) {
3030 String::from("url"),
3131 match status.provider {
3232 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)
3437 }
35 Provider::Invidious => format!(
36 "{}/search?{}",
37 mainconfig.invidious_instance,
38 search.to_string()
39 ),
4038 },
4139 )],
4240 Page::MainMenu(MainMenuPage::Popular) => vec![(
src/global/structs/item.rs +1 −2
@@ -59,8 +59,7 @@ pub struct MiniVideoItem {
5959
6060impl PartialOrd for MiniVideoItem {
6161 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))
6463 }
6564}
6665
src/global/structs/subscriptions.rs +6 −6
@@ -264,7 +264,11 @@ pub struct SubItem {
264264impl Eq for SubItem {}
265265impl Ord for SubItem {
266266 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))
268272 }
269273}
270274
@@ -282,11 +286,7 @@ impl PartialEq for SubItem {
282286
283287impl PartialOrd for SubItem {
284288 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))
290290 }
291291}
292292
src/global/traits/collection.rs +1 −4
@@ -220,10 +220,7 @@ where
220220
221221 // if res is err, then the file either doesn't exist of has be altered incorrectly, in
222222 // 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();
227224
228225 Self::from_items(items)
229226 }
src/items/channeldisplay.rs +10 −7
@@ -20,19 +20,22 @@ pub enum ChannelDisplay {
2020 /// a blank item, will turn into one of the other variants when `.load()` depending on the page
2121 None,
2222 /// main channel display page
23 Main { channel: Item, iteminfo: ItemInfo },
23 Main {
24 channel: Box<Item>,
25 iteminfo: Box<ItemInfo>,
26 },
2427 /// latest videos
2528 Videos {
2629 videos: Vec<Item>,
2730 textlist: TextList,
28 iteminfo: ItemInfo,
31 iteminfo: Box<ItemInfo>,
2932 grid: Grid,
3033 },
3134 /// created playlists
3235 Playlists {
3336 playlists: Vec<Item>,
3437 textlist: TextList,
35 iteminfo: ItemInfo,
38 iteminfo: Box<ItemInfo>,
3639 grid: Grid,
3740 },
3841}
@@ -422,8 +425,8 @@ impl FrameworkItem for ChannelDisplay {
422425 download_all_images(vec![(&channel).into()]);
423426 }
424427 *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),
427430 }
428431 }
429432 ChannelDisplayPageType::Videos => {
@@ -447,7 +450,7 @@ impl FrameworkItem for ChannelDisplay {
447450 .border_type(appearance.borders)
448451 .style(Style::default().fg(appearance.colors.text))
449452 .items(&videos)?,
450 iteminfo: ItemInfo::new(videos.first().cloned()),
453 iteminfo: Box::new(ItemInfo::new(videos.first().cloned())),
451454 grid: Grid::new(
452455 vec![Constraint::Percentage(60), Constraint::Percentage(40)],
453456 vec![Constraint::Percentage(100)],
@@ -477,7 +480,7 @@ impl FrameworkItem for ChannelDisplay {
477480 .border_type(appearance.borders)
478481 .style(Style::default().fg(appearance.colors.text))
479482 .items(&playlists)?,
480 iteminfo: ItemInfo::new(playlists.first().cloned()),
483 iteminfo: Box::new(ItemInfo::new(playlists.first().cloned())),
481484 grid: Grid::new(
482485 vec![Constraint::Percentage(60), Constraint::Percentage(40)],
483486 vec![Constraint::Percentage(100)],
src/items/itemlist.rs +78 −33
@@ -37,44 +37,89 @@ impl ItemList {
3737 }
3838
3939 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 ),
5064 ),
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 ]
5271 }
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 ),
6396 ),
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 ]
65103 }
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 ),
76116 ),
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 ]
78123 }
79124 Item::Page(_) => {
80125 vec![(String::from("hover-url"), String::from("not avaliable"))]
src/items/pagebutton.rs +14 −12
@@ -1,3 +1,5 @@
1use std::fmt::Display;
2
13use crate::{config::AppearanceConfig, global::structs::*};
24use ratatui::{
35 layout::Alignment,
@@ -53,18 +55,18 @@ impl PageButton {
5355 // }
5456}
5557
56impl 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 }
58impl 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 })
6870 }
6971}
7072