From f53deb9b877126b956a5e233fb743b639232232b Mon Sep 17 00:00:00 2001 From: Icelk Date: Wed, 8 Mar 2023 17:32:38 +0100 Subject: [PATCH] Upgrade librespot to 0.4 --- Cargo.lock | 320 +++++++++++++++++++++++++++------------------- Cargo.toml | 9 +- src/alsa_mixer.rs | 13 +- src/config.rs | 18 ++- src/dbus_mpris.rs | 4 +- src/main_loop.rs | 30 +++-- src/no_mixer.rs | 14 +- src/process.rs | 22 ++-- src/setup.rs | 59 ++++----- 9 files changed, 261 insertions(+), 228 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f20c0c49..51bec7b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,18 +81,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "alsa" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75c4da790adcb2ce5e758c064b4f3ec17a30349f9961d3e5e6c9688b052a9e18" -dependencies = [ - "alsa-sys", - "bitflags", - "libc", - "nix 0.20.0", -] - [[package]] name = "alsa" version = "0.6.0" @@ -612,7 +600,7 @@ dependencies = [ "ndk-glue", "nix 0.23.2", "oboe", - "parking_lot", + "parking_lot 0.11.2", "stdweb", "thiserror", "web-sys", @@ -949,6 +937,12 @@ dependencies = [ "syslog", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "fnv" version = "1.0.7" @@ -1068,12 +1062,6 @@ dependencies = [ "slab", ] -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - [[package]] name = "generic-array" version = "0.14.6" @@ -1123,6 +1111,31 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "headers" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" +dependencies = [ + "base64", + "bitflags", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http", +] + [[package]] name = "heck" version = "0.3.3" @@ -1270,6 +1283,21 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-proxy" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca815a891b24fdfb243fa3239c86154392b0953ee584aa1a2a1f66d20cbe75cc" +dependencies = [ + "bytes", + "futures", + "headers", + "http", + "hyper", + "tokio", + "tower-service", +] + [[package]] name = "iana-time-zone" version = "0.1.54" @@ -1312,25 +1340,14 @@ dependencies = [ [[package]] name = "if-addrs" -version = "0.6.7" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2273e421f7c4f0fc99e1934fe4776f59d8df2972f4199d703fc0da9f2a9f73de" +checksum = "cbc0fa01ffc752e9dbc72818cdb072cd028b86be5e09dd04c5a643704fe101a9" dependencies = [ - "if-addrs-sys", "libc", "winapi", ] -[[package]] -name = "if-addrs-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de74b9dd780476e837e5eb5ab7c88b49ed304126e412030a0adba99c8efe79ea" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "indenter" version = "0.3.3" @@ -1485,11 +1502,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "libm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" + [[package]] name = "libmdns" -version = "0.6.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a934bceaf91ba575f978d4042a96f919a2f10fa0189c2aa42fcc1051f6ac3e58" +checksum = "6a60d8339ad1ddf68a81335fcafb6c6cf20d5036138a1e4ef86b8ce87f076c92" dependencies = [ "byteorder", "futures-util", @@ -1497,10 +1520,12 @@ dependencies = [ "if-addrs", "log", "multimap", + "nix 0.23.2", "rand", "socket2", "thiserror", "tokio", + "winapi", ] [[package]] @@ -1553,40 +1578,30 @@ dependencies = [ [[package]] name = "librespot-audio" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0e89d3e106d80600537eba02c17ea6dd8b3de3f46c99952b813b6f6d6445c0" +checksum = "c176a31355e1ea8e0b9c4ced19df4947bfe4770661c25c142b6fba2365940d9d" dependencies = [ "aes-ctr", "byteorder", "bytes", - "cfg-if", "futures-util", - "lewton", "librespot-core", - "librespot-tremor", "log", - "ogg", "tempfile", "tokio", - "zerocopy", ] [[package]] name = "librespot-connect" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69425fd6c8d74779f1ec86b16e6b3114df50c8a0d94db5a5601ef634bfb5e288" +checksum = "4ffafb6a443e9445ccb3d5d591573b5b1da3c89a9b8846c63ba2c3710210d3ec" dependencies = [ - "aes-ctr", - "base64", "form_urlencoded", - "futures-core", "futures-util", - "hmac 0.11.0", - "hyper", - "libmdns", "librespot-core", + "librespot-discovery", "librespot-playback", "librespot-protocol", "log", @@ -1594,17 +1609,15 @@ dependencies = [ "rand", "serde", "serde_json", - "sha-1 0.9.8", "tokio", "tokio-stream", - "url", ] [[package]] name = "librespot-core" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3e70dce131f5531c982ca133f04fd1d1dd4208de27291dcd9ab6841c963248" +checksum = "046349f25888e644bf02d9c5de0164b2a493d29aa4ce18e1ad0b756da9b55d6d" dependencies = [ "aes 0.6.0", "base64", @@ -1616,6 +1629,8 @@ dependencies = [ "hmac 0.11.0", "http", "httparse", + "hyper", + "hyper-proxy", "librespot-protocol", "log", "num-bigint", @@ -1639,11 +1654,33 @@ dependencies = [ "vergen", ] +[[package]] +name = "librespot-discovery" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aa877d18f6150364012cb4be5682d62d7c712c88bae2d0d01720fd7c15e2f06" +dependencies = [ + "aes-ctr", + "base64", + "form_urlencoded", + "futures-core", + "hmac 0.11.0", + "hyper", + "libmdns", + "librespot-core", + "log", + "rand", + "serde_json", + "sha-1 0.9.8", + "thiserror", + "tokio", +] + [[package]] name = "librespot-metadata" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84157ce5d901dbdcaef17ed305deba5d87171725347673a1b632a334d910af47" +checksum = "6b80361fcbcb5092056fd47c08c34d5d51b08385d8efb6941c0d3e46d032c21c" dependencies = [ "async-trait", "byteorder", @@ -1655,22 +1692,27 @@ dependencies = [ [[package]] name = "librespot-playback" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ca3df986a7e1a43008717660803e159177e86a589d484a0fc01fccd7967ad6" +checksum = "5190a0b9bcc7f70ee4196a6b4a1c731d405ca130d4a6fcd4c561cfdde8b7cfb7" dependencies = [ - "alsa 0.5.0", + "alsa 0.6.0", "byteorder", "cpal", "futures-executor", "futures-util", + "lewton", "libpulse-binding", "libpulse-simple-binding", "librespot-audio", "librespot-core", "librespot-metadata", "log", + "ogg", + "parking_lot 0.12.1", "portaudio-rs", + "rand", + "rand_distr", "rodio", "shell-words", "thiserror", @@ -1680,28 +1722,15 @@ dependencies = [ [[package]] name = "librespot-protocol" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c753be4c3bd0f02b30c00d5d8547f16d557654cb737e70505aec6aa9990435d" +checksum = "5d6d3ac6196ac0ea67bbe039f56d6730a5d8b31502ef9bce0f504ed729dcb39f" dependencies = [ "glob", "protobuf", - "protobuf-codegen", "protobuf-codegen-pure", ] -[[package]] -name = "librespot-tremor" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97f525bff915d478a76940a7b988e5ea34911ba7280c97bd3a7673f54d68b4fe" -dependencies = [ - "cc", - "libc", - "ogg-sys", - "pkg-config", -] - [[package]] name = "link-cplusplus" version = "1.0.8" @@ -1796,6 +1825,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1888,18 +1923,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "nix" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", -] - [[package]] name = "nix" version = "0.23.2" @@ -2034,6 +2057,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -2117,17 +2141,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "ogg-sys" -version = "0.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a95b8c172e17df1a41bf8d666301d3b2c4efeb90d9d0415e2a4dc0668b35fdb2" -dependencies = [ - "gcc", - "libc", - "pkg-config", -] - [[package]] name = "once_cell" version = "1.17.1" @@ -2170,7 +2183,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core", + "parking_lot_core 0.8.6", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core 0.9.7", ] [[package]] @@ -2187,6 +2210,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "parking_lot_core" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +dependencies = [ + "backtrace", + "cfg-if", + "libc", + "petgraph", + "redox_syscall", + "smallvec", + "thread-id", + "windows-sys 0.45.0", +] + [[package]] name = "pbkdf2" version = "0.8.0" @@ -2209,6 +2248,16 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +[[package]] +name = "petgraph" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +dependencies = [ + "fixedbitset", + "indexmap", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -2325,24 +2374,24 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.14.0" +version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e86d370532557ae7573551a1ec8235a0f8d6cb276c7c9e6aa490b511c447485" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" [[package]] name = "protobuf-codegen" -version = "2.14.0" +version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de113bba758ccf2c1ef816b127c958001b7831136c9bc3f8e9ec695ac4e82b0c" +checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" dependencies = [ "protobuf", ] [[package]] name = "protobuf-codegen-pure" -version = "2.14.0" +version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d1a4febc73bf0cada1d77c459a0c8e5973179f1cfd5b0f1ab789d45b17b6440" +checksum = "95a29399fc94bcd3eeaa951c715f7bea69409b2445356b00519740bcd6ddd865" dependencies = [ "protobuf", "protobuf-codegen", @@ -2387,6 +2436,16 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_distr" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" +dependencies = [ + "num-traits", + "rand", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -2441,9 +2500,9 @@ dependencies = [ [[package]] name = "rodio" -version = "0.13.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b65c2eda643191f6d1bb12ea323a9db8d9ba95374e9be3780b5a9fb5cfb8520f" +checksum = "ec0939e9f626e6c6f1989adb6226a039c855ca483053f0ee7c98b90e41cf731e" dependencies = [ "cpal", ] @@ -2834,6 +2893,7 @@ dependencies = [ "librespot-audio", "librespot-connect", "librespot-core", + "librespot-discovery", "librespot-playback", "log", "rspotify", @@ -2947,18 +3007,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "unicode-xid", -] - [[package]] name = "syslog" version = "6.0.1" @@ -3023,6 +3071,17 @@ dependencies = [ "syn 2.0.4", ] +[[package]] +name = "thread-id" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fdfe0627923f7411a43ec9ec9c39c3a9b4151be313e0922042581fb6c9b717f" +dependencies = [ + "libc", + "redox_syscall", + "winapi", +] + [[package]] name = "thread_local" version = "1.1.7" @@ -3100,6 +3159,7 @@ dependencies = [ "memchr", "mio", "num_cpus", + "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", "socket2", @@ -3131,16 +3191,16 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.10" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" dependencies = [ "bytes", "futures-core", "futures-sink", - "log", "pin-project-lite", "tokio", + "tracing", ] [[package]] @@ -3292,12 +3352,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - [[package]] name = "untrusted" version = "0.7.1" @@ -3336,9 +3390,9 @@ dependencies = [ [[package]] name = "uuid" -version = "0.8.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ "getrandom", ] @@ -3723,9 +3777,9 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.3.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6580539ad917b7c026220c4b3f2c08d52ce54d6ce0dc491e66002e35388fab46" +checksum = "332f188cc1bcf1fe1064b8c58d150f497e697f49774aa846f2dc949d9a25f236" dependencies = [ "byteorder", "zerocopy-derive", @@ -3733,13 +3787,13 @@ dependencies = [ [[package]] name = "zerocopy-derive" -version = "0.2.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d498dbd1fd7beb83c86709ae1c33ca50942889473473d287d56ce4770a18edfb" +checksum = "6505e6815af7de1746a08f69c69606bb45695a17149517680f3b2149713b19a3" dependencies = [ "proc-macro2", + "quote", "syn 1.0.109", - "synstructure", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d8e07ee4..f56de932 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,10 +31,11 @@ tokio = {version = "1.6.1", features = ["signal", "rt-multi-thread", "process", tokio-stream = "0.1.7" url = "2.2.2" xdg = "2.2" -librespot-audio = { version = "0.2.0", default-features=false, features = ["with-tremor"] } -librespot-playback = { version = "0.2.0", default-features=false } -librespot-core = { version = "0.2.0"} -librespot-connect = { version = "0.2.0"} +librespot-audio = { version = "0.4", default-features = false } +librespot-playback = { version = "0.4", default-features = false } +librespot-core = { version = "0.4" } +librespot-discovery = { version = "0.4" } +librespot-connect = { version = "0.4" } toml = "0.7" color-eyre = "0.6" diff --git a/src/alsa_mixer.rs b/src/alsa_mixer.rs index ebc52ade..5bac42ab 100644 --- a/src/alsa_mixer.rs +++ b/src/alsa_mixer.rs @@ -1,7 +1,8 @@ -use librespot_playback::mixer::{AudioFilter, Mixer, MixerConfig}; +use librespot_playback::mixer::{Mixer, MixerConfig}; use log::error; use std::error::Error; +#[derive(Clone)] pub struct AlsaMixer { pub device: String, pub mixer: String, @@ -35,7 +36,7 @@ impl AlsaMixer { } impl Mixer for AlsaMixer { - fn open(_: Option) -> AlsaMixer { + fn open(_: MixerConfig) -> AlsaMixer { AlsaMixer { device: "default".to_string(), mixer: "Master".to_string(), @@ -43,10 +44,6 @@ impl Mixer for AlsaMixer { } } - fn start(&self) {} - - fn stop(&self) {} - fn volume(&self) -> u16 { let selem_id = alsa::mixer::SelemId::new(&self.mixer, 0); match alsa::mixer::Mixer::new(&self.device, false) @@ -79,8 +76,4 @@ impl Mixer for AlsaMixer { Err(e) => error!("Couldn't set volume: {:?}", e), } } - - fn get_audio_filter(&self) -> Option> { - None - } } diff --git a/src/config.rs b/src/config.rs index a31b07b7..0e8af349 100644 --- a/src/config.rs +++ b/src/config.rs @@ -415,7 +415,7 @@ pub struct SharedConfigValues { /// A custom pregain applied before sending the audio to the output device #[structopt(long, value_name = "number")] - normalisation_pregain: Option, + normalisation_pregain: Option, /// The port used for the Spotify Connect discovery #[structopt(long, value_name = "number")] @@ -647,7 +647,14 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig { let cache = config .shared_config .cache_path - .map(|path| Cache::new(Some(&path), audio_cache.then_some(&path), size_limit)) + .map(|path| { + Cache::new( + Some(&path), + Some(&path), + audio_cache.then_some(&path), + size_limit, + ) + }) .transpose() .unwrap_or_else(|e| { warn!("Cache couldn't be initialized: {e}"); @@ -692,7 +699,7 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig { let device_id = device_id(&device_name); - let normalisation_pregain = config.shared_config.normalisation_pregain.unwrap_or(0.0f32); + let normalisation_pregain = config.shared_config.normalisation_pregain.unwrap_or(0.0); let dbus_type = config.shared_config.dbus_type.unwrap_or(DBusType::Session); let autoplay = config.shared_config.autoplay; @@ -759,10 +766,7 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig { let pc = PlayerConfig { bitrate, normalisation: config.shared_config.volume_normalisation, - normalisation_pregain, - // Sensible default; the "default" supplied by PlayerConfig::default() sets this to -1.0, - // which turns the output to garbage. - normalisation_threshold: 1.0, + normalisation_pregain_db: normalisation_pregain, gapless: true, ..Default::default() }; diff --git a/src/dbus_mpris.rs b/src/dbus_mpris.rs index 9f247de8..d7c99746 100644 --- a/src/dbus_mpris.rs +++ b/src/dbus_mpris.rs @@ -614,12 +614,12 @@ async fn create_dbus_server( if let Some(track_id) = track_id { let item = match track_id.audio_type { SpotifyAudioType::Track => { - let track_id = TrackId::from_id(track_id.to_base62()).unwrap(); + let track_id = TrackId::from_id(track_id.to_base62().unwrap()).unwrap(); let track = spotify_api_client.track(track_id).map(PlayableItem::Track); Some(track) } SpotifyAudioType::Podcast => { - let id = EpisodeId::from_id(track_id.to_base62()).unwrap(); + let id = EpisodeId::from_id(track_id.to_base62().unwrap()).unwrap(); let episode = spotify_api_client .get_an_episode(id, None) .map(PlayableItem::Episode); diff --git a/src/main_loop.rs b/src/main_loop.rs index e4796f87..dd4ea578 100644 --- a/src/main_loop.rs +++ b/src/main_loop.rs @@ -8,13 +8,14 @@ use futures::{ stream::Peekable, Future, FutureExt, StreamExt, }; -use librespot_connect::{discovery::DiscoveryStream, spirc::Spirc}; +use librespot_connect::spirc::Spirc; use librespot_core::{ authentication::Credentials, cache::Cache, - config::{ConnectConfig, DeviceType, SessionConfig, VolumeCtrl}, + config::{ConnectConfig, DeviceType, SessionConfig}, session::{Session, SessionError}, }; +use librespot_discovery::Discovery; use librespot_playback::{ audio_backend::Sink, config::{AudioFormat, PlayerConfig}, @@ -38,20 +39,20 @@ pub struct SpotifydState { } pub(crate) enum CredentialsProvider { - DiscoveryStream(Peekable), + Discovery(Peekable), SpotifyCredentials(Credentials), } -impl From for CredentialsProvider { - fn from(stream: DiscoveryStream) -> Self { - CredentialsProvider::DiscoveryStream(stream.peekable()) +impl From for CredentialsProvider { + fn from(stream: Discovery) -> Self { + CredentialsProvider::Discovery(stream.peekable()) } } impl CredentialsProvider { async fn get_credentials(&mut self) -> Credentials { match self { - CredentialsProvider::DiscoveryStream(stream) => stream.next().await.unwrap(), + CredentialsProvider::Discovery(stream) => stream.next().await.unwrap(), CredentialsProvider::SpotifyCredentials(creds) => creds.clone(), } } @@ -59,7 +60,7 @@ impl CredentialsProvider { // wait for an incoming connection if the underlying provider is a discovery stream async fn incoming_connection(&mut self) { match self { - CredentialsProvider::DiscoveryStream(stream) => { + CredentialsProvider::Discovery(stream) => { let peeked = Pin::new(stream).peek().await; if peeked.is_none() { future::pending().await @@ -76,7 +77,7 @@ pub(crate) struct MainLoop { pub(crate) player_config: PlayerConfig, pub(crate) session_config: SessionConfig, pub(crate) autoplay: bool, - pub(crate) volume_ctrl: VolumeCtrl, + pub(crate) has_volume_ctrl: bool, pub(crate) initial_volume: Option, pub(crate) shell: String, pub(crate) device_type: DeviceType, @@ -94,7 +95,9 @@ impl MainLoop { let session_config = self.session_config.clone(); let cache = self.spotifyd_state.cache.clone(); - Session::connect(session_config, creds, cache).await + Session::connect(session_config, creds, cache, false) + .await + .map(|(session, _creds)| session) } pub(crate) async fn run(&mut self) { @@ -119,13 +122,12 @@ impl MainLoop { ); let mixer = (self.audio_setup.mixer)(); - let audio_filter = mixer.get_audio_filter(); let backend = self.audio_setup.backend; let audio_device = self.audio_setup.audio_device.clone(); let (player, mut event_channel) = Player::new( self.player_config.clone(), session.clone(), - audio_filter, + mixer.get_soft_volume(), // TODO: dunno how to work with AudioFormat yet, maybe dig further if this // doesn't work for all configurations move || (backend)(audio_device, AudioFormat::default()), @@ -136,8 +138,8 @@ impl MainLoop { autoplay: self.autoplay, name: self.spotifyd_state.device_name.clone(), device_type: self.device_type, - volume: self.initial_volume.unwrap_or_else(|| mixer.volume()), - volume_ctrl: self.volume_ctrl.clone(), + initial_volume: self.initial_volume, + has_volume_ctrl: self.has_volume_ctrl, }, session.clone(), player, diff --git a/src/no_mixer.rs b/src/no_mixer.rs index 9d015883..6200d00d 100644 --- a/src/no_mixer.rs +++ b/src/no_mixer.rs @@ -1,23 +1,15 @@ -use librespot_playback::mixer::{AudioFilter, Mixer, MixerConfig}; +use librespot_playback::mixer::{Mixer, MixerConfig}; -pub struct NoMixer {} +pub struct NoMixer; impl Mixer for NoMixer { - fn open(_: Option) -> NoMixer { + fn open(_: MixerConfig) -> NoMixer { NoMixer {} } - fn start(&self) {} - - fn stop(&self) {} - fn volume(&self) -> u16 { u16::MAX } fn set_volume(&self, _volume: u16) {} - - fn get_audio_filter(&self) -> Option> { - None - } } diff --git a/src/process.rs b/src/process.rs index 0ef2f933..886187f1 100644 --- a/src/process.rs +++ b/src/process.rs @@ -58,9 +58,9 @@ pub(crate) fn spawn_program_on_event( old_track_id, new_track_id, } => { - env.insert("OLD_TRACK_ID", old_track_id.to_base62()); + env.insert("OLD_TRACK_ID", old_track_id.to_base62().unwrap()); env.insert("PLAYER_EVENT", "change".to_string()); - env.insert("TRACK_ID", new_track_id.to_base62()); + env.insert("TRACK_ID", new_track_id.to_base62().unwrap()); } PlayerEvent::Started { track_id, @@ -68,7 +68,7 @@ pub(crate) fn spawn_program_on_event( position_ms, } => { env.insert("PLAYER_EVENT", "start".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); env.insert("POSITION_MS", position_ms.to_string()); } @@ -77,7 +77,7 @@ pub(crate) fn spawn_program_on_event( play_request_id, } => { env.insert("PLAYER_EVENT", "stop".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); } PlayerEvent::Loading { @@ -86,7 +86,7 @@ pub(crate) fn spawn_program_on_event( position_ms, } => { env.insert("PLAYER_EVENT", "load".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); env.insert("POSITION_MS", position_ms.to_string()); } @@ -97,7 +97,7 @@ pub(crate) fn spawn_program_on_event( duration_ms, } => { env.insert("PLAYER_EVENT", "play".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); env.insert("POSITION_MS", position_ms.to_string()); env.insert("DURATION_MS", duration_ms.to_string()); @@ -109,7 +109,7 @@ pub(crate) fn spawn_program_on_event( duration_ms, } => { env.insert("PLAYER_EVENT", "pause".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); env.insert("POSITION_MS", position_ms.to_string()); env.insert("DURATION_MS", duration_ms.to_string()); @@ -119,7 +119,7 @@ pub(crate) fn spawn_program_on_event( play_request_id, } => { env.insert("PLAYER_EVENT", "preload".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); } PlayerEvent::EndOfTrack { @@ -127,7 +127,7 @@ pub(crate) fn spawn_program_on_event( play_request_id, } => { env.insert("PLAYER_EVENT", "endoftrack".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); } PlayerEvent::VolumeSet { volume } => { @@ -139,12 +139,12 @@ pub(crate) fn spawn_program_on_event( track_id, } => { env.insert("PLAYER_EVENT", "unavailable".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); env.insert("PLAY_REQUEST_ID", play_request_id.to_string()); } PlayerEvent::Preloading { track_id } => { env.insert("PLAYER_EVENT", "preloading".to_string()); - env.insert("TRACK_ID", track_id.to_base62()); + env.insert("TRACK_ID", track_id.to_base62().unwrap()); } } spawn_program(shell, cmd, env) diff --git a/src/setup.rs b/src/setup.rs index 8892c45b..eca5619b 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -6,26 +6,23 @@ use crate::{ }; #[cfg(feature = "dbus_keyring")] use keyring::Entry; -use librespot_connect::discovery::discovery; -use librespot_core::{ - authentication::Credentials, - cache::Cache, - config::{ConnectConfig, DeviceType, VolumeCtrl}, -}; +use librespot_core::{authentication::Credentials, cache::Cache, config::DeviceType}; +use librespot_playback::mixer::MixerConfig; use librespot_playback::{ audio_backend::{Sink, BACKENDS}, config::AudioFormat, mixer::{self, Mixer}, }; +#[allow(unused_imports)] // cfg use log::{error, info, warn}; use std::str::FromStr; pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLoop { - let mut mixer = { + let mixer = { match config.volume_controller { config::VolumeController::None => { info!("Using no volume controller."); - Box::new(|| Box::new(crate::no_mixer::NoMixer::open(None)) as Box) + Box::new(|| Box::new(crate::no_mixer::NoMixer) as Box) as Box Box> } #[cfg(feature = "alsa_backend")] @@ -51,8 +48,10 @@ pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLo } _ => { info!("Using software volume controller."); - Box::new(|| Box::new(mixer::softmixer::SoftMixer::open(None)) as Box) - as Box Box> + Box::new(move || { + Box::new(mixer::softmixer::SoftMixer::open(MixerConfig::default())) + as Box + }) as Box Box> } } }; @@ -62,14 +61,8 @@ pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLo let session_config = config.session_config; let backend = config.backend.clone(); let autoplay = config.autoplay; - let device_id = session_config.device_id.clone(); - let volume_ctrl = match config.volume_controller { - #[cfg(feature = "alsa_backend")] - config::VolumeController::AlsaLinear => VolumeCtrl::Linear, - config::VolumeController::None => VolumeCtrl::Fixed, - _ => VolumeCtrl::Log, - }; + let has_volume_ctrl = !matches!(config.volume_controller, config::VolumeController::None); let zeroconf_port = config.zeroconf_port.unwrap_or(0); @@ -97,25 +90,19 @@ pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLo } } - let credentials_provider = - if let Some(credentials) = get_credentials(&cache, &username, &password) { - CredentialsProvider::SpotifyCredentials(credentials) - } else { - info!("no usable credentials found, enabling discovery"); - let discovery_stream = discovery( - ConnectConfig { - autoplay, - name: config.device_name.clone(), - device_type, - volume: mixer().volume(), - volume_ctrl: volume_ctrl.clone(), - }, - device_id, - zeroconf_port, - ) + let credentials_provider = if let Some(credentials) = + get_credentials(&cache, &username, &password) + { + CredentialsProvider::SpotifyCredentials(credentials) + } else { + info!("no usable credentials found, enabling discovery"); + let discovery_stream = librespot_discovery::Discovery::builder(config.device_name.clone()) + .device_type(device_type) + .port(zeroconf_port) + .launch() .unwrap(); - discovery_stream.into() - }; + discovery_stream.into() + }; let backend = find_backend(backend.as_ref().map(String::as_ref)); main_loop::MainLoop { @@ -133,7 +120,7 @@ pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLo player_config, session_config, initial_volume: config.initial_volume, - volume_ctrl, + has_volume_ctrl, shell: config.shell, device_type, autoplay,