From e93d79f28d7c988cad4ee2491dca2a700028b3ce Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Fri, 7 Jan 2022 13:22:22 -0500 Subject: [PATCH] Ignore unsupported file extensions in files by default and make OS media controls sort of optional --- Cargo.toml | 8 ++++- mps-interpreter/src/processing/filesystem.rs | 2 +- mps-player/Cargo.toml | 17 +++++++-- mps-player/src/os_controls.rs | 37 +++++++++++++------- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7a5e83b..beae4d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,12 @@ members = [ [dependencies] # local mps-interpreter = { version = "0.2.0", path = "./mps-interpreter" } -mps-player = { version = "0.2.0", path = "./mps-player" } # external clap = { version = "3.0", features = ["derive"] } + +[target.'cfg(not(target_os = "linux"))'.dependencies] +mps-player = { version = "0.2.0", path = "./mps-player", default-features = false } + +[target.'cfg(target_os = "linux")'.dependencies] +# TODO fix need to specify OS-specific dependency of mps-player +mps-player = { version = "0.2.0", path = "./mps-player", features = ["mpris-player"] } diff --git a/mps-interpreter/src/processing/filesystem.rs b/mps-interpreter/src/processing/filesystem.rs index e89398c..c561011 100644 --- a/mps-interpreter/src/processing/filesystem.rs +++ b/mps-interpreter/src/processing/filesystem.rs @@ -9,7 +9,7 @@ use super::OpGetter; use crate::lang::RuntimeError; use crate::MpsMusicItem; -const DEFAULT_REGEX: &str = r"/(?P[^/]+)/(?P[^/]+)/(?:(?:(?P\d+)\s+)?(?P\d+)\.?\s+)?(?P[^/]+)\.[a-zA-Z0-9]+$"; +const DEFAULT_REGEX: &str = r"/(?P<artist>[^/]+)/(?P<album>[^/]+)/(?:(?:(?P<disc>\d+)\s+)?(?P<track>\d+)\.?\s+)?(?P<title>[^/]+)\.(?P<format>(?:mp3)|(?:wav)|(?:ogg)|(?:flac)|(?:mp4)|(?:aac))$"; const DEFAULT_VEC_CACHE_SIZE: usize = 4; diff --git a/mps-player/Cargo.toml b/mps-player/Cargo.toml index 588054c..2a2bc78 100644 --- a/mps-player/Cargo.toml +++ b/mps-player/Cargo.toml @@ -12,6 +12,19 @@ m3u8-rs = { version = "^3.0.0" } # local mps-interpreter = { path = "../mps-interpreter", version = "0.2.0" } -[target.'cfg(unix)'.dependencies] +[target.'cfg(target_os = "linux")'.dependencies] #dbus = { version = "^0.9" } -mpris-player = { version = "^0.6.1", path = "../mpris-player" } +mpris-player = { version = "^0.6.1", path = "../mpris-player", optional = true } + +[features] +default = ["os-controls"] +os-controls = [] + +# I wish this worked... +#[target.'cfg(not(target_os = "linux"))'.features] +#default = ["os-controls"] +#os-controls = [] + +#[target.'cfg(target_os = "linux")'.features] +#default = ["os-controls"] +#os-controls = ["mpris-player"] diff --git a/mps-player/src/os_controls.rs b/mps-player/src/os_controls.rs index 7de77fb..74bcbc2 100644 --- a/mps-player/src/os_controls.rs +++ b/mps-player/src/os_controls.rs @@ -1,11 +1,12 @@ -#[cfg(unix)] +#[allow(unused_imports)] use std::sync::mpsc::{channel, Sender, Receiver}; -#[cfg(unix)] +#[cfg(all(target_os = "linux", feature = "os-controls"))] use std::thread::JoinHandle; -#[cfg(unix)] +#[cfg(all(target_os = "linux", feature = "os-controls"))] use mpris_player::{MprisPlayer, PlaybackStatus, Metadata}; +#[cfg(all(target_os = "linux", feature = "os-controls"))] use mps_interpreter::MpsMusicItem; //use super::MpsController; @@ -13,25 +14,32 @@ use super::player_wrapper::{ControlAction, PlaybackAction}; /// OS-specific APIs for media controls. /// Currently only Linux (dbus) is supported. +#[cfg(all(target_os = "linux", feature = "os-controls"))] pub struct SystemControlWrapper { control: Sender<ControlAction>, - #[cfg(target_os = "linux")] dbus_handle: Option<JoinHandle<()>>, //std::sync::Arc<MprisPlayer>, - #[cfg(target_os = "linux")] dbus_ctrl: Option<Sender<DbusControl>>, - #[cfg(target_os = "linux")] playback_event_handler: Option<JoinHandle<()>>, - #[cfg(target_os = "linux")] playback_event_handler_killer: Option<Sender<()>>, + } -#[cfg(target_os = "linux")] +/// OS-specific APIs for media controls. +/// Currently only Linux (dbus) is supported. +#[cfg(not(feature = "os-controls"))] +pub struct SystemControlWrapper { + #[allow(dead_code)] + control: Sender<ControlAction>, + playback_receiver: Option<Receiver<PlaybackAction>>, +} + +#[cfg(all(target_os = "linux", feature = "os-controls"))] enum DbusControl { Die, SetMetadata(Metadata), } -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", feature = "os-controls"))] impl SystemControlWrapper { pub fn new(control: Sender<ControlAction>) -> Self { Self { @@ -203,13 +211,18 @@ impl SystemControlWrapper { } } -#[cfg(not(any(target_os = "linux")))] +#[cfg(not(feature = "os-controls"))] impl SystemControlWrapper { pub fn new(control: Sender<ControlAction>) -> Self { - Self { control: control } + Self { + control: control, + playback_receiver: None + } } - pub fn init(&mut self, _playback: Receiver<PlaybackAction>) {} + pub fn init(&mut self, playback: Receiver<PlaybackAction>) { + self.playback_receiver = Some(playback); + } pub fn exit(self) {} }