fix(metadata): clear stream_title when DJ is talking

This commit is contained in:
bart
2026-11-07 17:21:24 +01:00
parent 9da6d3db27
commit 49ad12ff14
2 changed files with 63 additions and 14 deletions
+24 -1
View File
@@ -43,7 +43,11 @@ impl MqttPlaybackState {
artist: st.artist.clone(), artist: st.artist.clone(),
playlist: st.playlist.clone(), playlist: st.playlist.clone(),
genre: st.genre.clone(), genre: st.genre.clone(),
stream_title: st.stream_title.clone(), stream_title: if st.artist == "Radio Chicken DJ" || st.stream_title.contains("Radio Chicken DJ") {
String::new()
} else {
st.stream_title.clone()
},
} }
} }
} }
@@ -524,6 +528,25 @@ mod tests {
assert_eq!(mqtt_state.stream_title, ""); assert_eq!(mqtt_state.stream_title, "");
} }
#[test]
fn test_dj_announcement_stream_title_empty() {
let st = PlayerStatus {
state: PlaybackState::Playing,
media_type: "video".to_string(),
title: "Radio Chicken TV: Up next: Iron Maiden - The Trooper".to_string(),
artist: "Radio Chicken DJ".to_string(),
playlist: "HEUL_HARD".to_string(),
genre: "DJ".to_string(),
stream_title: "Radio Chicken DJ - Up next: Iron Maiden - The Trooper".to_string(),
..PlayerStatus::default()
};
let mqtt_state = MqttPlaybackState::from_status(&st);
assert_eq!(mqtt_state.state, "playing");
assert_eq!(mqtt_state.artist, "Radio Chicken DJ");
assert_eq!(mqtt_state.stream_title, "");
}
#[test] #[test]
fn test_yaml_config_deserialization() { fn test_yaml_config_deserialization() {
let yaml_str = r#" let yaml_str = r#"
+31 -5
View File
@@ -502,7 +502,12 @@ impl PlayerController {
InternalMpvEvent::MediaTitle(mt) => { InternalMpvEvent::MediaTitle(mt) => {
if !is_url_or_query_string(&mt) { if !is_url_or_query_string(&mt) {
if st.media_type == "stream" { if st.media_type == "stream" {
if (st.stream_title.is_empty() || st.stream_title != mt) && !st.stream_title.contains(" - ") { if st.artist == "Radio Chicken DJ" || mt.contains("Radio Chicken DJ") {
if !st.stream_title.is_empty() {
st.stream_title.clear();
notify = true;
}
} else if (st.stream_title.is_empty() || st.stream_title != mt) && !st.stream_title.contains(" - ") {
st.stream_title = mt; st.stream_title = mt;
notify = true; notify = true;
} }
@@ -513,7 +518,13 @@ impl PlayerController {
} }
} }
InternalMpvEvent::IcyTitle(icy) => { InternalMpvEvent::IcyTitle(icy) => {
if !is_url_or_query_string(&icy) && st.stream_title != icy { if !is_url_or_query_string(&icy) {
if st.artist == "Radio Chicken DJ" || icy.contains("Radio Chicken DJ") {
if !st.stream_title.is_empty() {
st.stream_title.clear();
notify = true;
}
} else if st.stream_title != icy {
st.stream_title = icy.clone(); st.stream_title = icy.clone();
st.media_type = "stream".to_string(); st.media_type = "stream".to_string();
if let Some((art, tit)) = parse_artist_title(&icy) { if let Some((art, tit)) = parse_artist_title(&icy) {
@@ -525,6 +536,7 @@ impl PlayerController {
notify = true; notify = true;
} }
} }
}
InternalMpvEvent::Metadata { artist, genre, stream_title, title } => { InternalMpvEvent::Metadata { artist, genre, stream_title, title } => {
if let Some(a) = artist { if let Some(a) = artist {
if !is_url_or_query_string(&a) && st.artist != a { if !is_url_or_query_string(&a) && st.artist != a {
@@ -545,7 +557,12 @@ impl PlayerController {
} }
} }
if let Some(s) = stream_title { if let Some(s) = stream_title {
if !is_url_or_query_string(&s) && st.stream_title != s { if st.artist == "Radio Chicken DJ" || s.contains("Radio Chicken DJ") {
if !st.stream_title.is_empty() {
st.stream_title.clear();
notify = true;
}
} else if !is_url_or_query_string(&s) && st.stream_title != s {
st.stream_title = s.clone(); st.stream_title = s.clone();
st.media_type = "stream".to_string(); st.media_type = "stream".to_string();
if let Some((art, tit)) = parse_artist_title(&s) { if let Some((art, tit)) = parse_artist_title(&s) {
@@ -917,7 +934,13 @@ impl PlayerController {
st.artist = song.artist.clone(); st.artist = song.artist.clone();
st.playlist = playlist_name.clone(); st.playlist = playlist_name.clone();
st.genre = song.genre.clone(); st.genre = song.genre.clone();
if song.is_tts || song.artist == "Radio Chicken DJ" {
st.stream_title.clear();
} else if let Some(ref st_title) = song.stream_title {
st.stream_title = st_title.clone();
} else {
st.stream_title = format!("{} - {}", song.artist, song.name); st.stream_title = format!("{} - {}", song.artist, song.name);
}
st.title = if is_video { st.title = if is_video {
format!("Radio Chicken TV: {}", song.name) format!("Radio Chicken TV: {}", song.name)
} else { } else {
@@ -926,11 +949,12 @@ impl PlayerController {
drop(st); drop(st);
player.notify_status().await; player.notify_status().await;
tracing::info!( tracing::info!(
"Radio Chicken metadata updated: artist='{}', title='{}', playlist='{}', genre='{}'", "Radio Chicken metadata updated: artist='{}', title='{}', playlist='{}', genre='{}', stream_title='{}'",
song.artist, song.artist,
song.name, song.name,
playlist_name, playlist_name,
song.genre song.genre,
if song.is_tts || song.artist == "Radio Chicken DJ" { "" } else { &song.name }
); );
} }
} }
@@ -969,6 +993,8 @@ pub struct RadioChickenCurrentSong {
#[serde(default)] #[serde(default)]
pub genre: String, pub genre: String,
#[serde(default)] #[serde(default)]
pub stream_title: Option<String>,
#[serde(default)]
pub is_tts: bool, pub is_tts: bool,
} }