8000 feat: make playback metadata fields configurable by VimDie5el · Pull Request #756 · aome510/spotify-player · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: make playback metadata fields configurable #756

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ All configuration files should be placed inside the application's configuration
| `client_port` | the port that the application's client is running on to handle CLI commands | `8080` |
| `tracks_playback_limit` | the limit for the number of tracks played in a **tracks** playback | `50` |
| `playback_format` | the format of the text in the playback's window | `{status} {track} • {artists} {liked}\n{album}\n{metadata}` |
| `playback_metadata_fields` | (optional) list of metadata fields to display in the playback UI's `{metadata}` section. Possible values: `"repeat"`, `"shuffle"`, `"volume"`, `"device"` | `["repeat", "shuffle", "volume", "device"]` |
| `notify_format` | the format of a notification (`notify` feature only) | `{ summary = "{track} • {artists}", body = "{album}" }` |
| `notify_timeout_in_secs` | the timeout (in seconds) of a notification (`notify` feature only) | `0` (no timeout) |
| `player_event_hook_command` | the hook command executed when there is a new player event | `None` |
Expand Down Expand Up @@ -326,3 +327,4 @@ target = "PlayingTrack"
action="ToggleLiked"
key_sequence="C-l"
```

2 changes: 2 additions & 0 deletions spotify_player/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct AppConfig {
pub player_event_hook_command: Option<Command>,

pub playback_format: String,
pub playback_metadata_fields: Option<Vec<String>>,
#[cfg(feature = "notify")]
pub notify_format: NotifyFormat,
#[cfg(feature = "notify")]
Expand Down 8000 Expand Up @@ -268,6 +269,7 @@ impl Default for AppConfig {
playback_format: String::from(
"{status} {track} • {artists} {liked}\n{album}\n{metadata}",
),
playback_metadata_fields: None,
#[cfg(feature = "notify")]
notify_format: NotifyFormat {
summary: String::from("{track} • {artists}"),
Expand Down
57 changes: 39 additions & 18 deletions spotify_player/src/ui/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,45 @@ fn construct_playback_text(
(episode.show.name.clone(), ui.theme.playback_album())
}
},
"{metadata}" => (
format!(
"repeat: {} | shuffle: {} | volume: {} | device: {}",
if playback.fake_track_repeat_state {
"track (fake)"
} else {
<&'static str>::from(playback.repeat_state)
},
playback.shuffle_state,
if let Some(volume) = playback.mute_state {
format!("{volume}% (muted)")
} else {
format!("{}%", playback.volume.unwrap_or_default())
},
playback.device_name,
),
ui.theme.playback_metadata(),
),
"{metadata}" => {
let default_fields = vec![
"repeat".to_string(),
"shuffle".to_string(),
"volume".to_string(),
"device".to_string(),
];
let fields = configs.app_config
.playback_metadata_fields
.as_ref()
.unwrap_or(&default_fields);

let repeat_value = if playback.fake_track_repeat_state {
"track (fake)".to_string()
} else {
<&'static str>::from(playback.repeat_state).to_string()
};

let volume_value = if let Some(volume) = playback.mute_state {
format!("{volume}% (muted)")
} else {
format!("{}%", playback.volume.unwrap_or_default())
};

let mut parts = vec![];

for field in fields {
match field.as_str() {
"repeat" => parts.push(format!("repeat: {}", repeat_value)),
"shuffle" => parts.push(format!("shuffle: {}", playback.shuffle_state)),
"volume" => parts.push(format!("volume: {}", volume_value)),
"device" => parts.push(format!("device: {}", playback.device_name)),
_ => {}
}
}

let metadata_str = parts.join(" | ");
(metadata_str, ui.theme.playback_metadata())
},
_ => continue,
};

Expand Down
0