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"
150150
151151[[package]]
152152name = "console"
153version = "0.15.3"
153version = "0.15.4"
154154source = "registry+https://github.com/rust-lang/crates.io-index"
155checksum = "5556015fe3aad8b968e5d4124980fbe2f6aaee7aeec6b749de1faaa2ca5d0a4c"
155checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a"
156156dependencies = [
157157 "encode_unicode",
158158 "lazy_static",
@@ -1477,9 +1477,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
14771477
14781478[[package]]
14791479name = "tokio"
1480version = "1.23.0"
1480version = "1.24.0"
14811481source = "registry+https://github.com/rust-lang/crates.io-index"
1482checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46"
1482checksum = "7125661431c26622a80ca5051a2f936c9a678318e0351007b0cc313143024e5c"
14831483dependencies = [
14841484 "autocfg",
14851485 "bytes",
@@ -1943,7 +1943,7 @@ dependencies = [
19431943
19441944[[package]]
19451945name = "youtube-tui"
1946version = "0.6.0"
1946version = "0.6.1"
19471947dependencies = [
19481948 "chrono",
19491949 "clipboard",
Cargo.toml +1 −1
@@ -1,6 +1,6 @@
11[package]
22name = "youtube-tui"
3version = "0.6.0"
3version = "0.6.1"
44authors = ["Siriusmart <siriusmart@tuta.io>"]
55edition = "2021"
66description = "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
1212
1313![](./docs/src/images/search-showcase.png)
1414
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).
1616
1717## Customisable
1818
@@ -21,6 +21,7 @@ The YouTube TUI can be customised through config files, they are located in `~/.
2121Here's an example of the config file:
2222
2323```yaml
24mouse_support: true
2425invidious_instance: https://vid.puffyan.us
2526max_watch_history: 50
2627allow_unicode: false
@@ -32,14 +33,13 @@ env:
3233 video-player: mpv
3334 youtube-downloader: yt-dlp
3435 terminal-emulator: konsole -e
35
3636```
3737
3838Anything from layouts to colours and keybindings can be customised, more on that later.
3939
4040## Dependency-free
4141
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`.
4343
4444However, the programs to launch can be changed, and therefore the YouTube TUI <u>does not rely on any specific dependencies</u> to run.
4545
@@ -61,20 +61,17 @@ It also includes features like:
6161
6262### What it doesn't have
6363
64- Command line args (first priority)
65- Bootleg Vimscript? (will implement)
64- Binding commands to keys (first priority)
6665- Channel search (will implement)
67- Channel videos sorting (will implement)
6866- Subscriptions (will implement)
69- Recommendations/comments (probably will not implement)
7067
7168## How to contribute
7269
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_.
7471
75721. Open an issue to make sure nobody else is working on the same feature
76732. Write code
77743. Open a pull request
78754. Get merged?
7976
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
44
55![](./images/search-showcase.png)
66
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).
88
99## Customisable
1010
@@ -13,6 +13,7 @@ The YouTube TUI can be customised through config files, they are located in `~/.
1313Here's an example of the config file:
1414
1515```yaml
16mouse_support: true
1617invidious_instance: https://vid.puffyan.us
1718max_watch_history: 50
1819allow_unicode: false
@@ -24,14 +25,13 @@ env:
2425 video-player: mpv
2526 youtube-downloader: yt-dlp
2627 terminal-emulator: konsole -e
27
2828```
2929
3030Anything from layouts to colours and keybindings can be customised, more on that later.
3131
3232## Dependency-free
3333
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`.
3535
3636However, the programs to launch can be changed, and therefore the YouTube TUI <u>does not rely on any specific dependencies</u> to run.
3737
@@ -54,18 +54,16 @@ It also includes features like:
5454### What it doesn't have
5555
5656- Binding commands to keys (first priority)
57- Bootleg Vimscript? (first priority)
5857- Channel search (will implement)
59- Channel videos sorting (will implement)
6058- Subscriptions (will implement)
6159
6260## How to contribute
6361
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_.
6563
66641. Open an issue to make sure nobody else is working on the same feature
67652. Write code
68663. Open a pull request
69674. Get merged?
7068
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`)
3838reload configs (alt `reload/r config/configs`)
3939flush
4040quit (alt `q`, `exit`, `x`)
41run [command]
4142```
4243
4344> 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>> {
6363 vec![
6464 HashMap::from([(
6565 String::from("Play video"),
66 String::from("${video-player} ${embed-url}"),
66 String::from("run ${video-player} ${embed-url}"),
6767 )]),
6868 HashMap::from([(
6969 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"),
7171 )]),
7272 HashMap::from([(
7373 String::from("Play audio (loop)"),
7474 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",
7676 ),
7777 )]),
7878 HashMap::from([(
7979 String::from("View channel"),
80 String::from(":channel ${channel-id}"),
80 String::from("channel ${channel-id}"),
8181 )]),
8282 HashMap::from([(
8383 String::from("Open in browser"),
84 String::from("${browser} ${url}"),
84 String::from("run ${browser} ${url}"),
8585 )]),
8686 HashMap::from([(
8787 String::from("Download video (webm)"),
8888 String::from(
89 "${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url}",
89 "run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url}",
9090 ),
9191 )]),
9292 HashMap::from([(
9393 String::from("Download audio (opus)"),
9494 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",
9696 ),
9797 )]),
9898 HashMap::from([(
@@ -107,35 +107,35 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
107107 HashMap::from([(String::from("Switch view"), String::from("%switch-view%"))]),
108108 HashMap::from([(
109109 String::from("Play all videos"),
110 String::from("${video-player} ${all-videos}"),
110 String::from("run ${video-player} ${all-videos}"),
111111 )]),
112112 HashMap::from([(
113113 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"),
115115 )]),
116116 HashMap::from([(
117117 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"),
119119 )]),
120120 HashMap::from([(
121121 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"),
123123 )]),
124124 HashMap::from([(
125125 String::from("View channel"),
126 String::from(":channel ${channel-id}"),
126 String::from("channel ${channel-id}"),
127127 )]),
128128 HashMap::from([(
129129 String::from("Open in browser"),
130 String::from("${browser} ${url}"),
130 String::from("run ${browser} ${url}"),
131131 )]),
132132 HashMap::from([(
133133 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}")
135135 )]),
136136 HashMap::from([(
137137 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")
139139 )]),
140140 HashMap::from([(
141141 String::from("Mode: ${provider}"),
src/global/functions/run_command.rs +10 −1
@@ -237,8 +237,16 @@ pub fn run_command(
237237 ));
238238 false
239239 }
240 ["run"] => {
241 *framework.data.global.get_mut::<Message>().unwrap() =
242 Message::Message(String::from("Usage: run [command]"));
243 false
244 }
240245 ["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);
242250 thread::spawn(move || {
243251 let _ = command.output();
244252 });
@@ -313,6 +321,7 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
313321 \x1b[33mreload configs\x1b[0m Reload all config files
314322 \x1b[33mflush\x1b[0m Run all tasks in queue immediately
315323 \x1b[33mquit\x1b[0m Immediately exit
324 \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run firefox example.com`)
316325
317326\x1b[91mALT:\x1b[0m
318327\x1b[37malts links back to the original command\x1b[30m
src/items/channeldisplay.rs +1 −4
@@ -25,10 +25,7 @@ pub enum ChannelDisplay {
2525 /// a blank item, will turn into one of the other variants when `.load()` depending on the page
2626 None,
2727 /// main channel display page
28 Main {
29 channel: Item,
30 iteminfo: ItemInfo,
31 },
28 Main { channel: Item, iteminfo: ItemInfo },
3229 /// latest videos
3330 Videos {
3431 videos: Vec<Item>,
src/items/singleitem.rs +28 −47
@@ -9,7 +9,6 @@ use crate::{
99 },
1010 },
1111};
12use std::thread;
1312use tui::{
1413 layout::{Constraint, Rect},
1514 style::Style,
@@ -337,10 +336,12 @@ impl SinglePlaylistItem {
337336}
338337
339338impl SingleItemType {
339 /// self is none
340340 pub fn is_none(&self) -> bool {
341341 matches!(self, Self::None)
342342 }
343343
344 /// update colours every render
344345 pub fn update_appearance(
345346 &mut self,
346347 appearance: &AppearanceConfig,
@@ -372,6 +373,7 @@ impl SingleItemType {
372373}
373374
374375impl SingleItem {
376 /// update colours and layout every render
375377 fn update_appearance(
376378 &mut self,
377379 appearance: &AppearanceConfig,
@@ -394,6 +396,7 @@ impl SingleItem {
394396 .update_appearance(appearance, iteminfo, &mut self.grid);
395397 }
396398
399 /// update hover item preview
397400 fn update(&mut self) {
398401 if let SingleItemType::Playlist(singleplaylistitem) = &mut self.r#type {
399402 let SinglePlaylistItem {
@@ -418,6 +421,7 @@ impl SingleItem {
418421 }
419422 }
420423
424 /// handle enter presses
421425 fn select_at_cursor(
422426 &mut self,
423427 framework: &mut FrameworkClean,
@@ -440,31 +444,14 @@ impl SingleItem {
440444 );
441445 }
442446 _ => {
443 // joins the env from the one in mainconfig and video info
444 let command_string = apply_envs(command_string);
445
446447 // check if the command starts with an ':' which case should be captured
447 if &command_string[0..1] == ":" {
448 framework
449 .data
450 .state
451 .get_mut::<Tasks>()
452 .unwrap()
453 .priority
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 });
448 framework
449 .data
450 .state
451 .get_mut::<Tasks>()
452 .unwrap()
453 .priority
454 .push(Task::Command(apply_envs(command_string)));
468455 }
469456 }
470457 }
@@ -491,27 +478,14 @@ impl SingleItem {
491478 }
492479 // same as before if string is not a special case then the run the command
493480 _ => {
494 let command_string = apply_envs(command_string);
495
496481 // check if the command starts with an ':' which case should be captured
497 if &command_string[0..1] == ":" {
498 framework
499 .data
500 .state
501 .get_mut::<Tasks>()
502 .unwrap()
503 .priority
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 });
482 framework
483 .data
484 .state
485 .get_mut::<Tasks>()
486 .unwrap()
487 .priority
488 .push(Task::Command(apply_envs(command_string)));
515489 }
516490 };
517491 }
@@ -762,7 +736,8 @@ impl FrameworkItem for SingleItem {
762736 [singleplaylistitem.videos_view.selected - 1]
763737 .clone(),
764738 );
765 } updated
739 }
740 updated
766741 }
767742 KeyAction::MoveDown => {
768743 let updated = singleplaylistitem.videos_view.down().is_ok();
@@ -883,7 +858,13 @@ impl FrameworkItem for SingleItem {
883858 } else {
884859 let y = (y - chunk.y) as usize + singleplaylistitem.videos_view.scroll;
885860 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);
887868 }
888869 &mut singleplaylistitem.videos_view
889870 }