Commit 183ac39ccb
Unsigned
Layout: unified · split
Cargo.lock +1
| @@ -1546,6 +1546,7 @@ dependencies = [ | |||
| 1546 | "serde_yaml", | 1546 | "serde_yaml", |
| 1547 | "tui-additions", | 1547 | "tui-additions", |
| 1548 | "typemap", | 1548 | "typemap", |
| 1549 | "unicode-segmentation", | ||
| 1549 | "urlencoding", | 1550 | "urlencoding", |
| 1550 | "viuer", | 1551 | "viuer", |
| 1551 | ] | 1552 | ] |
Cargo.toml +1
| @@ -38,6 +38,7 @@ clipboard = {version = "0.5", optional = true} | |||
| 38 | urlencoding = "2.1" | 38 | urlencoding = "2.1" |
| 39 | ratatui = {version = "0.21", default-features = false, features = ["serde"]} | 39 | ratatui = {version = "0.21", default-features = false, features = ["serde"]} |
| 40 | libmpv = { git = "https://github.com/sudipghimire533/libmpv-rs", optional = true } | 40 | libmpv = { git = "https://github.com/sudipghimire533/libmpv-rs", optional = true } |
| 41 | unicode-segmentation = "1" | ||
| 41 | 42 | ||
| 42 | tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} | 43 | tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} |
| 43 | # invidious = {path = "../../Rust/Packages/invidious"} | 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 | KeyCodeSerde::Char('y'), | 175 | KeyCodeSerde::Char('y'), |
| 176 | HashMap::from([(0, String::from("cp ${url}"))]), | 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 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 207 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 184 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 208 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 185 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 219 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 197 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 220 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 198 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 227 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 206 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 228 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 207 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 235 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 215 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 236 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 216 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 243 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 224 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 244 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 225 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 251 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 233 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 252 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 234 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | fn video_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | 257 | fn video_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { |
| 240 | HashMap::from([( | 258 | HashMap::new() |
| 241 | KeyCodeSerde::Char(' '), | ||
| 242 | HashMap::from([(0, String::from("parrun mpv '${embed-url}'"))]), | ||
| 243 | )]) | ||
| 244 | } | 259 | } |
| 245 | 260 | ||
| 246 | fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | 261 | fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { |
| @@ -248,7 +263,6 @@ fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | |||
| 248 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 263 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 249 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 264 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 250 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | KeyCodeSerde::Char('p'), | 281 | KeyCodeSerde::Char('p'), |
| 268 | HashMap::from([(2, String::from("parrun mpv '${hover-video-url}'"))]), | 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 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), | 289 | (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])), |
| 277 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), | 290 | (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])), |
| 278 | (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])), | 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 | HashMap::from([( | 101 | HashMap::from([( |
| 102 | String::from("Play audio"), | 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 | HashMap::from([( | 105 | HashMap::from([( |
| 106 | String::from("Play audio (loop)"), | 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 | HashMap::from([( | 109 | HashMap::from([( |
| 110 | String::from("View channel"), | 110 | String::from("View channel"), |
| @@ -149,11 +149,11 @@ fn saved_video_default() -> Vec<HashMap<String, String>> { | |||
| 149 | )]), | 149 | )]), |
| 150 | HashMap::from([( | 150 | HashMap::from([( |
| 151 | String::from("[Offline] Play saved file (audio)"), | 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 | HashMap::from([( | 154 | HashMap::from([( |
| 155 | String::from("[Offline] Play saved file (audio loop)"), | 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 | HashMap::from([( | 158 | HashMap::from([( |
| 159 | String::from("View channel"), | 159 | String::from("View channel"), |
| @@ -199,11 +199,11 @@ fn playlist_default() -> Vec<HashMap<String, String>> { | |||
| 199 | )]), | 199 | )]), |
| 200 | HashMap::from([( | 200 | HashMap::from([( |
| 201 | String::from("Play all (audio)"), | 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 | HashMap::from([( | 204 | HashMap::from([( |
| 205 | String::from("Shuffle play all (audio loop)"), | 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 | HashMap::from([( | 208 | HashMap::from([( |
| 209 | String::from("View channel"), | 209 | String::from("View channel"), |
| @@ -245,15 +245,15 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> { | |||
| 245 | )]), | 245 | )]), |
| 246 | HashMap::from([( | 246 | HashMap::from([( |
| 247 | String::from("[Offline] Play all (videos)"), | 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 | HashMap::from([( | 250 | HashMap::from([( |
| 251 | String::from("[Offline] Play all (audio)"), | 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 | HashMap::from([( | 254 | HashMap::from([( |
| 255 | String::from("[Offline] Shuffle play all (audio loop)"), | 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 | HashMap::from([( | 258 | HashMap::from([( |
| 259 | String::from("View channel"), | 259 | String::from("View channel"), |
src/config/commands_remap.rs +20
| @@ -42,6 +42,26 @@ impl Default for CommandsRemapConfig { | |||
| 42 | ("x".to_string(), "quit".to_string()), | 42 | ("x".to_string(), "quit".to_string()), |
| 43 | ("exit".to_string(), "quit".to_string()), | 43 | ("exit".to_string(), "quit".to_string()), |
| 44 | ("sub".to_string(), "sync".to_string()), | 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 | key_input(KeyEvent::new(keycode, keymodifier), framework, terminal) | 459 | key_input(KeyEvent::new(keycode, keymodifier), framework, terminal) |
| 460 | } | 460 | } |
| 461 | #[cfg(feature = "mpv")] | 461 | #[cfg(feature = "mpv")] |
| 462 | ["mpv", "property", property] | ["mpv", "prop", property] => { | 462 | ["mpv", "prop", property] => { |
| 463 | let res = framework | 463 | let res = framework |
| 464 | .data | 464 | .data |
| 465 | .global | 465 | .global |
| @@ -468,22 +468,41 @@ pub fn run_single_command( | |||
| 468 | .property(property.to_string()); | 468 | .property(property.to_string()); |
| 469 | 469 | ||
| 470 | *framework.data.global.get_mut::<Message>().unwrap() = match res { | 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 | None => Message::Error("No such property".to_string()), | 472 | None => Message::Error("No such property".to_string()), |
| 473 | }; | 473 | }; |
| 474 | } | 474 | } |
| 475 | #[cfg(feature = "mpv")] | 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 | let res = framework | 495 | let res = framework |
| 478 | .data | 496 | .data |
| 479 | .global | 497 | .global |
| 480 | .get::<MpvWrapper>() | 498 | .get::<MpvWrapper>() |
| 481 | .unwrap() | 499 | .unwrap() |
| 482 | .set_property(name.to_string(), command[3..].join(" ")); | 500 | .set_property(name.to_string(), value.clone()); |
| 483 | 501 | ||
| 484 | *framework.data.global.get_mut::<Message>().unwrap() = match res { | 502 | *framework.data.global.get_mut::<Message>().unwrap() = match res { |
| 485 | MpvResponse::Copy => Message::Mpv("Value set".to_string()), | 503 | // MpvResponse::Copy => Message::Mpv(format!("Set `{name}` to `{value}`")), |
| 486 | MpvResponse::Error(e) => Message::Error(format!("MPV error: {e}")), | 504 | MpvResponse::Copy => return, |
| 505 | MpvResponse::Error(e) => Message::Mpv(format!("MPV error: {e}")), | ||
| 487 | _ => unreachable!(), | 506 | _ => unreachable!(), |
| 488 | }; | 507 | }; |
| 489 | } | 508 | } |
| @@ -495,14 +514,21 @@ pub fn run_single_command( | |||
| 495 | ); | 514 | ); |
| 496 | 515 | ||
| 497 | *framework.data.global.get_mut::<Message>().unwrap() = match res { | 516 | *framework.data.global.get_mut::<Message>().unwrap() = match res { |
| 498 | MpvResponse::Copy => Message::Mpv("MPV player OK.".to_string()), | 517 | // MpvResponse::Copy => Message::Mpv("MPV player OK.".to_string()), |
| 499 | MpvResponse::Error(e) => Message::Error(format!("MPV error: {e}")), | 518 | MpvResponse::Copy => return, |
| 519 | MpvResponse::Error(e) => Message::Mpv(format!("MPV error: {e}")), | ||
| 500 | _ => unreachable!(), | 520 | _ => unreachable!(), |
| 501 | }; | 521 | }; |
| 502 | } | 522 | } |
| 503 | ["echo", ..] => { | 523 | ["echo", r#type, ..] => { |
| 504 | *framework.data.global.get_mut::<Message>().unwrap() = | 524 | *framework.data.global.get_mut::<Message>().unwrap() = match *r#type { |
| 505 | Message::Message(command[1..].join(" ")) | 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 | if let Some(cmd) = framework | 534 | if let Some(cmd) = framework |
| @@ -601,6 +627,12 @@ fn help_msg(cmdefines: &CommandsRemapConfig) -> String { | |||
| 601 | \x1b[33munsub [id or url]\x1b[0m Remove channel from subscription | 627 | \x1b[33munsub [id or url]\x1b[0m Remove channel from subscription |
| 602 | \x1b[33msyncall\x1b[0m Sync all subscriptions | 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 | \x1b[91mCUSTOM COMMANDS:\x1b[0m | 636 | \x1b[91mCUSTOM COMMANDS:\x1b[0m |
| 605 | \x1b[37mdefined in cmdefine.yml\x1b[30m | 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 | use ratatui::{ | 5 | use ratatui::{ |
| 3 | layout::Rect, | 6 | layout::Rect, |
| 4 | style::Style, | 7 | style::Style, |
| @@ -25,20 +28,70 @@ impl FrameworkItem for MessageBar { | |||
| 25 | 28 | ||
| 26 | let mpv = framework.data.global.get::<MpvWrapper>().unwrap(); | 29 | let mpv = framework.data.global.get::<MpvWrapper>().unwrap(); |
| 27 | if Self::is_mpv_render(framework) { | 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 | let duration = mpv | 44 | let duration = mpv |
| 29 | .property("duration".to_string()) | 45 | .property("duration".to_string()) |
| 30 | .unwrap_or_default() | 46 | .unwrap_or_default() |
| 31 | .parse::<f64>() | 47 | .parse::<f64>() |
| 32 | .unwrap() as u64; | 48 | .unwrap() as u64; |
| 49 | let duration_s = secs_display_string(duration as u32); | ||
| 33 | let playerhead = mpv | 50 | let playerhead = mpv |
| 34 | .property("time-pos".to_string()) | 51 | .property("time-pos".to_string()) |
| 35 | .unwrap_or_default() | 52 | .unwrap_or_default() |
| 36 | .parse::<f64>() | 53 | .parse::<f64>() |
| 37 | .unwrap() as u64; | 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 | *framework.data.global.get_mut::<Message>().unwrap() = | 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 | let message = framework.data.global.get::<Message>().unwrap(); | 97 | let message = framework.data.global.get::<Message>().unwrap(); |
src/items/singleitem.rs +1 −1
| @@ -347,7 +347,7 @@ impl SinglePlaylistItem { | |||
| 347 | Ok(entries) => entries | 347 | Ok(entries) => entries |
| 348 | .map(|entry| { | 348 | .map(|entry| { |
| 349 | format!( | 349 | format!( |
| 350 | "mpv loadfile '{}'", | 350 | "mpv loadfile '{}' append", |
| 351 | match entry { | 351 | match entry { |
| 352 | Ok(entry) => | 352 | Ok(entry) => |
| 353 | entry.path().as_os_str().to_str().unwrap().to_string(), | 353 | entry.path().as_os_str().to_str().unwrap().to_string(), |