Commit af1b4fe68d

af1b4fe68d11b772091927d15a6b8d3d75cfcffe

parent: 364209299d

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-01-06 19:15 UTC

0.6.1

Layout: unified · split

Cargo.lock +5 −5
@@ -150,9 +150,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
150 150
151[[package]] 151[[package]]
152name = "console" 152name = "console"
153version = "0.15.3" 153version = "0.15.4"
154source = "registry+https://github.com/rust-lang/crates.io-index" 154source = "registry+https://github.com/rust-lang/crates.io-index"
155checksum = "5556015fe3aad8b968e5d4124980fbe2f6aaee7aeec6b749de1faaa2ca5d0a4c" 155checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a"
156dependencies = [ 156dependencies = [
157 "encode_unicode", 157 "encode_unicode",
158 "lazy_static", 158 "lazy_static",
@@ -1477,9 +1477,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
1477 1477
1478[[package]] 1478[[package]]
1479name = "tokio" 1479name = "tokio"
1480version = "1.23.0" 1480version = "1.24.0"
1481source = "registry+https://github.com/rust-lang/crates.io-index" 1481source = "registry+https://github.com/rust-lang/crates.io-index"
1482checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" 1482checksum = "7125661431c26622a80ca5051a2f936c9a678318e0351007b0cc313143024e5c"
1483dependencies = [ 1483dependencies = [
1484 "autocfg", 1484 "autocfg",
1485 "bytes", 1485 "bytes",
@@ -1943,7 +1943,7 @@ dependencies = [
1943 1943
1944[[package]] 1944[[package]]
1945name = "youtube-tui" 1945name = "youtube-tui"
1946version = "0.6.0" 1946version = "0.6.1"
1947dependencies = [ 1947dependencies = [
1948 "chrono", 1948 "chrono",
1949 "clipboard", 1949 "clipboard",
Cargo.toml +1 −1
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "youtube-tui" 2name = "youtube-tui"
3version = "0.6.0" 3version = "0.6.1"
4authors = ["Siriusmart <siriusmart@tuta.io>"] 4authors = ["Siriusmart <siriusmart@tuta.io>"]
5edition = "2021" 5edition = "2021"
6description = "An aesthetically pleasing YouTube TUI written in Rust" 6description = "An aesthetically pleasing YouTube TUI written in Rust"
README.md +6 −9
@@ -12,7 +12,7 @@ Written in Rust, the **YouTube TUI** is a lightweight and user friendly TUI for
12 12
13![](./docs/src/images/search-showcase.png) 13![](./docs/src/images/search-showcase.png)
14 14
15It is like an *app launcher*, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). 15It is like an _app launcher_, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos).
16 16
17## Customisable 17## Customisable
18 18
@@ -21,6 +21,7 @@ The YouTube TUI can be customised through config files, they are located in `~/.
21Here's an example of the config file: 21Here's an example of the config file:
22 22
23```yaml 23```yaml
24mouse_support: true
24invidious_instance: https://vid.puffyan.us 25invidious_instance: https://vid.puffyan.us
25max_watch_history: 50 26max_watch_history: 50
26allow_unicode: false 27allow_unicode: false
@@ -32,14 +33,13 @@ env:
32 video-player: mpv 33 video-player: mpv
33 youtube-downloader: yt-dlp 34 youtube-downloader: yt-dlp
34 terminal-emulator: konsole -e 35 terminal-emulator: konsole -e
35
36``` 36```
37 37
38Anything from layouts to colours and keybindings can be customised, more on that later. 38Anything from layouts to colours and keybindings can be customised, more on that later.
39 39
40## Dependency-free 40## Dependency-free
41 41
42The YouTube TUI does not work on its own, it is instead like a *TUI frontend* for programs like `mpv` or `yt-dlp`/`youtube-dl`. 42The YouTube TUI does not work on its own, it is instead like a _TUI frontend_ for programs like `mpv` or `yt-dlp`/`youtube-dl`.
43 43
44However, the programs to launch can be changed, and therefore the YouTube TUI <u>does not rely on any specific dependencies</u> to run. 44However, the programs to launch can be changed, and therefore the YouTube TUI <u>does not rely on any specific dependencies</u> to run.
45 45
@@ -61,20 +61,17 @@ It also includes features like:
61 61
62### What it doesn't have 62### What it doesn't have
63 63
64- Command line args (first priority) 64- Binding commands to keys (first priority)
65- Bootleg Vimscript? (will implement)
66- Channel search (will implement) 65- Channel search (will implement)
67- Channel videos sorting (will implement)
68- Subscriptions (will implement) 66- Subscriptions (will implement)
69- Recommendations/comments (probably will not implement)
70 67
71## How to contribute 68## How to contribute
72 69
73You will need a <u>general knowledge</u> of the Rust programming language, and the ability to *understand my spaghetti*. 70You will need a <u>general knowledge</u> of the Rust programming language, and the ability to _understand my spaghetti_.
74 71
751. Open an issue to make sure nobody else is working on the same feature 721. Open an issue to make sure nobody else is working on the same feature
762. Write code 732. Write code
773. Open a pull request 743. Open a pull request
784. Get merged? 754. Get merged?
79 76
80Or just *fix that typo in README* -_- 77Or just _fix that typo in README_ -\_-
docs/src/README.md +5 −7
@@ -4,7 +4,7 @@ Written in Rust, the **YouTube TUI** is a lightweight and user friendly TUI for
4 4
5![](./images/search-showcase.png) 5![](./images/search-showcase.png)
6 6
7It is like an *app launcher*, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). 7It is like an _app launcher_, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos).
8 8
9## Customisable 9## Customisable
10 10
@@ -13,6 +13,7 @@ The YouTube TUI can be customised through config files, they are located in `~/.
13Here's an example of the config file: 13Here's an example of the config file:
14 14
15```yaml 15```yaml
16mouse_support: true
16invidious_instance: https://vid.puffyan.us 17invidious_instance: https://vid.puffyan.us
17max_watch_history: 50 18max_watch_history: 50
18allow_unicode: false 19allow_unicode: false
@@ -24,14 +25,13 @@ env:
24 video-player: mpv 25 video-player: mpv
25 youtube-downloader: yt-dlp 26 youtube-downloader: yt-dlp
26 terminal-emulator: konsole -e 27 terminal-emulator: konsole -e
27
28``` 28```
29 29
30Anything from layouts to colours and keybindings can be customised, more on that later. 30Anything from layouts to colours and keybindings can be customised, more on that later.
31 31
32## Dependency-free 32## Dependency-free
33 33
34The YouTube TUI does not work on its own, it is instead like a *TUI frontend* for programs like `mpv` or `yt-dlp`/`youtube-dl`. 34The YouTube TUI does not work on its own, it is instead like a _TUI frontend_ for programs like `mpv` or `yt-dlp`/`youtube-dl`.
35 35
36However, the programs to launch can be changed, and therefore the YouTube TUI <u>does not rely on any specific dependencies</u> to run. 36However, the programs to launch can be changed, and therefore the YouTube TUI <u>does not rely on any specific dependencies</u> to run.
37 37
@@ -54,18 +54,16 @@ It also includes features like:
54### What it doesn't have 54### What it doesn't have
55 55
56- Binding commands to keys (first priority) 56- Binding commands to keys (first priority)
57- Bootleg Vimscript? (first priority)
58- Channel search (will implement) 57- Channel search (will implement)
59- Channel videos sorting (will implement)
60- Subscriptions (will implement) 58- Subscriptions (will implement)
61 59
62## How to contribute 60## How to contribute
63 61
64You will need a <u>general knowledge</u> of the Rust programming language, and the ability to *understand my spaghetti*. 62You will need a <u>general knowledge</u> of the Rust programming language, and the ability to _understand my spaghetti_.
65 63
661. Open an issue to make sure nobody else is working on the same feature 641. Open an issue to make sure nobody else is working on the same feature
672. Write code 652. Write code
683. Open a pull request 663. Open a pull request
694. Get merged? 674. Get merged?
70 68
71Or just *fix that typo in README* -_- 69Or just _fix that typo in README_ -\_-
docs/src/commands.md +1
@@ -38,6 +38,7 @@ reload (alt `r`)
38reload configs (alt `reload/r config/configs`) 38reload configs (alt `reload/r config/configs`)
39flush 39flush
40quit (alt `q`, `exit`, `x`) 40quit (alt `q`, `exit`, `x`)
41run [command]
41``` 42```
42 43
43> The `flush` command is used to run all tasks in queue immediately, this is usually done automatically. 44> The `flush` command is used to run all tasks in queue immediately, this is usually done automatically.
src/config/commands.rs +15 −15
@@ -63,36 +63,36 @@ fn video_default() -> Vec<HashMap<String, String>> {
63 vec![ 63 vec![
64 HashMap::from([( 64 HashMap::from([(
65 String::from("Play video"), 65 String::from("Play video"),
66 String::from("${video-player} ${embed-url}"), 66 String::from("run ${video-player} ${embed-url}"),
67 )]), 67 )]),
68 HashMap::from([( 68 HashMap::from([(
69 String::from("Play audio"), 69 String::from("Play audio"),
70 String::from("${terminal-emulator} ${video-player} ${embed-url} --no-video"), 70 String::from("run ${terminal-emulator} ${video-player} ${embed-url} --no-video"),
71 )]), 71 )]),
72 HashMap::from([( 72 HashMap::from([(
73 String::from("Play audio (loop)"), 73 String::from("Play audio (loop)"),
74 String::from( 74 String::from(
75 "${terminal-emulator} ${video-player} ${embed-url} --no-video --loop-file=inf", 75 "run ${terminal-emulator} ${video-player} ${embed-url} --no-video --loop-file=inf",
76 ), 76 ),
77 )]), 77 )]),
78 HashMap::from([( 78 HashMap::from([(
79 String::from("View channel"), 79 String::from("View channel"),
80 String::from(":channel ${channel-id}"), 80 String::from("channel ${channel-id}"),
81 )]), 81 )]),
82 HashMap::from([( 82 HashMap::from([(
83 String::from("Open in browser"), 83 String::from("Open in browser"),
84 String::from("${browser} ${url}"), 84 String::from("run ${browser} ${url}"),
85 )]), 85 )]),
86 HashMap::from([( 86 HashMap::from([(
87 String::from("Download video (webm)"), 87 String::from("Download video (webm)"),
88 String::from( 88 String::from(
89 "${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url}", 89 "run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url}",
90 ), 90 ),
91 )]), 91 )]),
92 HashMap::from([( 92 HashMap::from([(
93 String::from("Download audio (opus)"), 93 String::from("Download audio (opus)"),
94 String::from( 94 String::from(
95 "${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} -x", 95 "run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} -x",
96 ), 96 ),
97 )]), 97 )]),
98 HashMap::from([( 98 HashMap::from([(
@@ -107,35 +107,35 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
107 HashMap::from([(String::from("Switch view"), String::from("%switch-view%"))]), 107 HashMap::from([(String::from("Switch view"), String::from("%switch-view%"))]),
108 HashMap::from([( 108 HashMap::from([(
109 String::from("Play all videos"), 109 String::from("Play all videos"),
110 String::from("${video-player} ${all-videos}"), 110 String::from("run ${video-player} ${all-videos}"),
111 )]), 111 )]),
112 HashMap::from([( 112 HashMap::from([(
113 String::from("Play all audio"), 113 String::from("Play all audio"),
114 String::from("${terminal-emulator} ${video-player} ${all-videos} --no-video"), 114 String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video"),
115 )]), 115 )]),
116 HashMap::from([( 116 HashMap::from([(
117 String::from("Shuffle play all audio"), 117 String::from("Shuffle play all audio"),
118 String::from("${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle"), 118 String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle"),
119 )]), 119 )]),
120 HashMap::from([( 120 HashMap::from([(
121 String::from("Shuffle play all audio (loop)"), 121 String::from("Shuffle play all audio (loop)"),
122 String::from("${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf"), 122 String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf"),
123 )]), 123 )]),
124 HashMap::from([( 124 HashMap::from([(
125 String::from("View channel"), 125 String::from("View channel"),
126 String::from(":channel ${channel-id}"), 126 String::from("channel ${channel-id}"),
127 )]), 127 )]),
128 HashMap::from([( 128 HashMap::from([(
129 String::from("Open in browser"), 129 String::from("Open in browser"),
130 String::from("${browser} ${url}"), 130 String::from("run ${browser} ${url}"),
131 )]), 131 )]),
132 HashMap::from([( 132 HashMap::from([(
133 String::from("Download all video (webm)"), 133 String::from("Download all video (webm)"),
134 String::from("${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos}") 134 String::from("run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos}")
135 )]), 135 )]),
136 HashMap::from([( 136 HashMap::from([(
137 String::from("Download all audio (opus)"), 137 String::from("Download all audio (opus)"),
138 String::from("${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x") 138 String::from("run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x")
139 )]), 139 )]),
140 HashMap::from([( 140 HashMap::from([(
141 String::from("Mode: ${provider}"), 141 String::from("Mode: ${provider}"),
src/global/functions/run_command.rs +10 −1
@@ -237,8 +237,16 @@ pub fn run_command(
237 )); 237 ));
238 false 238 false
239 } 239 }
240 ["run"] => {
241 *framework.data.global.get_mut::<Message>().unwrap() =
242 Message::Message(String::from("Usage: run [command]"));
243 false
244 }
240 ["run", ..] => { 245 ["run", ..] => {
241 let mut command = execute::command(&command[1..].join(" ")); 246 let command = &command[1..].join(" ");
247 *framework.data.global.get_mut::<Message>().unwrap() =
248 Message::Success(command.clone());
249 let mut command = execute::command(command);
242 thread::spawn(move || { 250 thread::spawn(move || {
243 let _ = command.output(); 251 let _ = command.output();
244 }); 252 });
@@ -313,6 +321,7 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
313 \x1b[33mreload configs\x1b[0m Reload all config files 321 \x1b[33mreload configs\x1b[0m Reload all config files
314 \x1b[33mflush\x1b[0m Run all tasks in queue immediately 322 \x1b[33mflush\x1b[0m Run all tasks in queue immediately
315 \x1b[33mquit\x1b[0m Immediately exit 323 \x1b[33mquit\x1b[0m Immediately exit
324 \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run firefox example.com`)
316 325
317\x1b[91mALT:\x1b[0m 326\x1b[91mALT:\x1b[0m
318\x1b[37malts links back to the original command\x1b[30m 327\x1b[37malts links back to the original command\x1b[30m
src/items/channeldisplay.rs +1 −4
@@ -25,10 +25,7 @@ pub enum ChannelDisplay {
25 /// a blank item, will turn into one of the other variants when `.load()` depending on the page 25 /// a blank item, will turn into one of the other variants when `.load()` depending on the page
26 None, 26 None,
27 /// main channel display page 27 /// main channel display page
28 Main { 28 Main { channel: Item, iteminfo: ItemInfo },
29 channel: Item,
30 iteminfo: ItemInfo,
31 },
32 /// latest videos 29 /// latest videos
33 Videos { 30 Videos {
34 videos: Vec<Item>, 31 videos: Vec<Item>,
src/items/singleitem.rs +28 −47
@@ -9,7 +9,6 @@ use crate::{
9 }, 9 },
10 }, 10 },
11}; 11};
12use std::thread;
13use tui::{ 12use tui::{
14 layout::{Constraint, Rect}, 13 layout::{Constraint, Rect},
15 style::Style, 14 style::Style,
@@ -337,10 +336,12 @@ impl SinglePlaylistItem {
337} 336}
338 337
339impl SingleItemType { 338impl SingleItemType {
339 /// self is none
340 pub fn is_none(&self) -> bool { 340 pub fn is_none(&self) -> bool {
341 matches!(self, Self::None) 341 matches!(self, Self::None)
342 } 342 }
343 343
344 /// update colours every render
344 pub fn update_appearance( 345 pub fn update_appearance(
345 &mut self, 346 &mut self,
346 appearance: &AppearanceConfig, 347 appearance: &AppearanceConfig,
@@ -372,6 +373,7 @@ impl SingleItemType {
372} 373}
373 374
374impl SingleItem { 375impl SingleItem {
376 /// update colours and layout every render
375 fn update_appearance( 377 fn update_appearance(
376 &mut self, 378 &mut self,
377 appearance: &AppearanceConfig, 379 appearance: &AppearanceConfig,
@@ -394,6 +396,7 @@ impl SingleItem {
394 .update_appearance(appearance, iteminfo, &mut self.grid); 396 .update_appearance(appearance, iteminfo, &mut self.grid);
395 } 397 }
396 398
399 /// update hover item preview
397 fn update(&mut self) { 400 fn update(&mut self) {
398 if let SingleItemType::Playlist(singleplaylistitem) = &mut self.r#type { 401 if let SingleItemType::Playlist(singleplaylistitem) = &mut self.r#type {
399 let SinglePlaylistItem { 402 let SinglePlaylistItem {
@@ -418,6 +421,7 @@ impl SingleItem {
418 } 421 }
419 } 422 }
420 423
424 /// handle enter presses
421 fn select_at_cursor( 425 fn select_at_cursor(
422 &mut self, 426 &mut self,
423 framework: &mut FrameworkClean, 427 framework: &mut FrameworkClean,
@@ -440,31 +444,14 @@ impl SingleItem {
440 ); 444 );
441 } 445 }
442 _ => { 446 _ => {
443 // joins the env from the one in mainconfig and video info
444 let command_string = apply_envs(command_string);
445
446 // check if the command starts with an ':' which case should be captured 447 // check if the command starts with an ':' which case should be captured
447 if &command_string[0..1] == ":" { 448 framework
448 framework 449 .data
449 .data 450 .state
450 .state 451 .get_mut::<Tasks>()
451 .get_mut::<Tasks>() 452 .unwrap()
452 .unwrap() 453 .priority
453 .priority 454 .push(Task::Command(apply_envs(command_string)));
454 .push(Task::Command(command_string[1..].to_string()))
455 }
456
457 // this allows creating commands from string
458 let mut command = execute::command(command_string);
459
460 *framework.data.global.get_mut::<Message>().unwrap() = Message::Success(
461 format!("{:?} {:?}", command.get_program(), command.get_args()),
462 );
463
464 // run the command in a new thread so it doesn't freeze the current one
465 thread::spawn(move || {
466 let _ = command.output();
467 });
468 } 455 }
469 } 456 }
470 } 457 }
@@ -491,27 +478,14 @@ impl SingleItem {
491 } 478 }
492 // same as before if string is not a special case then the run the command 479 // same as before if string is not a special case then the run the command
493 _ => { 480 _ => {
494 let command_string = apply_envs(command_string);
495
496 // check if the command starts with an ':' which case should be captured 481 // check if the command starts with an ':' which case should be captured
497 if &command_string[0..1] == ":" { 482 framework
498 framework 483 .data
499 .data 484 .state
500 .state 485 .get_mut::<Tasks>()
501 .get_mut::<Tasks>() 486 .unwrap()
502 .unwrap() 487 .priority
503 .priority 488 .push(Task::Command(apply_envs(command_string)));
504 .push(Task::Command(command_string[1..].to_string()))
505 }
506
507 *framework.data.global.get_mut::<Message>().unwrap() =
508 Message::Success(command_string.clone());
509
510 let mut command = execute::command(command_string);
511
512 thread::spawn(move || {
513 let _ = command.output();
514 });
515 } 489 }
516 }; 490 };
517 } 491 }
@@ -762,7 +736,8 @@ impl FrameworkItem for SingleItem {
762 [singleplaylistitem.videos_view.selected - 1] 736 [singleplaylistitem.videos_view.selected - 1]
763 .clone(), 737 .clone(),
764 ); 738 );
765 } updated 739 }
740 updated
766 } 741 }
767 KeyAction::MoveDown => { 742 KeyAction::MoveDown => {
768 let updated = singleplaylistitem.videos_view.down().is_ok(); 743 let updated = singleplaylistitem.videos_view.down().is_ok();
@@ -883,7 +858,13 @@ impl FrameworkItem for SingleItem {
883 } else { 858 } else {
884 let y = (y - chunk.y) as usize + singleplaylistitem.videos_view.scroll; 859 let y = (y - chunk.y) as usize + singleplaylistitem.videos_view.scroll;
885 if singleplaylistitem.videos_view.selected != 0 && y == 0 { 860 if singleplaylistitem.videos_view.selected != 0 && y == 0 {
886 framework.data.state.get_mut::<Tasks>().unwrap().priority.push(Task::ClearPage); 861 framework
862 .data
863 .state
864 .get_mut::<Tasks>()
865 .unwrap()
866 .priority
867 .push(Task::ClearPage);
887 } 868 }
888 &mut singleplaylistitem.videos_view 869 &mut singleplaylistitem.videos_view
889 } 870 }