Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for renaming the default Spotify device name #53

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading