From 96475c72966c7c5d6910f751e16395978624f7ab Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Aug 2024 12:44:28 -0400 Subject: [PATCH 1/5] Added "SPOTIFY_DEVICE_NAME" env variable support --- Cargo.lock | 2 +- config.sample.toml | 3 ++- src/lib/config.rs | 2 ++ src/lib/player.rs | 5 ++++- src/main.rs | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0719f33..f552bbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,7 +99,7 @@ dependencies = [ [[package]] name = "aoede" -version = "0.7.0" +version = "0.8.0" dependencies = [ "byteorder", "figment", diff --git a/config.sample.toml b/config.sample.toml index db22e67..6d2e336 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -2,4 +2,5 @@ DISCORD_TOKEN="the discord bot token" SPOTIFY_USERNAME="your spotify email" SPOTIFY_PASSWORD="your spotify password" DISCORD_USER_ID="your discord id here" -SPOTIFY_BOT_AUTOPLAY=true \ No newline at end of file +SPOTIFY_BOT_AUTOPLAY=true +SPOTIFY_DEVICE_NAME="Aoede" \ No newline at end of file diff --git a/src/lib/config.rs b/src/lib/config.rs index 451df9c..fd14c27 100644 --- a/src/lib/config.rs +++ b/src/lib/config.rs @@ -16,6 +16,8 @@ pub struct Config { pub discord_user_id: u64, #[serde(alias = "SPOTIFY_BOT_AUTOPLAY")] pub spotify_bot_autoplay: bool, + #[serde(alias = "SPOTIFY_DEVICE_NAME")] + pub spotify_device_name: String, } impl Config { diff --git a/src/lib/player.rs b/src/lib/player.rs index f245359..00bcb02 100644 --- a/src/lib/player.rs +++ b/src/lib/player.rs @@ -38,6 +38,7 @@ pub struct SpotifyPlayer { pub event_channel: Option>>, mixer: Box, pub bot_autoplay: bool, + pub device_name: String, } pub struct EmittedSink { @@ -208,6 +209,7 @@ impl SpotifyPlayer { quality: Bitrate, cache_dir: Option, bot_autoplay: bool, + device_name: String, ) -> SpotifyPlayer { let credentials = Credentials::with_password(username, password); @@ -259,12 +261,13 @@ impl SpotifyPlayer { event_channel: Some(Arc::new(tokio::sync::Mutex::new(rx))), mixer, bot_autoplay, + device_name } } pub async fn enable_connect(&mut self) { let config = ConnectConfig { - name: "Aoede".to_string(), + name: self.device_name.clone(), device_type: DeviceType::AudioDongle, initial_volume: None, has_volume_ctrl: true, diff --git a/src/main.rs b/src/main.rs index 98bb944..b874372 100644 --- a/src/main.rs +++ b/src/main.rs @@ -305,6 +305,7 @@ async fn main() { Bitrate::Bitrate320, cache_dir, config.spotify_bot_autoplay, + config.spotify_device_name.clone() ) .await, )); From 6bbe76c2120cf97c02750b51a366672a44df46bd Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Aug 2024 12:52:00 -0400 Subject: [PATCH 2/5] Updated readme for addition of SPOTIFY_DEVICE_NAME env variable --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ef68af4..a31a49e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ services: - SPOTIFY_PASSWORD= - DISCORD_USER_ID= # Discord user ID of the user you want Aoede to follow - SPOTIFY_BOT_AUTOPLAY= # Autoplay similar songs when your music ends (true/false) + - SPOTIFY_DEVICE_NAME= ``` ### Docker: @@ -55,6 +56,7 @@ SPOTIFY_USERNAME= SPOTIFY_PASSWORD= DISCORD_USER_ID= SPOTIFY_BOT_AUTOPLAY= +SPOTIFY_DEVICE_NAME= ``` ```bash From 0954ea89a2d273df181220418ae964a7422e10fe Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Aug 2024 13:46:47 -0400 Subject: [PATCH 3/5] Added default behavior for SPOTIFY_DEVICE_NAME env variable --- src/lib/config.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/config.rs b/src/lib/config.rs index fd14c27..5b0211c 100644 --- a/src/lib/config.rs +++ b/src/lib/config.rs @@ -17,9 +17,14 @@ pub struct Config { #[serde(alias = "SPOTIFY_BOT_AUTOPLAY")] pub spotify_bot_autoplay: bool, #[serde(alias = "SPOTIFY_DEVICE_NAME")] + #[serde(default = "default_spotify_device_name")] pub spotify_device_name: String, } +fn default_spotify_device_name() -> String{ + "Aoede".to_string() +} + impl Config { pub fn new() -> Result { let config: Config = Figment::new() From d489e24e98144839e40d39c76a5cab1c3cf846a5 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Aug 2024 13:57:38 -0400 Subject: [PATCH 4/5] Updated sample toml to be clearer --- config.sample.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.sample.toml b/config.sample.toml index 6d2e336..a42bf7c 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -3,4 +3,4 @@ SPOTIFY_USERNAME="your spotify email" SPOTIFY_PASSWORD="your spotify password" DISCORD_USER_ID="your discord id here" SPOTIFY_BOT_AUTOPLAY=true -SPOTIFY_DEVICE_NAME="Aoede" \ No newline at end of file +SPOTIFY_DEVICE_NAME="custom device name in spotify, optional" \ No newline at end of file From f79e3ab8007a2cb8fd9608884228d3c1986aacd0 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sun, 11 Aug 2024 21:13:55 -0700 Subject: [PATCH 5/5] Run cargo fmt --- src/lib/config.rs | 2 +- src/lib/player.rs | 2 +- src/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/config.rs b/src/lib/config.rs index 5b0211c..7f376d9 100644 --- a/src/lib/config.rs +++ b/src/lib/config.rs @@ -21,7 +21,7 @@ pub struct Config { pub spotify_device_name: String, } -fn default_spotify_device_name() -> String{ +fn default_spotify_device_name() -> String { "Aoede".to_string() } diff --git a/src/lib/player.rs b/src/lib/player.rs index 00bcb02..dd97930 100644 --- a/src/lib/player.rs +++ b/src/lib/player.rs @@ -261,7 +261,7 @@ impl SpotifyPlayer { event_channel: Some(Arc::new(tokio::sync::Mutex::new(rx))), mixer, bot_autoplay, - device_name + device_name, } } diff --git a/src/main.rs b/src/main.rs index b874372..780eaea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -305,7 +305,7 @@ async fn main() { Bitrate::Bitrate320, cache_dir, config.spotify_bot_autoplay, - config.spotify_device_name.clone() + config.spotify_device_name.clone(), ) .await, ));