Commit af1b4fe68d
Unsigned
Layout: unified · split
Cargo.lock +5 −5
| @@ -150,9 +150,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" | ||
| 150 | 150 | |
| 151 | 151 | [[package]] |
| 152 | 152 | name = "console" |
| 153 | version = "0.15.3" | |
| 153 | version = "0.15.4" | |
| 154 | 154 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 155 | checksum = "5556015fe3aad8b968e5d4124980fbe2f6aaee7aeec6b749de1faaa2ca5d0a4c" | |
| 155 | checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a" | |
| 156 | 156 | dependencies = [ |
| 157 | 157 | "encode_unicode", |
| 158 | 158 | "lazy_static", |
| @@ -1477,9 +1477,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" | ||
| 1477 | 1477 | |
| 1478 | 1478 | [[package]] |
| 1479 | 1479 | name = "tokio" |
| 1480 | version = "1.23.0" | |
| 1480 | version = "1.24.0" | |
| 1481 | 1481 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1482 | checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" | |
| 1482 | checksum = "7125661431c26622a80ca5051a2f936c9a678318e0351007b0cc313143024e5c" | |
| 1483 | 1483 | dependencies = [ |
| 1484 | 1484 | "autocfg", |
| 1485 | 1485 | "bytes", |
| @@ -1943,7 +1943,7 @@ dependencies = [ | ||
| 1943 | 1943 | |
| 1944 | 1944 | [[package]] |
| 1945 | 1945 | name = "youtube-tui" |
| 1946 | version = "0.6.0" | |
| 1946 | version = "0.6.1" | |
| 1947 | 1947 | dependencies = [ |
| 1948 | 1948 | "chrono", |
| 1949 | 1949 | "clipboard", |
Cargo.toml +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [package] |
| 2 | 2 | name = "youtube-tui" |
| 3 | version = "0.6.0" | |
| 3 | version = "0.6.1" | |
| 4 | 4 | authors = ["Siriusmart <siriusmart@tuta.io>"] |
| 5 | 5 | edition = "2021" |
| 6 | 6 | description = "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 | 13 |  |
| 14 | 14 | |
| 15 | It is like an *app launcher*, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). | |
| 15 | It is like an _app launcher_, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). | |
| 16 | 16 | |
| 17 | 17 | ## Customisable |
| 18 | 18 | |
| @@ -21,6 +21,7 @@ The YouTube TUI can be customised through config files, they are located in `~/. | ||
| 21 | 21 | Here's an example of the config file: |
| 22 | 22 | |
| 23 | 23 | ```yaml |
| 24 | mouse_support: true | |
| 24 | 25 | invidious_instance: https://vid.puffyan.us |
| 25 | 26 | max_watch_history: 50 |
| 26 | 27 | allow_unicode: false |
| @@ -32,14 +33,13 @@ env: | ||
| 32 | 33 | video-player: mpv |
| 33 | 34 | youtube-downloader: yt-dlp |
| 34 | 35 | terminal-emulator: konsole -e |
| 35 | ||
| 36 | 36 | ``` |
| 37 | 37 | |
| 38 | 38 | Anything from layouts to colours and keybindings can be customised, more on that later. |
| 39 | 39 | |
| 40 | 40 | ## Dependency-free |
| 41 | 41 | |
| 42 | The YouTube TUI does not work on its own, it is instead like a *TUI frontend* for programs like `mpv` or `yt-dlp`/`youtube-dl`. | |
| 42 | The 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 | |
| 44 | 44 | However, 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 | 62 | ### What it doesn't have |
| 63 | 63 | |
| 64 | - Command line args (first priority) | |
| 65 | - Bootleg Vimscript? (will implement) | |
| 64 | - Binding commands to keys (first priority) | |
| 66 | 65 | - Channel search (will implement) |
| 67 | - Channel videos sorting (will implement) | |
| 68 | 66 | - Subscriptions (will implement) |
| 69 | - Recommendations/comments (probably will not implement) | |
| 70 | 67 | |
| 71 | 68 | ## How to contribute |
| 72 | 69 | |
| 73 | You will need a <u>general knowledge</u> of the Rust programming language, and the ability to *understand my spaghetti*. | |
| 70 | You will need a <u>general knowledge</u> of the Rust programming language, and the ability to _understand my spaghetti_. | |
| 74 | 71 | |
| 75 | 72 | 1. Open an issue to make sure nobody else is working on the same feature |
| 76 | 73 | 2. Write code |
| 77 | 74 | 3. Open a pull request |
| 78 | 75 | 4. Get merged? |
| 79 | 76 | |
| 80 | Or just *fix that typo in README* -_- | |
| 77 | Or 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 | 5 |  |
| 6 | 6 | |
| 7 | It is like an *app launcher*, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). | |
| 7 | It is like an _app launcher_, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). | |
| 8 | 8 | |
| 9 | 9 | ## Customisable |
| 10 | 10 | |
| @@ -13,6 +13,7 @@ The YouTube TUI can be customised through config files, they are located in `~/. | ||
| 13 | 13 | Here's an example of the config file: |
| 14 | 14 | |
| 15 | 15 | ```yaml |
| 16 | mouse_support: true | |
| 16 | 17 | invidious_instance: https://vid.puffyan.us |
| 17 | 18 | max_watch_history: 50 |
| 18 | 19 | allow_unicode: false |
| @@ -24,14 +25,13 @@ env: | ||
| 24 | 25 | video-player: mpv |
| 25 | 26 | youtube-downloader: yt-dlp |
| 26 | 27 | terminal-emulator: konsole -e |
| 27 | ||
| 28 | 28 | ``` |
| 29 | 29 | |
| 30 | 30 | Anything from layouts to colours and keybindings can be customised, more on that later. |
| 31 | 31 | |
| 32 | 32 | ## Dependency-free |
| 33 | 33 | |
| 34 | The YouTube TUI does not work on its own, it is instead like a *TUI frontend* for programs like `mpv` or `yt-dlp`/`youtube-dl`. | |
| 34 | The 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 | |
| 36 | 36 | However, 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 | 54 | ### What it doesn't have |
| 55 | 55 | |
| 56 | 56 | - Binding commands to keys (first priority) |
| 57 | - Bootleg Vimscript? (first priority) | |
| 58 | 57 | - Channel search (will implement) |
| 59 | - Channel videos sorting (will implement) | |
| 60 | 58 | - Subscriptions (will implement) |
| 61 | 59 | |
| 62 | 60 | ## How to contribute |
| 63 | 61 | |
| 64 | You will need a <u>general knowledge</u> of the Rust programming language, and the ability to *understand my spaghetti*. | |
| 62 | You will need a <u>general knowledge</u> of the Rust programming language, and the ability to _understand my spaghetti_. | |
| 65 | 63 | |
| 66 | 64 | 1. Open an issue to make sure nobody else is working on the same feature |
| 67 | 65 | 2. Write code |
| 68 | 66 | 3. Open a pull request |
| 69 | 67 | 4. Get merged? |
| 70 | 68 | |
| 71 | Or just *fix that typo in README* -_- | |
| 69 | Or just _fix that typo in README_ -\_- | |
docs/src/commands.md +1
| @@ -38,6 +38,7 @@ reload (alt `r`) | ||
| 38 | 38 | reload configs (alt `reload/r config/configs`) |
| 39 | 39 | flush |
| 40 | 40 | quit (alt `q`, `exit`, `x`) |
| 41 | run [command] | |
| 41 | 42 | ``` |
| 42 | 43 | |
| 43 | 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 | 63 | vec![ |
| 64 | 64 | HashMap::from([( |
| 65 | 65 | String::from("Play video"), |
| 66 | String::from("${video-player} ${embed-url}"), | |
| 66 | String::from("run ${video-player} ${embed-url}"), | |
| 67 | 67 | )]), |
| 68 | 68 | HashMap::from([( |
| 69 | 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 | 72 | HashMap::from([( |
| 73 | 73 | String::from("Play audio (loop)"), |
| 74 | 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 | 78 | HashMap::from([( |
| 79 | 79 | String::from("View channel"), |
| 80 | String::from(":channel ${channel-id}"), | |
| 80 | String::from("channel ${channel-id}"), | |
| 81 | 81 | )]), |
| 82 | 82 | HashMap::from([( |
| 83 | 83 | String::from("Open in browser"), |
| 84 | String::from("${browser} ${url}"), | |
| 84 | String::from("run ${browser} ${url}"), | |
| 85 | 85 | )]), |
| 86 | 86 | HashMap::from([( |
| 87 | 87 | String::from("Download video (webm)"), |
| 88 | 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 | 92 | HashMap::from([( |
| 93 | 93 | String::from("Download audio (opus)"), |
| 94 | 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 | 98 | HashMap::from([( |
| @@ -107,35 +107,35 @@ fn playlist_default() -> Vec<HashMap<String, String>> { | ||
| 107 | 107 | HashMap::from([(String::from("Switch view"), String::from("%switch-view%"))]), |
| 108 | 108 | HashMap::from([( |
| 109 | 109 | String::from("Play all videos"), |
| 110 | String::from("${video-player} ${all-videos}"), | |
| 110 | String::from("run ${video-player} ${all-videos}"), | |
| 111 | 111 | )]), |
| 112 | 112 | HashMap::from([( |
| 113 | 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 | 116 | HashMap::from([( |
| 117 | 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 | 120 | HashMap::from([( |
| 121 | 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 | 124 | HashMap::from([( |
| 125 | 125 | String::from("View channel"), |
| 126 | String::from(":channel ${channel-id}"), | |
| 126 | String::from("channel ${channel-id}"), | |
| 127 | 127 | )]), |
| 128 | 128 | HashMap::from([( |
| 129 | 129 | String::from("Open in browser"), |
| 130 | String::from("${browser} ${url}"), | |
| 130 | String::from("run ${browser} ${url}"), | |
| 131 | 131 | )]), |
| 132 | 132 | HashMap::from([( |
| 133 | 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 | 136 | HashMap::from([( |
| 137 | 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 | 140 | HashMap::from([( |
| 141 | 141 | String::from("Mode: ${provider}"), |
src/global/functions/run_command.rs +10 −1
| @@ -237,8 +237,16 @@ pub fn run_command( | ||
| 237 | 237 | )); |
| 238 | 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 | 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 | 250 | thread::spawn(move || { |
| 243 | 251 | let _ = command.output(); |
| 244 | 252 | }); |
| @@ -313,6 +321,7 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m | ||
| 313 | 321 | \x1b[33mreload configs\x1b[0m Reload all config files |
| 314 | 322 | \x1b[33mflush\x1b[0m Run all tasks in queue immediately |
| 315 | 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 | 326 | \x1b[91mALT:\x1b[0m |
| 318 | 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 | 25 | /// a blank item, will turn into one of the other variants when `.load()` depending on the page |
| 26 | 26 | None, |
| 27 | 27 | /// main channel display page |
| 28 | Main { | |
| 29 | channel: Item, | |
| 30 | iteminfo: ItemInfo, | |
| 31 | }, | |
| 28 | Main { channel: Item, iteminfo: ItemInfo }, | |
| 32 | 29 | /// latest videos |
| 33 | 30 | Videos { |
| 34 | 31 | videos: Vec<Item>, |
src/items/singleitem.rs +28 −47
| @@ -9,7 +9,6 @@ use crate::{ | ||
| 9 | 9 | }, |
| 10 | 10 | }, |
| 11 | 11 | }; |
| 12 | use std::thread; | |
| 13 | 12 | use tui::{ |
| 14 | 13 | layout::{Constraint, Rect}, |
| 15 | 14 | style::Style, |
| @@ -337,10 +336,12 @@ impl SinglePlaylistItem { | ||
| 337 | 336 | } |
| 338 | 337 | |
| 339 | 338 | impl SingleItemType { |
| 339 | /// self is none | |
| 340 | 340 | pub fn is_none(&self) -> bool { |
| 341 | 341 | matches!(self, Self::None) |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | /// update colours every render | |
| 344 | 345 | pub fn update_appearance( |
| 345 | 346 | &mut self, |
| 346 | 347 | appearance: &AppearanceConfig, |
| @@ -372,6 +373,7 @@ impl SingleItemType { | ||
| 372 | 373 | } |
| 373 | 374 | |
| 374 | 375 | impl SingleItem { |
| 376 | /// update colours and layout every render | |
| 375 | 377 | fn update_appearance( |
| 376 | 378 | &mut self, |
| 377 | 379 | appearance: &AppearanceConfig, |
| @@ -394,6 +396,7 @@ impl SingleItem { | ||
| 394 | 396 | .update_appearance(appearance, iteminfo, &mut self.grid); |
| 395 | 397 | } |
| 396 | 398 | |
| 399 | /// update hover item preview | |
| 397 | 400 | fn update(&mut self) { |
| 398 | 401 | if let SingleItemType::Playlist(singleplaylistitem) = &mut self.r#type { |
| 399 | 402 | let SinglePlaylistItem { |
| @@ -418,6 +421,7 @@ impl SingleItem { | ||
| 418 | 421 | } |
| 419 | 422 | } |
| 420 | 423 | |
| 424 | /// handle enter presses | |
| 421 | 425 | fn select_at_cursor( |
| 422 | 426 | &mut self, |
| 423 | 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 | 447 | // 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))); | |
| 468 | 455 | } |
| 469 | 456 | } |
| 470 | 457 | } |
| @@ -491,27 +478,14 @@ impl SingleItem { | ||
| 491 | 478 | } |
| 492 | 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 | 481 | // 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))); | |
| 515 | 489 | } |
| 516 | 490 | }; |
| 517 | 491 | } |
| @@ -762,7 +736,8 @@ impl FrameworkItem for SingleItem { | ||
| 762 | 736 | [singleplaylistitem.videos_view.selected - 1] |
| 763 | 737 | .clone(), |
| 764 | 738 | ); |
| 765 | } updated | |
| 739 | } | |
| 740 | updated | |
| 766 | 741 | } |
| 767 | 742 | KeyAction::MoveDown => { |
| 768 | 743 | let updated = singleplaylistitem.videos_view.down().is_ok(); |
| @@ -883,7 +858,13 @@ impl FrameworkItem for SingleItem { | ||
| 883 | 858 | } else { |
| 884 | 859 | let y = (y - chunk.y) as usize + singleplaylistitem.videos_view.scroll; |
| 885 | 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 | 869 | &mut singleplaylistitem.videos_view |
| 889 | 870 | } |