Commit 183ac39ccb
Unsigned
Layout: unified · split
Cargo.lock +1
| @@ -1546,6 +1546,7 @@ dependencies = [ | ||
| 1546 | 1546 | "serde_yaml", |
| 1547 | 1547 | "tui-additions", |
| 1548 | 1548 | "typemap", |
| 1549 | "unicode-segmentation", | |
| 1549 | 1550 | "urlencoding", |
| 1550 | 1551 | "viuer", |
| 1551 | 1552 | ] |
Cargo.toml +1
| @@ -38,6 +38,7 @@ clipboard = {version = "0.5", optional = true} | ||
| 38 | 38 | urlencoding = "2.1" |
| 39 | 39 | ratatui = {version = "0.21", default-features = false, features = ["serde"]} |
| 40 | 40 | libmpv = { git = "https://github.com/sudipghimire533/libmpv-rs", optional = true } |
| 41 | unicode-segmentation = "1" | |
| 41 | 42 | |
| 42 | 43 | tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} |
| 43 | 44 | # invidious = {path = "../../Rust/Packages/invidious"} |
src/config/commandbindings.rs +25 −13
| @@ -175,6 +175,30 @@ fn global_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 175 | 175 | KeyCodeSerde::Char('y'), |
| 176 | 176 | HashMap::from([(0, String::from("cp ${url}"))]), |
| 177 | 177 | ), |
| 178 | ( | |
| 179 | KeyCodeSerde::Char(' '), | |
| 180 | HashMap::from([(0, String::from("tpause ;; echo mpv Player paused toggled"))]), | |
| 181 | ), | |
| 182 | ( | |
| 183 | KeyCodeSerde::KeyVariants(super::serde::KeyVariantsSerde::Left), | |
| 184 | HashMap::from([ | |
| 185 | ( | |
| 186 | 2, | |
| 187 | String::from("mpv seek -5 ;; echo mpv Reversed 5 seconds"), | |
| 188 | ), | |
| 189 | (3, String::from("back ;; echo mpv Unskipped")), | |
| 190 | ]), | |
| 191 | ), | |
| 192 | ( | |
| 193 | KeyCodeSerde::KeyVariants(super::serde::KeyVariantsSerde::Right), | |
| 194 | HashMap::from([ | |
| 195 | ( | |
| 196 | 2, | |
| 197 | String::from("mpv seek 5 ;; echo mpv Fast forwarded 5 seconds"), | |
| 198 | ), | |
| 199 | (3, String::from("next ;; echo mpv Skipped")), | |
| 200 | ]), | |
| 201 | ), | |
| 178 | 202 | ]) |
| 179 | 203 | } |
| 180 | 204 | |
| @@ -183,7 +207,6 @@ fn search_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 183 | 207 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 184 | 208 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 185 | 209 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 186 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 187 | 210 | ]) |
| 188 | 211 | } |
| 189 | 212 | |
| @@ -196,7 +219,6 @@ fn channel_playlists_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 196 | 219 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 197 | 220 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 198 | 221 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 199 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 200 | 222 | ]) |
| 201 | 223 | } |
| 202 | 224 | |
| @@ -205,7 +227,6 @@ fn channel_videos_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 205 | 227 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 206 | 228 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 207 | 229 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 208 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 209 | 230 | ]) |
| 210 | 231 | } |
| 211 | 232 | |
| @@ -214,7 +235,6 @@ fn playlist_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 214 | 235 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 215 | 236 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 216 | 237 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 217 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 218 | 238 | ]) |
| 219 | 239 | } |
| 220 | 240 | |
| @@ -223,7 +243,6 @@ fn popular_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 223 | 243 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 224 | 244 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 225 | 245 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 226 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 227 | 246 | ]) |
| 228 | 247 | } |
| 229 | 248 | |
| @@ -232,15 +251,11 @@ fn trending_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 232 | 251 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 233 | 252 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 234 | 253 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 235 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 236 | 254 | ]) |
| 237 | 255 | } |
| 238 | 256 | |
| 239 | 257 | fn video_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { |
| 240 | HashMap::from([( | |
| 241 | KeyCodeSerde::Char(' '), | |
| 242 | HashMap::from([(0, String::from("parrun mpv '${embed-url}'"))]), | |
| 243 | )]) | |
| 258 | HashMap::new() | |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { |
| @@ -248,7 +263,6 @@ fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 248 | 263 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 249 | 264 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 250 | 265 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 251 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 252 | 266 | ]) |
| 253 | 267 | } |
| 254 | 268 | |
| @@ -267,7 +281,6 @@ fn feed_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 267 | 281 | KeyCodeSerde::Char('p'), |
| 268 | 282 | HashMap::from([(2, String::from("parrun mpv '${hover-video-url}'"))]), |
| 269 | 283 | ), |
| 270 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 271 | 284 | ]) |
| 272 | 285 | } |
| 273 | 286 | |
| @@ -276,6 +289,5 @@ fn library_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 276 | 289 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 277 | 290 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 278 | 291 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), |
| 279 | (KeyCodeSerde::Char(' '), HashMap::from([(0, String::from("parrun mpv '${hover-url}'"))])), | |
| 280 | 292 | ]) |
| 281 | 293 | } |
src/config/commands.rs +9 −9
| @@ -100,11 +100,11 @@ fn video_default() -> Vec<HashMap<String, String>> { | ||
| 100 | 100 | )]), |
| 101 | 101 | HashMap::from([( |
| 102 | 102 | String::from("Play audio"), |
| 103 | String::from("mpv sprop loop no ;; mpv loadfile '${embed-url}'"), | |
| 103 | String::from("mpv stop ;; resume ;; mpv sprop loop no ;; mpv loadfile '${embed-url}'"), | |
| 104 | 104 | )]), |
| 105 | 105 | HashMap::from([( |
| 106 | 106 | String::from("Play audio (loop)"), |
| 107 | String::from("mpv sprop loop inf ;; mpv loadfile '${embed-url}'"), | |
| 107 | String::from("mpv stop ;; resume ;; mpv sprop loop inf ;; mpv loadfile '${embed-url}'"), | |
| 108 | 108 | )]), |
| 109 | 109 | HashMap::from([( |
| 110 | 110 | String::from("View channel"), |
| @@ -149,11 +149,11 @@ fn saved_video_default() -> Vec<HashMap<String, String>> { | ||
| 149 | 149 | )]), |
| 150 | 150 | HashMap::from([( |
| 151 | 151 | String::from("[Offline] Play saved file (audio)"), |
| 152 | String::from("mpv sprop loop no ;; mpv loadfile '${offline-path}'"), | |
| 152 | String::from("mpv stop ;; resume ;; mpv sprop loop no ;; mpv loadfile '${offline-path}'"), | |
| 153 | 153 | )]), |
| 154 | 154 | HashMap::from([( |
| 155 | 155 | String::from("[Offline] Play saved file (audio loop)"), |
| 156 | String::from("mpv sprop loop inf ;; mpv loadfile '${offline-path}'"), | |
| 156 | String::from("mpv stop ;; resume ;; mpv sprop loop inf ;; mpv loadfile '${offline-path}'"), | |
| 157 | 157 | )]), |
| 158 | 158 | HashMap::from([( |
| 159 | 159 | String::from("View channel"), |
| @@ -199,11 +199,11 @@ fn playlist_default() -> Vec<HashMap<String, String>> { | ||
| 199 | 199 | )]), |
| 200 | 200 | HashMap::from([( |
| 201 | 201 | String::from("Play all (audio)"), |
| 202 | String::from("mpv stop ;; ${mpv-queuelist} ;; mpv playlist-play-index 0"), | |
| 202 | String::from("mpv stop ;; resume ;; ${mpv-queuelist} ;; mpv playlist-play-index 0"), | |
| 203 | 203 | )]), |
| 204 | 204 | HashMap::from([( |
| 205 | 205 | String::from("Shuffle play all (audio loop)"), |
| 206 | String::from("mpv stop ;; ${mpv-queuelist} ;; mpv playlist-shuffle ;; mpv playlist-play-index 0"), | |
| 206 | String::from("mpv stop ;; resume ;; ${mpv-queuelist} ;; mpv playlist-shuffle ;; mpv playlist-play-index 0"), | |
| 207 | 207 | )]), |
| 208 | 208 | HashMap::from([( |
| 209 | 209 | String::from("View channel"), |
| @@ -245,15 +245,15 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> { | ||
| 245 | 245 | )]), |
| 246 | 246 | HashMap::from([( |
| 247 | 247 | String::from("[Offline] Play all (videos)"), |
| 248 | String::from("parrun ${terminal-emulator} bash -c '${video-player} ${save-path}*${id}*/* --force-window'"), | |
| 248 | String::from("parrun ${video-player} ${save-path}*${id}*/* --force-window"), | |
| 249 | 249 | )]), |
| 250 | 250 | HashMap::from([( |
| 251 | 251 | String::from("[Offline] Play all (audio)"), |
| 252 | String::from("mpv stop ;; ${offline-queuelist} ;; mpv playlist-play-index 0"), | |
| 252 | String::from("mpv stop ;; resume ;; ${offline-queuelist} ;; mpv playlist-play-index 0"), | |
| 253 | 253 | )]), |
| 254 | 254 | HashMap::from([( |
| 255 | 255 | String::from("[Offline] Shuffle play all (audio loop)"), |
| 256 | String::from("mpv stop ;; ${offline-queuelist} ;; mpv playlist-shuffle ;; mpv playlist-play-index 0"), | |
| 256 | String::from("mpv stop ;; resume ;; ${offline-queuelist} ;; mpv playlist-shuffle ;; mpv playlist-play-index 0"), | |
| 257 | 257 | )]), |
| 258 | 258 | HashMap::from([( |
| 259 | 259 | String::from("View channel"), |
src/config/commands_remap.rs +20
| @@ -42,6 +42,26 @@ impl Default for CommandsRemapConfig { | ||
| 42 | 42 | ("x".to_string(), "quit".to_string()), |
| 43 | 43 | ("exit".to_string(), "quit".to_string()), |
| 44 | 44 | ("sub".to_string(), "sync".to_string()), |
| 45 | ( | |
| 46 | "tpause".to_string(), | |
| 47 | "mpv tprop pause ;; echo success Toggled player pause".to_string(), | |
| 48 | ), | |
| 49 | ( | |
| 50 | "pause".to_string(), | |
| 51 | "mpv sprop pause yes ;; echo mpv Player paused".to_string(), | |
| 52 | ), | |
| 53 | ( | |
| 54 | "resume".to_string(), | |
| 55 | "mpv sprop pause no ;; echo mpv Player resumed".to_string(), | |
| 56 | ), | |
| 57 | ( | |
| 58 | "back".to_string(), | |
| 59 | "mpv playlist-previous ;; echo mpv Skipped".to_string(), | |
| 60 | ), | |
| 61 | ( | |
| 62 | "next".to_string(), | |
| 63 | "mpv playlist-next ;; echo mpv Skipped".to_string(), | |
| 64 | ), | |
| 45 | 65 | ])) |
| 46 | 66 | } |
| 47 | 67 | } |
src/global/functions/run_command.rs +43 −11
| @@ -459,7 +459,7 @@ pub fn run_single_command( | ||
| 459 | 459 | key_input(KeyEvent::new(keycode, keymodifier), framework, terminal) |
| 460 | 460 | } |
| 461 | 461 | #[cfg(feature = "mpv")] |
| 462 | ["mpv", "property", property] | ["mpv", "prop", property] => { | |
| 462 | ["mpv", "prop", property] => { | |
| 463 | 463 | let res = framework |
| 464 | 464 | .data |
| 465 | 465 | .global |
| @@ -468,22 +468,41 @@ pub fn run_single_command( | ||
| 468 | 468 | .property(property.to_string()); |
| 469 | 469 | |
| 470 | 470 | *framework.data.global.get_mut::<Message>().unwrap() = match res { |
| 471 | Some(value) => Message::Message(format!("Value: {value}")), | |
| 471 | Some(value) => Message::Message(format!("Value: `{value}`")), | |
| 472 | 472 | None => Message::Error("No such property".to_string()), |
| 473 | 473 | }; |
| 474 | 474 | } |
| 475 | 475 | #[cfg(feature = "mpv")] |
| 476 | ["mpv", "set_property", name, ..] | ["mpv", "sprop", name, ..] => { | |
| 476 | ["mpv", "tprop", property] => { | |
| 477 | let mpv = framework.data.global.get::<MpvWrapper>().unwrap(); | |
| 478 | let res = mpv.property(property.to_string()); | |
| 479 | ||
| 480 | let toset = match res { | |
| 481 | Some(value) if value.as_str() == "yes" || value.as_str() == "true" => "no", | |
| 482 | _ => "yes", | |
| 483 | }; | |
| 484 | ||
| 485 | let res = mpv.set_property(property.to_string(), toset.to_string()); | |
| 486 | *framework.data.global.get_mut::<Message>().unwrap() = match res { | |
| 487 | MpvResponse::Copy => Message::Mpv(format!("Set `{property}` to `{toset}`")), | |
| 488 | MpvResponse::Error(e) => Message::Error(format!("MPV error: {e}")), | |
| 489 | _ => unreachable!(), | |
| 490 | }; | |
| 491 | } | |
| 492 | #[cfg(feature = "mpv")] | |
| 493 | ["mpv", "sprop", name, ..] => { | |
| 494 | let value = command[3..].join(" "); | |
| 477 | 495 | let res = framework |
| 478 | 496 | .data |
| 479 | 497 | .global |
| 480 | 498 | .get::<MpvWrapper>() |
| 481 | 499 | .unwrap() |
| 482 | .set_property(name.to_string(), command[3..].join(" ")); | |
| 500 | .set_property(name.to_string(), value.clone()); | |
| 483 | 501 | |
| 484 | 502 | *framework.data.global.get_mut::<Message>().unwrap() = match res { |
| 485 | MpvResponse::Copy => Message::Mpv("Value set".to_string()), | |
| 486 | MpvResponse::Error(e) => Message::Error(format!("MPV error: {e}")), | |
| 503 | // MpvResponse::Copy => Message::Mpv(format!("Set `{name}` to `{value}`")), | |
| 504 | MpvResponse::Copy => return, | |
| 505 | MpvResponse::Error(e) => Message::Mpv(format!("MPV error: {e}")), | |
| 487 | 506 | _ => unreachable!(), |
| 488 | 507 | }; |
| 489 | 508 | } |
| @@ -495,14 +514,21 @@ pub fn run_single_command( | ||
| 495 | 514 | ); |
| 496 | 515 | |
| 497 | 516 | *framework.data.global.get_mut::<Message>().unwrap() = match res { |
| 498 | MpvResponse::Copy => Message::Mpv("MPV player OK.".to_string()), | |
| 499 | MpvResponse::Error(e) => Message::Error(format!("MPV error: {e}")), | |
| 517 | // MpvResponse::Copy => Message::Mpv("MPV player OK.".to_string()), | |
| 518 | MpvResponse::Copy => return, | |
| 519 | MpvResponse::Error(e) => Message::Mpv(format!("MPV error: {e}")), | |
| 500 | 520 | _ => unreachable!(), |
| 501 | 521 | }; |
| 502 | 522 | } |
| 503 | ["echo", ..] => { | |
| 504 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 505 | Message::Message(command[1..].join(" ")) | |
| 523 | ["echo", r#type, ..] => { | |
| 524 | *framework.data.global.get_mut::<Message>().unwrap() = match *r#type { | |
| 525 | "message" => Message::Message(command[2..].join(" ")), | |
| 526 | "mpv" => Message::Mpv(command[2..].join(" ")), | |
| 527 | "success" => Message::Success(command[2..].join(" ")), | |
| 528 | "error" => Message::Error(command[2..].join(" ")), | |
| 529 | "none" => Message::None, | |
| 530 | _ => Message::Error(format!("Unknown type `{}`", r#type)), | |
| 531 | } | |
| 506 | 532 | } |
| 507 | 533 | _ => { |
| 508 | 534 | if let Some(cmd) = framework |
| @@ -601,6 +627,12 @@ fn help_msg(cmdefines: &CommandsRemapConfig) -> String { | ||
| 601 | 627 | \x1b[33munsub [id or url]\x1b[0m Remove channel from subscription |
| 602 | 628 | \x1b[33msyncall\x1b[0m Sync all subscriptions |
| 603 | 629 | |
| 630 | \x1b[91mMPV:\x1b[0m | |
| 631 | \x1b[33mmpv prop [label]\x1b[0m Gets mpv property | |
| 632 | \x1b[33mmpv sprop [label] [value]\x1b[0m Set mpv property | |
| 633 | \x1b[33mmpv tprop [label] [value]\x1b[0m Toggle a yes/no property | |
| 634 | \x1b[33mmpv [command]\x1b[0m Runs a libmpv command | |
| 635 | ||
| 604 | 636 | \x1b[91mCUSTOM COMMANDS:\x1b[0m |
| 605 | 637 | \x1b[37mdefined in cmdefine.yml\x1b[30m |
| 606 | 638 | {} |
src/items/messagebar.rs +56 −3
| @@ -1,4 +1,7 @@ | ||
| 1 | use crate::{config::*, global::structs::*}; | |
| 1 | use crate::{ | |
| 2 | config::*, | |
| 3 | global::{functions::secs_display_string, structs::*}, | |
| 4 | }; | |
| 2 | 5 | use ratatui::{ |
| 3 | 6 | layout::Rect, |
| 4 | 7 | style::Style, |
| @@ -25,20 +28,70 @@ impl FrameworkItem for MessageBar { | ||
| 25 | 28 | |
| 26 | 29 | let mpv = framework.data.global.get::<MpvWrapper>().unwrap(); |
| 27 | 30 | if Self::is_mpv_render(framework) { |
| 31 | let mut label = mpv.property("media-title".to_string()).unwrap(); | |
| 32 | if let Some((name, ext)) = label.rsplit_once('.') { | |
| 33 | if ext.len() < 5 | |
| 34 | && !name.len() > 13 | |
| 35 | && &name[name.len() - 1..name.len()] == "]" | |
| 36 | && name[name.len() - 12..name.len() - 1] | |
| 37 | .chars() | |
| 38 | .all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_')) | |
| 39 | && &name[name.len() - 13..name.len() - 12] == "[" | |
| 40 | { | |
| 41 | label = name[0..name.len() - 13].to_string(); | |
| 42 | } | |
| 43 | } | |
| 28 | 44 | let duration = mpv |
| 29 | 45 | .property("duration".to_string()) |
| 30 | 46 | .unwrap_or_default() |
| 31 | 47 | .parse::<f64>() |
| 32 | 48 | .unwrap() as u64; |
| 49 | let duration_s = secs_display_string(duration as u32); | |
| 33 | 50 | let playerhead = mpv |
| 34 | 51 | .property("time-pos".to_string()) |
| 35 | 52 | .unwrap_or_default() |
| 36 | 53 | .parse::<f64>() |
| 37 | 54 | .unwrap() as u64; |
| 38 | let percentage = playerhead * 100 / duration; | |
| 55 | let mut playerhead_s = secs_display_string(playerhead as u32); | |
| 56 | if playerhead_s.len() != duration_s.len() { | |
| 57 | playerhead_s = format!( | |
| 58 | "{}{playerhead_s}", | |
| 59 | " ".repeat(duration_s.len() - playerhead_s.len()) | |
| 60 | ); | |
| 61 | } | |
| 62 | let percentage = (playerhead * 100 / duration).to_string(); | |
| 63 | ||
| 64 | let right_chunk = format!( | |
| 65 | "{playerhead_s}/{duration_s} {}[{percentage}%]", | |
| 66 | " ".repeat(3 - percentage.len()) | |
| 67 | ); | |
| 68 | let left_chunk = format!("[Now Playing]: {label}"); | |
| 69 | let length = area.width as usize - 2; | |
| 70 | let total_len = right_chunk.len() + left_chunk.len(); | |
| 39 | 71 | |
| 40 | 72 | *framework.data.global.get_mut::<Message>().unwrap() = |
| 41 | Message::Mpv(format!("{playerhead}/{duration} [{percentage}%]")); | |
| 73 | Message::Mpv(if length > total_len + 6 { | |
| 74 | let mut seeker_len = length - total_len - 4; | |
| 75 | let seeker_pad = if seeker_len > 10 { seeker_len / 10 } else { 0 }; | |
| 76 | seeker_len -= seeker_pad * 2; | |
| 77 | let seeker_pos = seeker_len * playerhead as usize / duration as usize; | |
| 78 | format!( | |
| 79 | "{left_chunk} {}├{}-{}┤{} {right_chunk}", | |
| 80 | " ".repeat(seeker_pad), | |
| 81 | "─".repeat(seeker_pos), | |
| 82 | "─".repeat(seeker_len - seeker_pos - 1), | |
| 83 | " ".repeat(seeker_pad) | |
| 84 | ) | |
| 85 | } else if length > total_len + 3 { | |
| 86 | format!( | |
| 87 | "{left_chunk}{}{right_chunk}", | |
| 88 | " ".repeat(length - total_len) | |
| 89 | ) | |
| 90 | } else if length > 19 { | |
| 91 | left_chunk | |
| 92 | } else { | |
| 93 | String::from("Not enough width") | |
| 94 | }); | |
| 42 | 95 | } |
| 43 | 96 | |
| 44 | 97 | let message = framework.data.global.get::<Message>().unwrap(); |
src/items/singleitem.rs +1 −1
| @@ -347,7 +347,7 @@ impl SinglePlaylistItem { | ||
| 347 | 347 | Ok(entries) => entries |
| 348 | 348 | .map(|entry| { |
| 349 | 349 | format!( |
| 350 | "mpv loadfile '{}'", | |
| 350 | "mpv loadfile '{}' append", | |
| 351 | 351 | match entry { |
| 352 | 352 | Ok(entry) => |
| 353 | 353 | entry.path().as_os_str().to_str().unwrap().to_string(), |