Skip to content

Commit

Permalink
feat: added support for renaming the default Spotify device name (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Isom <[email protected]>
  • Loading branch information
ChrisMoriarty and codetheweb authored Aug 12, 2024
1 parent a5c1503 commit 76fe9b4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -55,6 +56,7 @@ SPOTIFY_USERNAME=
SPOTIFY_PASSWORD=
DISCORD_USER_ID=
SPOTIFY_BOT_AUTOPLAY=
SPOTIFY_DEVICE_NAME=
```

```bash
Expand Down
3 changes: 2 additions & 1 deletion config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
SPOTIFY_BOT_AUTOPLAY=true
SPOTIFY_DEVICE_NAME="custom device name in spotify, optional"
7 changes: 7 additions & 0 deletions src/lib/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ pub struct Config {
pub discord_user_id: u64,
#[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 {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct SpotifyPlayer {
pub event_channel: Option<Arc<tokio::sync::Mutex<PlayerEventChannel>>>,
mixer: Box<SoftMixer>,
pub bot_autoplay: bool,
pub device_name: String,
}

pub struct EmittedSink {
Expand Down Expand Up @@ -208,6 +209,7 @@ impl SpotifyPlayer {
quality: Bitrate,
cache_dir: Option<String>,
bot_autoplay: bool,
device_name: String,
) -> SpotifyPlayer {
let credentials = Credentials::with_password(username, password);

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ async fn main() {
Bitrate::Bitrate320,
cache_dir,
config.spotify_bot_autoplay,
config.spotify_device_name.clone(),
)
.await,
));
Expand Down

0 comments on commit 76fe9b4

Please sign in to comment.