From d7987bb4ef6d0aa1e7735a857c6e09863aac8354 Mon Sep 17 00:00:00 2001 From: dakriy Date: Sun, 8 Jun 2025 07:54:21 -0700 Subject: [PATCH] fix: when metadata has a newline playout stops (#3160) ### Description If the title or artist metadata in libretime has a newline, that file is not played as telnet takes the newline as a command enter in the middle of the command. **This is a new feature**: No **I have updated the documentation to reflect these changes**: No ### Testing Notes **What I did:** I spun up a fresh local LibreTime instance, uploaded a track with a newline in the creator field. I then created a show and added the track to the show and verified that the track did not play with error: ``` playout-1 | 2025-06-06 17:41:49,888 | ERROR | libretime_playout.liquidsoap.client._client:_set_var:50 - ERROR: unknown command, type "help" to get a list of commands. ``` I then added my fix and verified that the track did play as it was supposed to. **How you can replicate my testing:** See the above section --------- Co-authored-by: jo --- playout/libretime_playout/player/liquidsoap.py | 6 ++++-- playout/tests/player/liquidsoap_test.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/playout/libretime_playout/player/liquidsoap.py b/playout/libretime_playout/player/liquidsoap.py index c09d01a90..112d0532c 100644 --- a/playout/libretime_playout/player/liquidsoap.py +++ b/playout/libretime_playout/player/liquidsoap.py @@ -30,10 +30,12 @@ def create_liquidsoap_annotation(file_event: FileEvent) -> str: # the metadata we get from LibreTime. (You can modify metadata in LibreTime's library, # which doesn't get saved back to the file.) if file_event.artist_name: - annotations["artist"] = file_event.artist_name.replace('"', '\\"') + value = file_event.artist_name.replace('"', '\\"').strip().replace("\n", " ") + annotations["artist"] = value if file_event.track_title: - annotations["title"] = file_event.track_title.replace('"', '\\"') + value = file_event.track_title.replace('"', '\\"').strip().replace("\n", " ") + annotations["title"] = value annotations_str = ",".join(f'{key}="{value}"' for key, value in annotations.items()) diff --git a/playout/tests/player/liquidsoap_test.py b/playout/tests/player/liquidsoap_test.py index 2f0324bf9..f1ac7ad5d 100644 --- a/playout/tests/player/liquidsoap_test.py +++ b/playout/tests/player/liquidsoap_test.py @@ -44,6 +44,24 @@ def test_create_liquidsoap_annotation(): ":/fake/2.flac" ) + file_event.artist_name = "New\nline to space" + file_event.track_title = "Trailing\nnewline\n" + + assert create_liquidsoap_annotation(file_event) == ( + "annotate:" + 'media_id="2",' + 'schedule_table_id="1",' + 'liq_start_next="0",' + 'liq_fade_in="0.5",' + 'liq_fade_out="0.5",' + 'liq_cue_in="13.7008",' + 'liq_cue_out="315.845",' + 'replay_gain="11.46 dB",' + 'artist="New line to space",' + 'title="Trailing newline"' + ":/fake/2.flac" + ) + def test_liquidsoap(): Liquidsoap(MagicMock())