From 34eae153a88770d906ac2d51ae399606bbfc666b Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Apr 2020 15:58:50 +0100 Subject: [PATCH 01/12] add makefile and fix passwords with '#' --- Makefile | 8 ++++++++ src/config.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..6be4e2bd --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +build: + cargo build --release --no-default-features --features "pulseaudio_backend,dbus_keyring,dbus_mpris" + +run: + cargo run --no-default-features --features "pulseaudio_backend,dbus_keyring,dbus_mpris" -- --no-daemon --verbose + +install: ./target/release/spotifyd + sudo cp ./target/release/spotifyd /usr/bin/ diff --git a/src/config.rs b/src/config.rs index 59d1f962..fa06695a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -489,7 +489,7 @@ impl CliConfig { .filter_map(Option::Some) .map(|x| x.unwrap()) .map(|mut l: String| { - let last_index = l.rfind('#').unwrap_or_else(|| l.len()); + let last_index = l.rfind(" #").unwrap_or_else(|| l.len()); l.drain(..last_index).collect() }) // The password field takes the whole value as the password. We need to remove the space between From b569a8814eb23e0792ff129fb3a7018d05e9dd9a Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Apr 2020 23:24:10 +0100 Subject: [PATCH 02/12] change config format to TOML --- Cargo.lock | 38 ++++++++++--------- Cargo.toml | 3 +- src/config.rs | 102 ++++++++++++++------------------------------------ 3 files changed, 51 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab022323..02590db1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2194,11 +2194,6 @@ dependencies = [ "winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "result" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "rodio" version = "0.9.0" @@ -2375,23 +2370,23 @@ dependencies = [ ] [[package]] -name = "serde_ini" -version = "0.2.0" +name = "serde_json" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "result 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "serde_json" -version = "1.0.44" +name = "serde_repr" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2542,13 +2537,14 @@ dependencies = [ "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rspotify 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_ini 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "syslog 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-signal 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "whoami 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3020,6 +3016,14 @@ dependencies = [ "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "toml" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tower-service" version = "0.3.0" @@ -3583,7 +3587,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum relay 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1576e382688d7e9deecea24417e350d3062d97e32e45d70b1cde65994ff1489a" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0e798e19e258bf6c30a304622e3e9ac820e483b06a1857a026e1f109b113fe4" -"checksum result 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560" "checksum rodio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d0f961b254e66d147a7b550c78b01308934c97d807a34b417fd0f5a0a0f3a2d" "checksum rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34fa7bcae7fca3c8471e8417088bbc3ad9af8066b0ecf4f3c0d98a0d772716e" "checksum rspotify 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a924a166cfb1315c8d9c89148e438a1337feb655ce052fc6dc952af8018bad93" @@ -3604,8 +3607,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" "checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" -"checksum serde_ini 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb236687e2bb073a7521c021949be944641e671b8505a94069ca37b656c81139" "checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" +"checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" "checksum sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" "checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" @@ -3663,6 +3666,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" "checksum tokio-util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "571da51182ec208780505a32528fc5512a8fe1443ab960b3f2f3ef093cd16930" +"checksum toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" "checksum tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" "checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" diff --git a/Cargo.toml b/Cargo.toml index 1bec0ff0..fef544c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ log = "0.4.6" percent-encoding = "2.1.0" rspotify = "0.8.0" serde = { version = "1.0.103", features = ["derive"] } -serde_ini = "0.2.0" sha-1 = "0.8" structopt = "0.3.11" syslog = "4" @@ -35,6 +34,8 @@ tokio-signal = "0.1" url = "1.7" xdg = "2.2" librespot = { version = "0.1.1", default-features = false, features = ["with-tremor"] } +toml = "0.5.6" +serde_repr = "0.1.5" [target."cfg(target_os = \"macos\")".dependencies] whoami = "0.8.1" diff --git a/src/config.rs b/src/config.rs index fa06695a..5fddd6c8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,13 +5,14 @@ use librespot::{ playback::config::{Bitrate as LSBitrate, PlayerConfig}, }; use log::{error, info}; -use serde::{de, Deserialize}; +use serde::Deserialize; +use serde_repr::Deserialize_repr; use sha1::{Digest, Sha1}; use structopt::{clap::AppSettings, StructOpt}; use url::Url; use xdg; -use std::{fmt, fs, io::BufRead, path::PathBuf, str::FromStr, string::ToString}; +use std::{fmt, fs, path::PathBuf, str::FromStr, string::ToString}; use crate::{ error::{Error as CrateError, ParseError}, @@ -193,14 +194,12 @@ lazy_static! { } /// Spotify's audio bitrate -#[derive(Clone, Copy, Debug, Deserialize, PartialEq, StructOpt)] +#[derive(Clone, Copy, Debug, Deserialize_repr, PartialEq, StructOpt)] +#[repr(u16)] pub enum Bitrate { - #[serde(rename = "96")] - Bitrate96, - #[serde(rename = "160")] - Bitrate160, - #[serde(rename = "320")] - Bitrate320, + Bitrate96 = 96, + Bitrate160 = 160, + Bitrate320 = 320, } impl FromStr for Bitrate { @@ -226,30 +225,6 @@ impl Into for Bitrate { } } -struct BoolFromStr; - -impl<'de> de::Visitor<'de> for BoolFromStr { - type Value = bool; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("a string containing \"true\" or \"false\"") - } - - fn visit_str(self, s: &str) -> Result - where - E: serde::de::Error, - { - bool::from_str(s).map_err(serde::de::Error::custom) - } -} - -fn de_from_str<'de, D>(deserializer: D) -> Result -where - D: de::Deserializer<'de>, -{ - deserializer.deserialize_str(BoolFromStr) -} - #[derive(Debug, Default, StructOpt)] #[structopt( about = "A Spotify daemon", @@ -294,7 +269,7 @@ pub struct SharedConfigValues { #[cfg_attr( feature = "dbus_keyring", structopt(long), - serde(alias = "use-keyring", default, deserialize_with = "de_from_str") + serde(alias = "use-keyring", default) )] #[cfg_attr(not(feature = "dbus_keyring"), structopt(skip), serde(skip))] use_keyring: bool, @@ -320,7 +295,7 @@ pub struct SharedConfigValues { /// Disable the use of audio cache #[structopt(long)] - #[serde(default, deserialize_with = "de_from_str")] + #[serde(default)] no_audio_cache: bool, /// The audio backend to use @@ -354,7 +329,7 @@ pub struct SharedConfigValues { /// Enable to normalize the volume during playback #[structopt(long)] - #[serde(default, deserialize_with = "de_from_str")] + #[serde(default)] volume_normalisation: bool, /// A custom pregain applied before sending the audio to the output device @@ -375,7 +350,7 @@ pub struct SharedConfigValues { /// Autoplay on connect #[structopt(long)] - #[serde(default, deserialize_with = "de_from_str")] + #[serde(default)] autoplay: bool, } @@ -461,44 +436,23 @@ impl fmt::Debug for SharedConfigValues { impl CliConfig { pub fn load_config_file_values(&mut self) { - let config_file_path = self.config_path.clone().or_else(get_config_file); - - if config_file_path.is_none() { - info!("No config file specified. Running with default values"); - return; - } - let unwrapped_config_file_path = config_file_path.unwrap(); - info!("Loading config from {:?}", &unwrapped_config_file_path); - - let config_file = fs::File::open(&unwrapped_config_file_path); - if config_file.is_err() { - info!( - "Failed to open config file at {:?}", - &unwrapped_config_file_path - ); - return; - } + let config_file_path = match self.config_path.clone().or_else(get_config_file) { + Some(p) => p, + None => { + info!("No config file specified. Running with default values"); + return; + } + }; + info!("Loading config from {:?}", &config_file_path); - let bufreader = std::io::BufReader::new(config_file.unwrap()); - // serde_ini doesn't support inline comments. We treat every hashtag as a comment starter and everything that follows - // it as not part of the key's value. - // The method below will filter out any errors that occur. - // TODO: Is there a cleaner way to do this? One with less allocations. - let comment_free_lines: Vec = bufreader - .lines() - .filter_map(Option::Some) - .map(|x| x.unwrap()) - .map(|mut l: String| { - let last_index = l.rfind(" #").unwrap_or_else(|| l.len()); - l.drain(..last_index).collect() - }) - // The password field takes the whole value as the password. We need to remove the space between - // the password and the # character. - .map(|l: String| l.trim().to_string()) - .collect(); - - let comment_free_content = comment_free_lines.join("\n"); - let config_content: FileConfig = serde_ini::from_str(&comment_free_content).unwrap(); + let content = match std::fs::read_to_string(config_file_path) { + Ok(s) => s, + Err(e) => { + error!("Failed reading from config file: {}", e); + return; + } + }; + let config_content: FileConfig = toml::from_str(&content).unwrap(); // The call to get_merged_sections consumes the FileConfig! if let Some(merged_sections) = config_content.get_merged_sections() { From a45e23dcb7b68e5828e0726df3a24fcbf5ad8c5f Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 16 Apr 2020 03:46:14 +0100 Subject: [PATCH 03/12] remove makefile --- Makefile | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 6be4e2bd..00000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -build: - cargo build --release --no-default-features --features "pulseaudio_backend,dbus_keyring,dbus_mpris" - -run: - cargo run --no-default-features --features "pulseaudio_backend,dbus_keyring,dbus_mpris" -- --no-daemon --verbose - -install: ./target/release/spotifyd - sudo cp ./target/release/spotifyd /usr/bin/ From 18327da1e5c4c4e176f6c391a1328300a5edfb80 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 19 Apr 2020 15:12:00 +0100 Subject: [PATCH 04/12] minor tidy --- src/config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 5fddd6c8..e1110248 100644 --- a/src/config.rs +++ b/src/config.rs @@ -448,10 +448,11 @@ impl CliConfig { let content = match std::fs::read_to_string(config_file_path) { Ok(s) => s, Err(e) => { - error!("Failed reading from config file: {}", e); + info!("Failed reading config file: {}", e); return; } }; + let config_content: FileConfig = toml::from_str(&content).unwrap(); // The call to get_merged_sections consumes the FileConfig! From e888a1d5296f92e515cbd1ee10aa1f545cbd01e8 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 7 Sep 2020 13:17:30 +0100 Subject: [PATCH 05/12] fix imports --- Cargo.lock | 59 +++++++-------------------------------------------- src/config.rs | 12 ++--------- 2 files changed, 10 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5587a92e..2f52df54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,17 +231,6 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "block-buffer" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "block-cipher-trait" version = "0.6.2" @@ -616,14 +605,6 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "dotenv" version = "0.13.0" @@ -872,15 +853,6 @@ dependencies = [ "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "generic-array" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "gethostname" version = "0.2.1" @@ -2424,7 +2396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2432,9 +2404,9 @@ name = "serde_repr" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2459,17 +2431,6 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sha-1" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-buffer 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sha2" version = "0.8.1" @@ -2595,10 +2556,10 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rspotify 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", "serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "syslog 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3080,7 +3041,7 @@ name = "toml" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3437,7 +3398,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -"checksum block-buffer 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dbcf92448676f82bb7a334c58bbce8b0d43580fb5362a9d608b18879d12a3d31" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" "checksum block-modes 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "31aa8410095e39fdb732909fb5730a48d5bd7c2e3cd76bd1b07b3dbea130c529" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" @@ -3481,7 +3441,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ac53fa6a3cda160df823a9346442525dcaf1e171999a1cf23e67067e4fd64d4" "checksum derive_builder_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0288a23da9333c246bb18c143426074a6ae96747995c5819d2947b64cd942b37" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" -"checksum digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" "checksum dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d0a1279c96732bc6800ce6337b6a614697b0e74ae058dc03c62ebeb78b4d86" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" @@ -3513,7 +3472,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" -"checksum generic-array 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ac746a5f3bbfdadd6106868134545e684693d54d9d44f6e9588a7d54af0bf980" "checksum gethostname 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e692e296bfac1d2533ef168d0b60ff5897b8b70a4009276834014dd8924cc028" "checksum getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" @@ -3669,13 +3627,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum security-framework-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" -"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +"checksum serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" +"checksum serde_derive 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" "checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" "checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" "checksum sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" -"checksum sha-1 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "59520a294fcfdaff2ce8276dc1bdc6170b97abe8043560f70178222e611242fc" "checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" "checksum shannon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ea5b41c9427b56caa7b808cb548a04fb50bb5b9e98590b53f28064ff4174561" "checksum shell-words 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39acde55a154c4cd3ae048ac78cc21c25f3a0145e44111b523279113dce0d94a" diff --git a/src/config.rs b/src/config.rs index b8762fe5..7f98913b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,23 +9,15 @@ use librespot::{ core::{cache::Cache, config::DeviceType as LSDeviceType, config::SessionConfig, version}, playback::config::{Bitrate as LSBitrate, PlayerConfig}, }; -use log::{error, info}; +use log::{error, info, warn}; use serde::Deserialize; use serde_repr::Deserialize_repr; use sha1::{Digest, Sha1}; -use std::{fmt, fs, io::BufRead, path::PathBuf, str::FromStr, string::ToString}; +use std::{fmt, fs, path::PathBuf, str::FromStr, string::ToString}; use structopt::{clap::AppSettings, StructOpt}; use url::Url; use xdg; -use std::{fmt, fs, path::PathBuf, str::FromStr, string::ToString}; - -use crate::{ - error::{Error as CrateError, ParseError}, - process::run_program, - utils, -}; - const CONFIG_FILE_NAME: &str = "spotifyd.conf"; lazy_static! { From 41aa6f890e80c9488f4065c93e18b3b6e7b993f3 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 7 Sep 2020 13:24:45 +0100 Subject: [PATCH 06/12] unused import --- src/config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 7f98913b..43ebc912 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,7 +16,6 @@ use sha1::{Digest, Sha1}; use std::{fmt, fs, path::PathBuf, str::FromStr, string::ToString}; use structopt::{clap::AppSettings, StructOpt}; use url::Url; -use xdg; const CONFIG_FILE_NAME: &str = "spotifyd.conf"; From a6e3b894e7cd28313eab426530542d71de3c2c53 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 27 Sep 2020 16:24:49 +0100 Subject: [PATCH 07/12] bump deps to match master --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1e0ebba6..8f9d8ce4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,9 @@ libc = "0.2.73" log = "0.4.6" percent-encoding = "2.1.0" rspotify = "0.8.0" -serde = { version = "1.0.103", features = ["derive"] } -sha-1 = "0.8" -structopt = "0.3.11" +serde = { version = "1.0.115", features = ["derive"] } +sha-1 = "0.9" +structopt = "0.3.17" syslog = "4" tokio-core = "0.1" tokio-io = "0.1" From 6653aaade8bc0cef5b4f6646b1eace7b8ea164a6 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 27 Sep 2020 16:27:35 +0100 Subject: [PATCH 08/12] update lock file --- Cargo.lock | 63 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f52df54..94165f34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,6 +231,14 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block-cipher-trait" version = "0.6.2" @@ -427,6 +435,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "crossbeam-deque" version = "0.7.2" @@ -605,6 +618,14 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dotenv" version = "0.13.0" @@ -850,7 +871,16 @@ name = "generic-array" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1531,7 +1561,7 @@ dependencies = [ "num-rational 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1708,6 +1738,11 @@ name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "openssl" version = "0.10.26" @@ -2431,6 +2466,18 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sha-1" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cpuid-bool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha2" version = "0.8.1" @@ -2558,7 +2605,7 @@ dependencies = [ "rspotify 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", "serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "syslog 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3061,7 +3108,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3398,6 +3445,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +"checksum block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" "checksum block-modes 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "31aa8410095e39fdb732909fb5730a48d5bd7c2e3cd76bd1b07b3dbea130c529" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" @@ -3423,6 +3471,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum coreaudio-rs 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f229761965dad3e9b11081668a6ea00f1def7aa46062321b5ec245b834f6e491" "checksum coreaudio-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e8f5954c1c7ccb55340443e8b29fca24013545a5e7d72c1ca7db4fc02b982ce" "checksum cpal 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d58ae1ed6536b1b233f5e3aeb6997a046ddb4d05e3f61701b58a92eb254a829e" +"checksum cpuid-bool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" @@ -3441,6 +3490,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ac53fa6a3cda160df823a9346442525dcaf1e171999a1cf23e67067e4fd64d4" "checksum derive_builder_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0288a23da9333c246bb18c143426074a6ae96747995c5819d2947b64cd942b37" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +"checksum digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" "checksum dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d0a1279c96732bc6800ce6337b6a614697b0e74ae058dc03c62ebeb78b4d86" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" @@ -3472,6 +3522,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +"checksum generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" "checksum gethostname 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e692e296bfac1d2533ef168d0b60ff5897b8b70a4009276834014dd8924cc028" "checksum getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" @@ -3553,6 +3604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ogg 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d79f1db9148be9d0e174bb3ac890f6030fcb1ed947267c5a91ee4c91b5a91e15" "checksum ogg-sys 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a95b8c172e17df1a41bf8d666301d3b2c4efeb90d9d0415e2a4dc0668b35fdb2" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +"checksum opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" "checksum openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)" = "465d16ae7fc0e313318f7de5cecf57b2fbe7511fd213978b457e1c96ff46736f" @@ -3633,6 +3685,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" "checksum sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +"checksum sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" "checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" "checksum shannon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ea5b41c9427b56caa7b808cb548a04fb50bb5b9e98590b53f28064ff4174561" "checksum shell-words 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39acde55a154c4cd3ae048ac78cc21c25f3a0145e44111b523279113dce0d94a" @@ -3692,7 +3745,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" "checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" -"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" "checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" From 7158b418852f2e83d30995258740a4f96596d469 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 27 Sep 2020 17:16:58 +0100 Subject: [PATCH 09/12] manual bitrate deserialisation --- Cargo.lock | 12 ------------ Cargo.toml | 1 - src/config.rs | 27 ++++++++++++++++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94165f34..1c6be59e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2434,16 +2434,6 @@ dependencies = [ "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "serde_repr" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "serde_urlencoded" version = "0.6.1" @@ -2604,7 +2594,6 @@ dependencies = [ "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rspotify 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "syslog 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3682,7 +3671,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" "checksum serde_derive 1.0.115 (registry+https://github.com/rust-lang/crates.io-index)" = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" "checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" -"checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" "checksum sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" "checksum sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" diff --git a/Cargo.toml b/Cargo.toml index 8f9d8ce4..7862feef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ url = "1.7" xdg = "2.2" librespot = { version = "0.1.1", default-features = false, features = ["with-tremor"] } toml = "0.5.6" -serde_repr = "0.1.5" [target."cfg(target_os = \"macos\")".dependencies] whoami = "0.9.0" diff --git a/src/config.rs b/src/config.rs index 43ebc912..6c1703aa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,8 +10,7 @@ use librespot::{ playback::config::{Bitrate as LSBitrate, PlayerConfig}, }; use log::{error, info, warn}; -use serde::Deserialize; -use serde_repr::Deserialize_repr; +use serde::{de::Error, de::Unexpected, Deserialize, Deserializer}; use sha1::{Digest, Sha1}; use std::{fmt, fs, path::PathBuf, str::FromStr, string::ToString}; use structopt::{clap::AppSettings, StructOpt}; @@ -191,12 +190,26 @@ lazy_static! { } /// Spotify's audio bitrate -#[derive(Clone, Copy, Debug, Deserialize_repr, PartialEq, StructOpt)] -#[repr(u16)] +#[derive(Clone, Copy, Debug, PartialEq, StructOpt)] pub enum Bitrate { - Bitrate96 = 96, - Bitrate160 = 160, - Bitrate320 = 320, + Bitrate96, + Bitrate160, + Bitrate320, +} + +impl<'de> Deserialize<'de> for Bitrate { + fn deserialize>(deserializer: D) -> Result { + match u16::deserialize(deserializer) { + Ok(96) => Ok(Self::Bitrate96), + Ok(160) => Ok(Self::Bitrate160), + Ok(320) => Ok(Self::Bitrate320), + Ok(x) => Err(D::Error::invalid_value( + Unexpected::Unsigned(x.into()), + &"a bitrate: 96, 160, 320", + )), + Err(e) => Err(e), + } + } } impl FromStr for Bitrate { From 0adf440298a9b750b9bc5493e6d1a2433bff2826 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 29 Sep 2020 19:25:57 +0100 Subject: [PATCH 10/12] update config file section in README --- README.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5222125e..faadcc11 100644 --- a/README.md +++ b/README.md @@ -169,19 +169,19 @@ spotifyd --help ### Configuration file -`Spotifyd` is able to load configuration values from a file too. The file has to be named `spotifyd.conf` and reside in the user's configuration directory (`~/.config/spotifyd`) or the system configuration directory (`/etc` or `/etc/xdg/spotifyd`). This also applies to macOS! +`Spotifyd` is able to load configuration values from a TOML file too. The file has to be named `spotifyd.conf` and reside in the user's configuration directory (`~/.config/spotifyd`) or the system configuration directory (`/etc` or `/etc/xdg/spotifyd`). This also applies to macOS! The configuration file consists of two sections, `global` and `spotifyd`, whereas `spotifyd` takes priority over `global`. The configuration file has the following format: -```ini +```toml [global] # Your Spotify account name. -username = username +username = "username" # Your Spotify account password. -password = password +password = "password" # A command that gets executed and can be used to # retrieve your password. @@ -189,7 +189,7 @@ password = password # # This is an alternative to the `password` field. Both # can't be used simultaneously. -password_cmd = command_that_writes_password_to_stdout +password_cmd = "command_that_writes_password_to_stdout" # If set to true, `spotifyd` tries to look up your # password in the system's password storage. @@ -200,30 +200,30 @@ use_keyring = true # The audio backend used to play the your music. To get # a list of possible backends, run `spotifyd --help`. -backend = alsa +backend = "alsa" # The alsa audio device to stream audio to. To get a # list of valid devices, run `aplay -L`, -device = alsa_audio_device # omit for macOS +device = "alsa_audio_device" # omit for macOS # The alsa control device. By default this is the same # name as the `device` field. -control = alsa_audio_device # omit for macOS +control = "alsa_audio_device" # omit for macOS # The alsa mixer used by `spotifyd`. -mixer = PCM +mixer = "PCM" # The volume controller. Each one behaves different to # volume increases. For possible values, run # `spotifyd --help`. -volume_controller = alsa # use softvol for macOS +volume_controller = "alsa" # use softvol for macOS # A command that gets executed in your shell after each song changes. -on_song_change_hook = command_to_run_on_playback_events +on_song_change_hook = "command_to_run_on_playback_events" # The name that gets displayed under the connect tab on # official clients. Spaces are not allowed! -device_name = device_name_in_spotify_connect +device_name = "device_name_in_spotify_connect" # The audio bitrate. 96, 160 or 320 kbit/s bitrate = 160 @@ -234,7 +234,7 @@ bitrate = 160 # # Note: The file path does not get expanded. Environment variables and # shell placeholders like $HOME or ~ don't work! -cache_path = cache_directory +cache_path = "cache_directory" # If set to true, audio data does NOT get cached. no_audio_cache = true @@ -252,12 +252,12 @@ normalisation_pregain = -10 zeroconf_port = 1234 # The proxy `spotifyd` will use to connect to spotify. -proxy = http://proxy.example.org:8080 +proxy = "http://proxy.example.org:8080" # The displayed device type in Spotify clients. # Can be unknown, computer, tablet, smartphone, speaker, tv, # avr (Audio/Video Receiver), stb (Set-Top Box), and audiodongle. -device_type = speaker +device_type = "speaker" ``` #### Alternatives to storing your password in the config file @@ -268,9 +268,9 @@ device_type = speaker For example (using the password-management utility [pass][pass-homepage]). - ```ini + ```toml # ~/.config/spotifyd/spotifyd.conf - password_cmd = pass spotify + password_cmd = "pass spotify" ``` - **`use_keyring`** config entry / **`--use-keyring`** CLI flag From 9823473571485202285eb94af425c9dd287231e1 Mon Sep 17 00:00:00 2001 From: 0jdxt <4650251+0jdxt@users.noreply.github.com> Date: Wed, 30 Sep 2020 00:26:03 +0100 Subject: [PATCH 11/12] add link to toml spec this will help users who may not have used TOML before - link will need to be updated when the toml crate updates to support TOML v1.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index faadcc11..187585ed 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ spotifyd --help ### Configuration file -`Spotifyd` is able to load configuration values from a TOML file too. The file has to be named `spotifyd.conf` and reside in the user's configuration directory (`~/.config/spotifyd`) or the system configuration directory (`/etc` or `/etc/xdg/spotifyd`). This also applies to macOS! +`Spotifyd` is able to load configuration values from a [TOML](https://toml.io/en/v0.5.0) file too. The file has to be named `spotifyd.conf` and reside in the user's configuration directory (`~/.config/spotifyd`) or the system configuration directory (`/etc` or `/etc/xdg/spotifyd`). This also applies to macOS! The configuration file consists of two sections, `global` and `spotifyd`, whereas `spotifyd` takes priority over `global`. From a5c793357c1d3ca72aacb5142cbf8845c60c42ef Mon Sep 17 00:00:00 2001 From: 0jdxt <4650251+0jdxt@users.noreply.github.com> Date: Wed, 30 Sep 2020 00:44:13 +0100 Subject: [PATCH 12/12] redundant use of `std::`, `fs` already imported --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 6c1703aa..d26c71e4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -477,7 +477,7 @@ impl CliConfig { }; info!("Loading config from {:?}", &config_file_path); - let content = match std::fs::read_to_string(config_file_path) { + let content = match fs::read_to_string(config_file_path) { Ok(s) => s, Err(e) => { info!("Failed reading config file: {}", e);